Refactor onboarding user vars to be absent when user is fully onboarded (#6531)

In this PR:
- take feedbacks from: https://github.com/twentyhq/twenty/pull/6530 /
https://github.com/twentyhq/twenty/pull/6529 /
https://github.com/twentyhq/twenty/pull/6526 /
https://github.com/twentyhq/twenty/pull/6512
- refactor onboarding uservars to be absent when the user is fully
onboarded: isStepComplete ==> isStepIncomplete
- introduce a new workspace.activationStatus: CREATION_ONGOING

I'm retesting the whole flow:
- with/without BILLING
- sign in with/without SSO
- sign up with/without SSO
- another workspaceMembers join the team
- subscriptionCanceled
- access to billingPortal
This commit is contained in:
Charles Bochet
2024-08-04 20:37:36 +02:00
committed by GitHub
parent c543716381
commit 03204021cb
49 changed files with 517 additions and 364 deletions

View File

@ -5,7 +5,6 @@ import chalk from 'chalk';
import { Command, CommandRunner, Option } from 'nest-commander';
import { Repository } from 'typeorm';
import { UpdateFileFolderStructureCommand } from 'src/database/commands/upgrade-version/0-23/0-23-update-file-folder-structure.command';
import { OnboardingService } from 'src/engine/core-modules/onboarding/onboarding.service';
import {
Workspace,
@ -21,7 +20,9 @@ interface BackfillNewOnboardingUserVarsCommandOptions {
description: 'Backfill new onboarding user vars for existing workspaces',
})
export class BackfillNewOnboardingUserVarsCommand extends CommandRunner {
private readonly logger = new Logger(UpdateFileFolderStructureCommand.name);
private readonly logger = new Logger(
BackfillNewOnboardingUserVarsCommand.name,
);
constructor(
@InjectRepository(Workspace, 'core')
private readonly workspaceRepository: Repository<Workspace>,
@ -43,22 +44,13 @@ export class BackfillNewOnboardingUserVarsCommand extends CommandRunner {
_passedParam: string[],
options: BackfillNewOnboardingUserVarsCommandOptions,
): Promise<void> {
let workspaces;
if (options.workspaceId) {
workspaces = await this.workspaceRepository.find({
where: {
activationStatus: WorkspaceActivationStatus.ACTIVE,
id: options.workspaceId,
},
relations: ['users'],
});
} else {
workspaces = await this.workspaceRepository.find({
where: { activationStatus: WorkspaceActivationStatus.ACTIVE },
relations: ['users'],
});
}
const workspaces = await this.workspaceRepository.find({
where: {
activationStatus: WorkspaceActivationStatus.PENDING_CREATION,
...(options.workspaceId && { id: options.workspaceId }),
},
relations: ['users'],
});
if (!workspaces.length) {
this.logger.log(chalk.yellow('No workspace found'));
@ -75,19 +67,19 @@ export class BackfillNewOnboardingUserVarsCommand extends CommandRunner {
chalk.green(`Running command on workspace ${workspace.id}`),
);
await this.onboardingService.toggleOnboardingInviteTeamCompletion({
await this.onboardingService.setOnboardingInviteTeamPending({
workspaceId: workspace.id,
value: true,
});
for (const user of workspace.users) {
await this.onboardingService.toggleOnboardingConnectAccountCompletion({
await this.onboardingService.setOnboardingCreateProfileCompletion({
userId: user.id,
workspaceId: workspace.id,
value: true,
});
await this.onboardingService.toggleOnboardingCreateProfileCompletion({
await this.onboardingService.setOnboardingConnectAccountPending({
userId: user.id,
workspaceId: workspace.id,
value: true,