Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

40 remove self billing feature flag #4379

Merged
merged 14 commits into from
Mar 12, 2024
Merged
23 changes: 10 additions & 13 deletions packages/twenty-front/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Route, Routes } from 'react-router-dom';
import { useRecoilValue } from 'recoil';

import { billingState } from '@/client-config/states/billingState.ts';
import { AppPath } from '@/types/AppPath';
import { SettingsPath } from '@/types/SettingsPath';
import { DefaultLayout } from '@/ui/layout/page/DefaultLayout';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { DefaultPageTitle } from '~/DefaultPageTitle';
import { CommandMenuEffect } from '~/effect-components/CommandMenuEffect';
import { GotoHotkeysEffect } from '~/effect-components/GotoHotkeysEffect';
Expand All @@ -12,7 +13,6 @@ import { CreateProfile } from '~/pages/auth/CreateProfile';
import { CreateWorkspace } from '~/pages/auth/CreateWorkspace';
import { PasswordReset } from '~/pages/auth/PasswordReset';
import { PaymentSuccess } from '~/pages/auth/PaymentSuccess.tsx';
import { PlanRequired } from '~/pages/auth/PlanRequired';
import { SignInUp } from '~/pages/auth/SignInUp';
import { VerifyEffect } from '~/pages/auth/VerifyEffect';
import { DefaultHomePage } from '~/pages/DefaultHomePage';
Expand Down Expand Up @@ -47,7 +47,7 @@ import { SettingsWorkspaceMembers } from '~/pages/settings/SettingsWorkspaceMemb
import { Tasks } from '~/pages/tasks/Tasks';

export const App = () => {
const isSelfBillingEnabled = useIsFeatureEnabled('IS_SELF_BILLING_ENABLED');
const billing = useRecoilValue(billingState());

return (
<>
Expand All @@ -63,12 +63,7 @@ export const App = () => {
<Route path={AppPath.ResetPassword} element={<PasswordReset />} />
<Route path={AppPath.CreateWorkspace} element={<CreateWorkspace />} />
<Route path={AppPath.CreateProfile} element={<CreateProfile />} />
<Route
path={AppPath.PlanRequired}
element={
isSelfBillingEnabled ? <ChooseYourPlan /> : <PlanRequired />
}
/>
<Route path={AppPath.PlanRequired} element={<ChooseYourPlan />} />
<Route
path={AppPath.PlanRequiredSuccess}
element={<PaymentSuccess />}
Expand Down Expand Up @@ -115,10 +110,12 @@ export const App = () => {
path={SettingsPath.AccountsEmailsInboxSettings}
element={<SettingsAccountsEmailsInboxSettings />}
/>
<Route
path={SettingsPath.Billing}
element={<SettingsBilling />}
/>
{billing?.isBillingEnabled && (
<Route
path={SettingsPath.Billing}
element={<SettingsBilling />}
/>
)}
<Route
path={SettingsPath.WorkspaceMembersPage}
element={<SettingsWorkspaceMembers />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export const PageChangeEffect = () => {
[OnboardingStatus.Unpaid, OnboardingStatus.Canceled].includes(
onboardingStatus,
) &&
!isMatchingLocation(SettingsPath.Billing)
!(
isMatchingLocation(AppPath.SettingsCatchAll) ||
isMatchingLocation(AppPath.PlanRequired)
)
) {
navigate(
`${AppPath.SettingsCatchAll.replace('/*', '')}/${SettingsPath.Billing}`,
Expand All @@ -110,7 +113,8 @@ export const PageChangeEffect = () => {
) {
navigate(AppPath.CreateProfile);
} else if (
onboardingStatus === OnboardingStatus.Completed &&
(onboardingStatus === OnboardingStatus.Completed ||
onboardingStatus === OnboardingStatus.CompletedWithoutSubscription) &&
isMatchingOnboardingRoute
) {
navigate(AppPath.Index);
Expand Down
43 changes: 34 additions & 9 deletions packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ export type Billing = {
isBillingEnabled: Scalars['Boolean'];
};

export type BillingSubscription = {
__typename?: 'BillingSubscription';
id: Scalars['ID'];
status: Scalars['String'];
};

export type BillingSubscriptionFilter = {
and?: InputMaybe<Array<BillingSubscriptionFilter>>;
id?: InputMaybe<IdFilterComparison>;
or?: InputMaybe<Array<BillingSubscriptionFilter>>;
};

export type BillingSubscriptionSort = {
direction: SortDirection;
field: BillingSubscriptionSortFields;
nulls?: InputMaybe<SortNulls>;
};

export enum BillingSubscriptionSortFields {
Id = 'id'
}

export type BooleanFieldComparison = {
is?: InputMaybe<Scalars['Boolean']>;
isNot?: InputMaybe<Scalars['Boolean']>;
Expand Down Expand Up @@ -134,8 +156,6 @@ export type FieldConnection = {
edges: Array<FieldEdge>;
/** Paging information */
pageInfo: PageInfo;
/** Fetch total count of records */
totalCount: Scalars['Int'];
};

export type FieldDeleteResponse = {
Expand Down Expand Up @@ -351,8 +371,6 @@ export type ObjectConnection = {
edges: Array<ObjectEdge>;
/** Paging information */
pageInfo: PageInfo;
/** Fetch total count of records */
totalCount: Scalars['Int'];
};

export type ObjectFieldsConnection = {
Expand All @@ -361,8 +379,6 @@ export type ObjectFieldsConnection = {
edges: Array<FieldEdge>;
/** Paging information */
pageInfo: PageInfo;
/** Fetch total count of records */
totalCount: Scalars['Int'];
};

export type PageInfo = {
Expand Down Expand Up @@ -474,8 +490,6 @@ export type RelationConnection = {
edges: Array<RelationEdge>;
/** Paging information */
pageInfo: PageInfo;
/** Fetch total count of records */
totalCount: Scalars['Int'];
};

export type RelationDeleteResponse = {
Expand Down Expand Up @@ -639,7 +653,9 @@ export type Workspace = {
__typename?: 'Workspace';
activationStatus: Scalars['String'];
allowImpersonation: Scalars['Boolean'];
billingSubscriptions?: Maybe<Array<BillingSubscription>>;
createdAt: Scalars['DateTime'];
currentBillingSubscription?: Maybe<BillingSubscription>;
deletedAt?: Maybe<Scalars['DateTime']>;
displayName?: Maybe<Scalars['String']>;
domainName?: Maybe<Scalars['String']>;
Expand All @@ -652,6 +668,12 @@ export type Workspace = {
};


export type WorkspaceBillingSubscriptionsArgs = {
filter?: BillingSubscriptionFilter;
sorting?: Array<BillingSubscriptionSort>;
};


export type WorkspaceFeatureFlagsArgs = {
filter?: FeatureFlagFilter;
sorting?: Array<FeatureFlagSort>;
Expand Down Expand Up @@ -950,7 +972,7 @@ export type UploadProfilePictureMutation = { __typename?: 'Mutation', uploadProf
export type GetCurrentUserQueryVariables = Exact<{ [key: string]: never; }>;


export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean, subscriptionStatus: string, activationStatus: string, featureFlags?: Array<{ __typename?: 'FeatureFlag', id: string, key: string, value: boolean, workspaceId: string }> | null }, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null } | null }> } };
export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, firstName: string, lastName: string, email: string, canImpersonate: boolean, supportUserHash?: string | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, colorScheme: string, avatarUrl?: string | null, locale: string, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, defaultWorkspace: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null, inviteHash?: string | null, allowImpersonation: boolean, subscriptionStatus: string, activationStatus: string, featureFlags?: Array<{ __typename?: 'FeatureFlag', id: string, key: string, value: boolean, workspaceId: string }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', status: string } | null }, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: string, displayName?: string | null, logo?: string | null, domainName?: string | null } | null }> } };

export type ActivateWorkspaceMutationVariables = Exact<{
input: ActivateWorkspaceInput;
Expand Down Expand Up @@ -1925,6 +1947,9 @@ export const GetCurrentUserDocument = gql`
value
workspaceId
}
currentBillingSubscription {
status
}
}
workspaces {
workspace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const currentWorkspace = {
activationStatus: 'active',
id: '1',
allowImpersonation: true,
currentBillingSubscription: {
status: 'trialing',
},
};
const currentWorkspaceMember = {
id: '1',
Expand Down Expand Up @@ -240,4 +243,35 @@ describe('useOnboardingStatus', () => {

expect(result.current.onboardingStatus).toBe('unpaid');
});

it('should return "completed_without_subscription"', async () => {
const { result } = renderHooks();
const {
setTokenPair,
setBilling,
setCurrentWorkspace,
setCurrentWorkspaceMember,
} = result.current;

act(() => {
setTokenPair(tokenPair);
setBilling(billing);
setCurrentWorkspace({
...currentWorkspace,
subscriptionStatus: 'trialing',
currentBillingSubscription: null,
});
setCurrentWorkspaceMember({
...currentWorkspaceMember,
name: {
firstName: 'John',
lastName: 'Doe',
},
});
});

expect(result.current.onboardingStatus).toBe(
'completed_without_subscription',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type CurrentWorkspace = Pick<
| 'featureFlags'
| 'subscriptionStatus'
| 'activationStatus'
| 'currentBillingSubscription'
>;

export const currentWorkspaceState = createState<CurrentWorkspace | null>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum OnboardingStatus {
OngoingWorkspaceActivation = 'ongoing_workspace_activation',
OngoingProfileCreation = 'ongoing_profile_creation',
Completed = 'completed',
CompletedWithoutSubscription = 'completed_without_subscription',
}

export const getOnboardingStatus = ({
Expand Down Expand Up @@ -75,5 +76,12 @@ export const getOnboardingStatus = ({
return OnboardingStatus.Unpaid;
}

if (
isBillingEnabled === true &&
!currentWorkspace.currentBillingSubscription
) {
return OnboardingStatus.CompletedWithoutSubscription;
}

return OnboardingStatus.Completed;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';

import { useAuth } from '@/auth/hooks/useAuth';
import { billingState } from '@/client-config/states/billingState.ts';
import { SettingsNavigationDrawerItem } from '@/settings/components/SettingsNavigationDrawerItem';
import { AppPath } from '@/types/AppPath';
import { SettingsPath } from '@/types/SettingsPath';
Expand Down Expand Up @@ -35,7 +37,7 @@ export const SettingsNavigationDrawerItems = () => {
}, [signOut, navigate]);

const isCalendarEnabled = useIsFeatureEnabled('IS_CALENDAR_ENABLED');
const isSelfBillingEnabled = useIsFeatureEnabled('IS_SELF_BILLING_ENABLED');
const billing = useRecoilValue(billingState());

return (
<>
Expand Down Expand Up @@ -88,12 +90,13 @@ export const SettingsNavigationDrawerItems = () => {
path={SettingsPath.WorkspaceMembersPage}
Icon={IconUsers}
/>
<SettingsNavigationDrawerItem
label="Billing"
path={SettingsPath.Billing}
Icon={IconCurrencyDollar}
soon={!isSelfBillingEnabled}
/>
{billing?.isBillingEnabled && (
<SettingsNavigationDrawerItem
label="Billing"
path={SettingsPath.Billing}
Icon={IconCurrencyDollar}
/>
)}
<SettingsNavigationDrawerItem
label="Data model"
path={SettingsPath.Objects}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export const DefaultLayout = ({ children }: DefaultLayoutProps) => {
OnboardingStatus.OngoingProfileCreation,
OnboardingStatus.OngoingWorkspaceActivation,
].includes(onboardingStatus)) ||
isMatchingLocation(AppPath.ResetPassword)
isMatchingLocation(AppPath.ResetPassword) ||
(isMatchingLocation(AppPath.PlanRequired) &&
(OnboardingStatus.CompletedWithoutSubscription ||
OnboardingStatus.Canceled))
);
}, [isMatchingLocation, onboardingStatus]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const GET_CURRENT_USER = gql`
value
workspaceId
}
currentBillingSubscription {
status
}
}
workspaces {
workspace {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type FeatureFlagKey =
| 'IS_BLOCKLIST_ENABLED'
| 'IS_CALENDAR_ENABLED'
| 'IS_QUICK_ACTIONS_ENABLED'
| 'IS_SELF_BILLING_ENABLED';
| 'IS_QUICK_ACTIONS_ENABLED';
47 changes: 0 additions & 47 deletions packages/twenty-front/src/pages/auth/PlanRequired.tsx

This file was deleted.

Loading
Loading