Skip to content

Commit

Permalink
Refactor onboarding user vars to be absent when user is fully onboard…
Browse files Browse the repository at this point in the history
…ed (#6531)

In this PR:
- take feedbacks from: #6530 /
#6529 /
#6526 /
#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
  • Loading branch information
charlesBochet authored Aug 4, 2024
1 parent c543716 commit 0320402
Show file tree
Hide file tree
Showing 49 changed files with 517 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const useGenerateCombinedFindManyRecordsQuery = ({
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import { ShowPageContainer } from '@/ui/layout/page/ShowPageContainer';
import { ShowPageLeftContainer } from '@/ui/layout/show-page/components/ShowPageLeftContainer';
import { ShowPageRightContainer } from '@/ui/layout/show-page/components/ShowPageRightContainer';
import { ShowPageSummaryCard } from '@/ui/layout/show-page/components/ShowPageSummaryCard';
import { ShowPageRecoilScopeContext } from '@/ui/layout/states/ShowPageRecoilScopeContext';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import {
FieldMetadataType,
Expand Down Expand Up @@ -302,27 +300,25 @@ export const RecordShowContainer = ({
);

return (
<RecoilScope CustomRecoilScopeContext={ShowPageRecoilScopeContext}>
<ShowPageContainer>
<ShowPageLeftContainer forceMobile={isInRightDrawer}>
{!isMobile && summaryCard}
{!isMobile && fieldsBox}
</ShowPageLeftContainer>
<ShowPageRightContainer
targetableObject={{
id: objectRecordId,
targetObjectNameSingular: objectMetadataItem?.nameSingular,
}}
timeline
tasks
notes
emails
isInRightDrawer={isInRightDrawer}
summaryCard={isMobile ? summaryCard : <></>}
fieldsBox={fieldsBox}
loading={isPrefetchLoading || loading || recordLoading}
/>
</ShowPageContainer>
</RecoilScope>
<ShowPageContainer>
<ShowPageLeftContainer forceMobile={isInRightDrawer}>
{!isMobile && summaryCard}
{!isMobile && fieldsBox}
</ShowPageLeftContainer>
<ShowPageRightContainer
targetableObject={{
id: objectRecordId,
targetObjectNameSingular: objectMetadataItem?.nameSingular,
}}
timeline
tasks
notes
emails
isInRightDrawer={isInRightDrawer}
summaryCard={isMobile ? summaryCard : <></>}
fieldsBox={fieldsBox}
loading={isPrefetchLoading || loading || recordLoading}
/>
</ShowPageContainer>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { lastShowPageRecordIdState } from '@/object-record/record-field/states/lastShowPageRecordId';
import { useRecordIdsFromFindManyCacheRootQuery } from '@/object-record/record-show/hooks/useRecordIdsFromFindManyCacheRootQuery';
Expand Down Expand Up @@ -37,10 +36,6 @@ export const useRecordShowPagePagination = (

const { objectMetadataItem } = useObjectMetadataItem({ objectNameSingular });

const recordGqlFields = generateDepthOneRecordGqlFields({
objectMetadataItem,
});

const { filter, orderBy } =
useQueryVariablesFromActiveFieldsOfViewOrDefaultView({
objectMetadataItem,
Expand All @@ -55,7 +50,7 @@ export const useRecordShowPagePagination = (
orderBy,
limit: 1,
objectNameSingular,
recordGqlFields,
recordGqlFields: { id: true },
});

const cursorFromRequest = currentRecordsPageInfo?.endCursor;
Expand All @@ -77,7 +72,7 @@ export const useRecordShowPagePagination = (
}
: undefined,
objectNameSingular,
recordGqlFields,
recordGqlFields: { id: true },
onCompleted: (_, pagination) => {
setTotalCountBefore(pagination?.totalCount ?? 0);
},
Expand All @@ -97,7 +92,7 @@ export const useRecordShowPagePagination = (
}
: undefined,
objectNameSingular,
recordGqlFields,
recordGqlFields: { id: true },
onCompleted: (_, pagination) => {
setTotalCountAfter(pagination?.totalCount ?? 0);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useRecoilValue } from 'recoil';

import { currentUserState } from '@/auth/states/currentUserState';
import { Favorite } from '@/favorites/types/Favorite';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useCombinedFindManyRecords } from '@/object-record/multiple-objects/hooks/useCombinedFindManyRecords';
import { PREFETCH_CONFIG } from '@/prefetch/constants/PrefetchConfig';
import { usePrefetchRunQuery } from '@/prefetch/hooks/internal/usePrefetchRunQuery';
import { FIND_ALL_FAVORITES_OPERATION_SIGNATURE } from '@/prefetch/query-keys/FindAllFavoritesOperationSignature';
import { FIND_ALL_VIEWS_OPERATION_SIGNATURE } from '@/prefetch/query-keys/FindAllViewsOperationSignature';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { View } from '@/views/types/View';
import { isDefined } from '~/utils/isDefined';
Expand All @@ -24,11 +24,20 @@ export const PrefetchRunQueriesEffect = () => {
prefetchKey: PrefetchKey.AllFavorites,
});

const { objectMetadataItems } = useObjectMetadataItems();

const operationSignatures = Object.values(PREFETCH_CONFIG).map(
({ objectNameSingular, operationSignatureFactory }) => {
const objectMetadataItem = objectMetadataItems.find(
(item) => item.nameSingular === objectNameSingular,
);

return operationSignatureFactory({ objectMetadataItem });
},
);

const { result } = useCombinedFindManyRecords({
operationSignatures: [
FIND_ALL_VIEWS_OPERATION_SIGNATURE,
FIND_ALL_FAVORITES_OPERATION_SIGNATURE,
],
operationSignatures,
skip: !currentUser,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { RecordGqlOperationSignature } from '@/object-record/graphql/types/RecordGqlOperationSignature';
import { FIND_ALL_FAVORITES_OPERATION_SIGNATURE } from '@/prefetch/query-keys/FindAllFavoritesOperationSignature';
import { FIND_ALL_VIEWS_OPERATION_SIGNATURE } from '@/prefetch/query-keys/FindAllViewsOperationSignature';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { RecordGqlOperationSignatureFactory } from '@/object-record/graphql/types/RecordGqlOperationSignatureFactory';
import { findAllFavoritesOperationSignatureFactory } from '@/prefetch/operation-signatures/factories/findAllFavoritesOperationSignatureFactory';
import { findAllViewsOperationSignatureFactory } from '@/prefetch/operation-signatures/factories/findAllViewsOperationSignatureFactory';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';

export const PREFETCH_CONFIG: Record<PrefetchKey, RecordGqlOperationSignature> =
export const PREFETCH_CONFIG: Record<
PrefetchKey,
{
ALL_VIEWS: FIND_ALL_VIEWS_OPERATION_SIGNATURE,
ALL_FAVORITES: FIND_ALL_FAVORITES_OPERATION_SIGNATURE,
};
objectNameSingular: CoreObjectNameSingular;
operationSignatureFactory: RecordGqlOperationSignatureFactory;
}
> = {
ALL_VIEWS: {
objectNameSingular: CoreObjectNameSingular.View,
operationSignatureFactory: findAllViewsOperationSignatureFactory,
},
ALL_FAVORITES: {
objectNameSingular: CoreObjectNameSingular.Favorite,
operationSignatureFactory: findAllFavoritesOperationSignatureFactory,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useSetRecoilState } from 'recoil';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useUpsertFindManyRecordsQueryInCache } from '@/object-record/cache/hooks/useUpsertFindManyRecordsQueryInCache';
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { PREFETCH_CONFIG } from '@/prefetch/constants/PrefetchConfig';
import { prefetchIsLoadedFamilyState } from '@/prefetch/states/prefetchIsLoadedFamilyState';
Expand All @@ -18,10 +17,16 @@ export const usePrefetchRunQuery = <T extends ObjectRecord>({
const setPrefetchDataIsLoaded = useSetRecoilState(
prefetchIsLoadedFamilyState(prefetchKey),
);

const { operationSignatureFactory, objectNameSingular } =
PREFETCH_CONFIG[prefetchKey];

const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular: PREFETCH_CONFIG[prefetchKey].objectNameSingular,
objectNameSingular,
});

const operationSignature = operationSignatureFactory({ objectMetadataItem });

const { upsertFindManyRecordsQueryInCache } =
useUpsertFindManyRecordsQueryInCache({
objectMetadataItem: objectMetadataItem,
Expand All @@ -30,10 +35,8 @@ export const usePrefetchRunQuery = <T extends ObjectRecord>({
const upsertRecordsInCache = (records: T[]) => {
setPrefetchDataIsLoaded(false);
upsertFindManyRecordsQueryInCache({
queryVariables: PREFETCH_CONFIG[prefetchKey].variables,
recordGqlFields:
PREFETCH_CONFIG[prefetchKey].fields ??
generateDepthOneRecordGqlFields({ objectMetadataItem }),
queryVariables: operationSignature.variables,
recordGqlFields: operationSignature.fields,
objectRecordsToOverwrite: records,
computeReferences: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useRecoilValue } from 'recoil';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter';
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { PREFETCH_CONFIG } from '@/prefetch/constants/PrefetchConfig';
Expand All @@ -17,21 +16,18 @@ export const usePrefetchedData = <T extends ObjectRecord>(
prefetchIsLoadedFamilyState(prefetchKey),
);

const prefetchQueryKey = PREFETCH_CONFIG[prefetchKey];
const { operationSignatureFactory, objectNameSingular } =
PREFETCH_CONFIG[prefetchKey];

const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular: prefetchQueryKey.objectNameSingular,
objectNameSingular,
});

const { records } = useFindManyRecords<T>({
skip: !isDataPrefetched,
objectNameSingular: prefetchQueryKey.objectNameSingular,
objectNameSingular: objectNameSingular,
recordGqlFields:
prefetchQueryKey.fields ??
generateDepthOneRecordGqlFields({
objectMetadataItem,
}),
filter,
operationSignatureFactory({ objectMetadataItem }).fields ?? filter,
});

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { RecordGqlOperationSignatureFactory } from '@/object-record/graphql/types/RecordGqlOperationSignatureFactory';
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';

export const findAllFavoritesOperationSignatureFactory: RecordGqlOperationSignatureFactory =
({ objectMetadataItem }: { objectMetadataItem: ObjectMetadataItem }) => ({
objectNameSingular: CoreObjectNameSingular.Favorite,
variables: {},
fields: {
...generateDepthOneRecordGqlFields({
objectMetadataItem,
}),
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { RecordGqlOperationSignatureFactory } from '@/object-record/graphql/types/RecordGqlOperationSignatureFactory';

export const findAllViewsOperationSignatureFactory: RecordGqlOperationSignatureFactory =
() => ({
objectNameSingular: CoreObjectNameSingular.View,
variables: {},
fields: {
id: true,
createdAt: true,
updatedAt: true,
isCompact: true,
objectMetadataId: true,
position: true,
type: true,
kanbanFieldMetadataId: true,
name: true,
icon: true,
key: true,
viewFilters: true,
viewSorts: true,
viewFields: true,
},
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const prefetchIsLoadedFamilyState = createFamilyState<
PrefetchKey
>({
key: 'prefetchIsLoadedFamilyState',
defaultValue: true,
defaultValue: false,
});

This file was deleted.

1 change: 1 addition & 0 deletions packages/twenty-server/src/command/command-logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { Injectable } from '@nestjs/common';

import { existsSync } from 'fs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Logger } from '@nestjs/common';

import { Command, CommandRunner } from 'nest-commander';
import { EntityManager } from 'typeorm';

Expand Down Expand Up @@ -43,6 +45,7 @@ import { WorkspaceSyncMetadataService } from 'src/engine/workspace-manager/works
})
export class DataSeedWorkspaceCommand extends CommandRunner {
workspaceIds = [SEED_APPLE_WORKSPACE_ID, SEED_TWENTY_WORKSPACE_ID];
private readonly logger = new Logger(DataSeedWorkspaceCommand.name);

constructor(
private readonly dataSourceService: DataSourceService,
Expand Down Expand Up @@ -86,7 +89,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
});
}
} catch (error) {
console.error(error);
this.logger.error(error);

return;
}
Expand Down Expand Up @@ -197,7 +200,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
},
);
} catch (error) {
console.error(error);
this.logger.error(error);
}

await this.typeORMService.disconnectFromDataSource(dataSourceMetadata.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-wo
import { ConfirmationQuestion } from 'src/database/commands/questions/confirmation.question';
import { UpgradeTo0_23CommandModule } from 'src/database/commands/upgrade-version/0-23/0-23-upgrade-version.module';
import { UpgradeVersionModule } from 'src/database/commands/upgrade-version/upgrade-version.module';
import { WorkspaceAddTotalCountCommand } from 'src/database/commands/workspace-add-total-count.command';
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
Expand Down Expand Up @@ -51,7 +50,6 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp
providers: [
DataSeedWorkspaceCommand,
DataSeedDemoWorkspaceCommand,
WorkspaceAddTotalCountCommand,
ConfirmationQuestion,
StartDataSeedDemoWorkspaceCronCommand,
StopDataSeedDemoWorkspaceCronCommand,
Expand Down
Loading

0 comments on commit 0320402

Please sign in to comment.