The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Update billing page ctas (#12459)
martmullb2c57c5dcc1e
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.tsindex e9af365be95..7745e071359 100644--- a/packages/twenty-front/src/generated-metadata/graphql.ts+++ b/packages/twenty-front/src/generated-metadata/graphql.ts@@ -248,6 +248,7 @@ export type BillingSubscription = {billingSubscriptionItems?: Maybe<Array<BillingSubscriptionItem>>;id: Scalars['UUID']['output'];interval?: Maybe<SubscriptionInterval>;+ metadata: Scalars['JSON']['output'];status: SubscriptionStatus;};@@ -256,6 +257,7 @@ export type BillingSubscriptionItem = {billingProduct?: Maybe<BillingProduct>;hasReachedCurrentPeriodCap: Scalars['Boolean']['output'];id: Scalars['UUID']['output'];+ quantity?: Maybe<Scalars['Float']['output']>;};export type BillingTrialPeriodDto = {@@ -653,13 +655,13 @@ export type FeatureFlagDto = {export enum FeatureFlagKey {IS_AIRTABLE_INTEGRATION_ENABLED = 'IS_AIRTABLE_INTEGRATION_ENABLED',+ IS_AI_ENABLED = 'IS_AI_ENABLED',IS_JSON_FILTER_ENABLED = 'IS_JSON_FILTER_ENABLED',IS_PERMISSIONS_V2_ENABLED = 'IS_PERMISSIONS_V2_ENABLED',IS_POSTGRESQL_INTEGRATION_ENABLED = 'IS_POSTGRESQL_INTEGRATION_ENABLED',IS_STRIPE_INTEGRATION_ENABLED = 'IS_STRIPE_INTEGRATION_ENABLED',IS_UNIQUE_INDEXES_ENABLED = 'IS_UNIQUE_INDEXES_ENABLED',- IS_WORKFLOW_ENABLED = 'IS_WORKFLOW_ENABLED',- IS_AI_ENABLED = 'IS_AI_ENABLED'+ IS_WORKFLOW_ENABLED = 'IS_WORKFLOW_ENABLED'}export type Field = {@@ -1006,6 +1008,7 @@ export type Mutation = {signUpInNewWorkspace: SignUpOutput;skipSyncEmailOnboardingStep: OnboardingStepSuccess;submitFormStep: Scalars['Boolean']['output'];+ switchToEnterprisePlan: BillingUpdateOutput;switchToYearlyInterval: BillingUpdateOutput;syncRemoteTable: RemoteTable;syncRemoteTableSchemaChanges: RemoteTable;diff --git a/packages/twenty-front/src/generated/graphql.tsx b/packages/twenty-front/src/generated/graphql.tsxindex 16102da208e..ab5df2a704a 100644--- a/packages/twenty-front/src/generated/graphql.tsx+++ b/packages/twenty-front/src/generated/graphql.tsx@@ -1,5 +1,5 @@-import * as Apollo from '@apollo/client';import { gql } from '@apollo/client';+import * as Apollo from '@apollo/client';export type Maybe<T> = T | null;export type InputMaybe<T> = Maybe<T>;export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };@@ -240,6 +240,7 @@ export type BillingSubscription = {billingSubscriptionItems?: Maybe<Array<BillingSubscriptionItem>>;id: Scalars['UUID'];interval?: Maybe<SubscriptionInterval>;+ metadata: Scalars['JSON'];status: SubscriptionStatus;};@@ -248,6 +249,7 @@ export type BillingSubscriptionItem = {billingProduct?: Maybe<BillingProduct>;hasReachedCurrentPeriodCap: Scalars['Boolean'];id: Scalars['UUID'];+ quantity?: Maybe<Scalars['Float']>;};export type BillingTrialPeriodDto = {@@ -584,13 +586,13 @@ export type FeatureFlagDto = {export enum FeatureFlagKey {IS_AIRTABLE_INTEGRATION_ENABLED = 'IS_AIRTABLE_INTEGRATION_ENABLED',+ IS_AI_ENABLED = 'IS_AI_ENABLED',IS_JSON_FILTER_ENABLED = 'IS_JSON_FILTER_ENABLED',IS_PERMISSIONS_V2_ENABLED = 'IS_PERMISSIONS_V2_ENABLED',IS_POSTGRESQL_INTEGRATION_ENABLED = 'IS_POSTGRESQL_INTEGRATION_ENABLED',IS_STRIPE_INTEGRATION_ENABLED = 'IS_STRIPE_INTEGRATION_ENABLED',IS_UNIQUE_INDEXES_ENABLED = 'IS_UNIQUE_INDEXES_ENABLED',- IS_WORKFLOW_ENABLED = 'IS_WORKFLOW_ENABLED',- IS_AI_ENABLED = 'IS_AI_ENABLED'+ IS_WORKFLOW_ENABLED = 'IS_WORKFLOW_ENABLED'}export type Field = {@@ -926,6 +928,7 @@ export type Mutation = {signUpInNewWorkspace: SignUpOutput;skipSyncEmailOnboardingStep: OnboardingStepSuccess;submitFormStep: Scalars['Boolean'];+ switchToEnterprisePlan: BillingUpdateOutput;switchToYearlyInterval: BillingUpdateOutput;trackAnalytics: Analytics;updateDatabaseConfigVariable: Scalars['Boolean'];@@ -2705,18 +2708,6 @@ export type ValidatePasswordResetTokenQueryVariables = Exact<{export type ValidatePasswordResetTokenQuery = { __typename?: 'Query', validatePasswordResetToken: { __typename?: 'ValidatePasswordResetToken', id: string, email: string } };-export type BillingBaseProductPricesQueryVariables = Exact<{ [key: string]: never; }>;---export type BillingBaseProductPricesQuery = { __typename?: 'Query', plans: Array<{ __typename?: 'BillingPlanOutput', planKey: BillingPlanKey, baseProduct: { __typename?: 'BillingProduct', name: string, prices?: Array<{ __typename?: 'BillingPriceLicensedDTO', unitAmount: number, stripePriceId: string, recurringInterval: SubscriptionInterval } | { __typename?: 'BillingPriceMeteredDTO' }> | null } }> };--export type BillingPortalSessionQueryVariables = Exact<{- returnUrlPath?: InputMaybe<Scalars['String']>;-}>;---export type BillingPortalSessionQuery = { __typename?: 'Query', billingPortalSession: { __typename?: 'BillingSessionOutput', url?: string | null } };-export type CheckoutSessionMutationVariables = Exact<{recurringInterval: SubscriptionInterval;successUrlPath?: InputMaybe<Scalars['String']>;@@ -2732,16 +2723,33 @@ export type EndSubscriptionTrialPeriodMutationVariables = Exact<{ [key: string]:export type EndSubscriptionTrialPeriodMutation = { __typename?: 'Mutation', endSubscriptionTrialPeriod: { __typename?: 'BillingEndTrialPeriodOutput', status?: SubscriptionStatus | null, hasPaymentMethod: boolean } };-export type GetMeteredProductsUsageQueryVariables = Exact<{ [key: string]: never; }>;+export type SwitchSubscriptionToEnterprisePlanMutationVariables = Exact<{ [key: string]: never; }>;-export type GetMeteredProductsUsageQuery = { __typename?: 'Query', getMeteredProductsUsage: Array<{ __typename?: 'BillingMeteredProductUsageOutput', productKey: BillingProductKey, usageQuantity: number, freeTierQuantity: number, freeTrialQuantity: number, unitPriceCents: number, totalCostCents: number }> };+export type SwitchSubscriptionToEnterprisePlanMutation = { __typename?: 'Mutation', switchToEnterprisePlan: { __typename?: 'BillingUpdateOutput', success: boolean } };export type SwitchSubscriptionToYearlyIntervalMutationVariables = Exact<{ [key: string]: never; }>;export type SwitchSubscriptionToYearlyIntervalMutation = { __typename?: 'Mutation', switchToYearlyInterval: { __typename?: 'BillingUpdateOutput', success: boolean } };+export type BillingBaseProductPricesQueryVariables = Exact<{ [key: string]: never; }>;+++export type BillingBaseProductPricesQuery = { __typename?: 'Query', plans: Array<{ __typename?: 'BillingPlanOutput', planKey: BillingPlanKey, baseProduct: { __typename?: 'BillingProduct', name: string, prices?: Array<{ __typename?: 'BillingPriceLicensedDTO', unitAmount: number, stripePriceId: string, recurringInterval: SubscriptionInterval } | { __typename?: 'BillingPriceMeteredDTO' }> | null } }> };++export type BillingPortalSessionQueryVariables = Exact<{+ returnUrlPath?: InputMaybe<Scalars['String']>;+}>;+++export type BillingPortalSessionQuery = { __typename?: 'Query', billingPortalSession: { __typename?: 'BillingSessionOutput', url?: string | null } };++export type GetMeteredProductsUsageQueryVariables = Exact<{ [key: string]: never; }>;+++export type GetMeteredProductsUsageQuery = { __typename?: 'Query', getMeteredProductsUsage: Array<{ __typename?: 'BillingMeteredProductUsageOutput', productKey: BillingProductKey, usageQuantity: number, freeTierQuantity: number, freeTrialQuantity: number, unitPriceCents: number, totalCostCents: number }> };+export type GetClientConfigQueryVariables = Exact<{ [key: string]: never; }>;@@ -2960,7 +2968,7 @@ export type OnDbEventSubscriptionVariables = Exact<{export type OnDbEventSubscription = { __typename?: 'Subscription', onDbEvent: { __typename?: 'OnDbEventDTO', eventDate: string, action: DatabaseEventAction, objectNameSingular: string, updatedFields?: Array<string> | null, record: any } };-export type UserQueryFragmentFragment = { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canAccessFullAdminPanel: boolean, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, deletedWorkspaceMembers?: Array<{ __typename?: 'DeletedWorkspaceMember', id: any, avatarUrl?: string | null, userEmail: string, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentUserWorkspace?: { __typename?: 'UserWorkspace', settingsPermissions?: Array<SettingPermissionType> | null, objectRecordsPermissions?: Array<PermissionsOnAllObjectRecords> | null, objectPermissions?: Array<{ __typename?: 'ObjectPermission', objectMetadataId: string, canReadObjectRecords?: boolean | null, canUpdateObjectRecords?: boolean | null, canSoftDeleteObjectRecords?: boolean | null, canDestroyObjectRecords?: boolean | null }> | null } | null, currentWorkspace?: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, customDomain?: string | null, isCustomDomainEnabled: boolean, metadataVersion: number, workspaceMembersCount?: number | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null }, featureFlags?: Array<{ __typename?: 'FeatureFlagDTO', key: FeatureFlagKey, value: boolean }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null, billingSubscriptionItems?: Array<{ __typename?: 'BillingSubscriptionItem', id: any, hasReachedCurrentPeriodCap: boolean, billingProduct?: { __typename?: 'BillingProduct', name: string, description: string, metadata: { __typename?: 'BillingProductMetadata', planKey: BillingPlanKey, priceUsageBased: BillingUsageType, productKey: BillingProductKey } } | null }> | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus }>, defaultRole?: { __typename?: 'Role', id: string, label: string, description?: string | null, icon?: string | null, canUpdateAllSettings: boolean, isEditable: boolean, canReadAllObjectRecords: boolean, canUpdateAllObjectRecords: boolean, canSoftDeleteAllObjectRecords: boolean, canDestroyAllObjectRecords: boolean } | null } | null, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string, customDomain?: string | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null } } | null }> };+export type UserQueryFragmentFragment = { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canAccessFullAdminPanel: boolean, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, deletedWorkspaceMembers?: Array<{ __typename?: 'DeletedWorkspaceMember', id: any, avatarUrl?: string | null, userEmail: string, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentUserWorkspace?: { __typename?: 'UserWorkspace', settingsPermissions?: Array<SettingPermissionType> | null, objectRecordsPermissions?: Array<PermissionsOnAllObjectRecords> | null, objectPermissions?: Array<{ __typename?: 'ObjectPermission', objectMetadataId: string, canReadObjectRecords?: boolean | null, canUpdateObjectRecords?: boolean | null, canSoftDeleteObjectRecords?: boolean | null, canDestroyObjectRecords?: boolean | null }> | null } | null, currentWorkspace?: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, customDomain?: string | null, isCustomDomainEnabled: boolean, metadataVersion: number, workspaceMembersCount?: number | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null }, featureFlags?: Array<{ __typename?: 'FeatureFlagDTO', key: FeatureFlagKey, value: boolean }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null, metadata: any, billingSubscriptionItems?: Array<{ __typename?: 'BillingSubscriptionItem', id: any, hasReachedCurrentPeriodCap: boolean, quantity?: number | null, billingProduct?: { __typename?: 'BillingProduct', name: string, description: string, metadata: { __typename?: 'BillingProductMetadata', planKey: BillingPlanKey, priceUsageBased: BillingUsageType, productKey: BillingProductKey } } | null }> | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, metadata: any }>, defaultRole?: { __typename?: 'Role', id: string, label: string, description?: string | null, icon?: string | null, canUpdateAllSettings: boolean, isEditable: boolean, canReadAllObjectRecords: boolean, canUpdateAllObjectRecords: boolean, canSoftDeleteAllObjectRecords: boolean, canDestroyAllObjectRecords: boolean } | null } | null, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string, customDomain?: string | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null } } | null }> };export type DeleteUserAccountMutationVariables = Exact<{ [key: string]: never; }>;@@ -2977,7 +2985,7 @@ export type UploadProfilePictureMutation = { __typename?: 'Mutation', uploadProfexport type GetCurrentUserQueryVariables = Exact<{ [key: string]: never; }>;-export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canAccessFullAdminPanel: boolean, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, deletedWorkspaceMembers?: Array<{ __typename?: 'DeletedWorkspaceMember', id: any, avatarUrl?: string | null, userEmail: string, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentUserWorkspace?: { __typename?: 'UserWorkspace', settingsPermissions?: Array<SettingPermissionType> | null, objectRecordsPermissions?: Array<PermissionsOnAllObjectRecords> | null, objectPermissions?: Array<{ __typename?: 'ObjectPermission', objectMetadataId: string, canReadObjectRecords?: boolean | null, canUpdateObjectRecords?: boolean | null, canSoftDeleteObjectRecords?: boolean | null, canDestroyObjectRecords?: boolean | null }> | null } | null, currentWorkspace?: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, customDomain?: string | null, isCustomDomainEnabled: boolean, metadataVersion: number, workspaceMembersCount?: number | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null }, featureFlags?: Array<{ __typename?: 'FeatureFlagDTO', key: FeatureFlagKey, value: boolean }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null, billingSubscriptionItems?: Array<{ __typename?: 'BillingSubscriptionItem', id: any, hasReachedCurrentPeriodCap: boolean, billingProduct?: { __typename?: 'BillingProduct', name: string, description: string, metadata: { __typename?: 'BillingProductMetadata', planKey: BillingPlanKey, priceUsageBased: BillingUsageType, productKey: BillingProductKey } } | null }> | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus }>, defaultRole?: { __typename?: 'Role', id: string, label: string, description?: string | null, icon?: string | null, canUpdateAllSettings: boolean, isEditable: boolean, canReadAllObjectRecords: boolean, canUpdateAllObjectRecords: boolean, canSoftDeleteAllObjectRecords: boolean, canDestroyAllObjectRecords: boolean } | null } | null, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string, customDomain?: string | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null } } | null }> } };+export type GetCurrentUserQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: any, firstName: string, lastName: string, email: string, canAccessFullAdminPanel: boolean, canImpersonate: boolean, supportUserHash?: string | null, onboardingStatus?: OnboardingStatus | null, userVars: any, workspaceMember?: { __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } } | null, workspaceMembers?: Array<{ __typename?: 'WorkspaceMember', id: any, colorScheme: string, avatarUrl?: string | null, locale?: string | null, userEmail: string, timeZone?: string | null, dateFormat?: WorkspaceMemberDateFormatEnum | null, timeFormat?: WorkspaceMemberTimeFormatEnum | null, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, deletedWorkspaceMembers?: Array<{ __typename?: 'DeletedWorkspaceMember', id: any, avatarUrl?: string | null, userEmail: string, name: { __typename?: 'FullName', firstName: string, lastName: string } }> | null, currentUserWorkspace?: { __typename?: 'UserWorkspace', settingsPermissions?: Array<SettingPermissionType> | null, objectRecordsPermissions?: Array<PermissionsOnAllObjectRecords> | null, objectPermissions?: Array<{ __typename?: 'ObjectPermission', objectMetadataId: string, canReadObjectRecords?: boolean | null, canUpdateObjectRecords?: boolean | null, canSoftDeleteObjectRecords?: boolean | null, canDestroyObjectRecords?: boolean | null }> | null } | null, currentWorkspace?: { __typename?: 'Workspace', id: any, displayName?: string | null, logo?: string | null, inviteHash?: string | null, allowImpersonation: boolean, activationStatus: WorkspaceActivationStatus, isPublicInviteLinkEnabled: boolean, isGoogleAuthEnabled: boolean, isMicrosoftAuthEnabled: boolean, isPasswordAuthEnabled: boolean, subdomain: string, hasValidEnterpriseKey: boolean, customDomain?: string | null, isCustomDomainEnabled: boolean, metadataVersion: number, workspaceMembersCount?: number | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null }, featureFlags?: Array<{ __typename?: 'FeatureFlagDTO', key: FeatureFlagKey, value: boolean }> | null, currentBillingSubscription?: { __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, interval?: SubscriptionInterval | null, metadata: any, billingSubscriptionItems?: Array<{ __typename?: 'BillingSubscriptionItem', id: any, hasReachedCurrentPeriodCap: boolean, quantity?: number | null, billingProduct?: { __typename?: 'BillingProduct', name: string, description: string, metadata: { __typename?: 'BillingProductMetadata', planKey: BillingPlanKey, priceUsageBased: BillingUsageType, productKey: BillingProductKey } } | null }> | null } | null, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: any, status: SubscriptionStatus, metadata: any }>, defaultRole?: { __typename?: 'Role', id: string, label: string, description?: string | null, icon?: string | null, canUpdateAllSettings: boolean, isEditable: boolean, canReadAllObjectRecords: boolean, canUpdateAllObjectRecords: boolean, canSoftDeleteAllObjectRecords: boolean, canDestroyAllObjectRecords: boolean } | null } | null, workspaces: Array<{ __typename?: 'UserWorkspace', workspace?: { __typename?: 'Workspace', id: any, logo?: string | null, displayName?: string | null, subdomain: string, customDomain?: string | null, workspaceUrls: { __typename?: 'WorkspaceUrls', subdomainUrl: string, customUrl?: string | null } } | null }> } };export type ActivateWorkflowVersionMutationVariables = Exact<{workflowVersionId: Scalars['String'];@@ -3327,9 +3335,11 @@ export const UserQueryFragmentFragmentDoc = gql`idstatusinterval+ metadatabillingSubscriptionItems {idhasReachedCurrentPeriodCap+ quantitybillingProduct {namedescription@@ -3344,6 +3354,7 @@ export const UserQueryFragmentFragmentDoc = gql`billingSubscriptions {idstatus+ metadata}workspaceMembersCountdefaultRole {@@ -4338,85 +4349,6 @@ export function useValidatePasswordResetTokenLazyQuery(baseOptions?: Apollo.Lazyexport type ValidatePasswordResetTokenQueryHookResult = ReturnType<typeof useValidatePasswordResetTokenQuery>;export type ValidatePasswordResetTokenLazyQueryHookResult = ReturnType<typeof useValidatePasswordResetTokenLazyQuery>;export type ValidatePasswordResetTokenQueryResult = Apollo.QueryResult<ValidatePasswordResetTokenQuery, ValidatePasswordResetTokenQueryVariables>;-export const BillingBaseProductPricesDocument = gql`- query billingBaseProductPrices {- plans {- planKey- baseProduct {- name- prices {- ... on BillingPriceLicensedDTO {- unitAmount- stripePriceId- recurringInterval- }- }- }- }-}- `;--/**- * __useBillingBaseProductPricesQuery__- *- * To run a query within a React component, call `useBillingBaseProductPricesQuery` and pass it any options that fit your needs.- * When your component renders, `useBillingBaseProductPricesQuery` returns an object from Apollo Client that contains loading, error, and data properties- * you can use to render your UI.- *- * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;- *- * @example- * const { data, loading, error } = useBillingBaseProductPricesQuery({- * variables: {- * },- * });- */-export function useBillingBaseProductPricesQuery(baseOptions?: Apollo.QueryHookOptions<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>) {- const options = {...defaultOptions, ...baseOptions}- return Apollo.useQuery<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>(BillingBaseProductPricesDocument, options);- }-export function useBillingBaseProductPricesLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>) {- const options = {...defaultOptions, ...baseOptions}- return Apollo.useLazyQuery<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>(BillingBaseProductPricesDocument, options);- }-export type BillingBaseProductPricesQueryHookResult = ReturnType<typeof useBillingBaseProductPricesQuery>;-export type BillingBaseProductPricesLazyQueryHookResult = ReturnType<typeof useBillingBaseProductPricesLazyQuery>;-export type BillingBaseProductPricesQueryResult = Apollo.QueryResult<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>;-export const BillingPortalSessionDocument = gql`- query BillingPortalSession($returnUrlPath: String) {- billingPortalSession(returnUrlPath: $returnUrlPath) {- url- }-}- `;--/**- * __useBillingPortalSessionQuery__- *- * To run a query within a React component, call `useBillingPortalSessionQuery` and pass it any options that fit your needs.- * When your component renders, `useBillingPortalSessionQuery` returns an object from Apollo Client that contains loading, error, and data properties- * you can use to render your UI.- *- * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;- *- * @example- * const { data, loading, error } = useBillingPortalSessionQuery({- * variables: {- * returnUrlPath: // value for 'returnUrlPath'- * },- * });- */-export function useBillingPortalSessionQuery(baseOptions?: Apollo.QueryHookOptions<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>) {- const options = {...defaultOptions, ...baseOptions}- return Apollo.useQuery<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>(BillingPortalSessionDocument, options);- }-export function useBillingPortalSessionLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>) {- const options = {...defaultOptions, ...baseOptions}- return Apollo.useLazyQuery<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>(BillingPortalSessionDocument, options);- }-export type BillingPortalSessionQueryHookResult = ReturnType<typeof useBillingPortalSessionQuery>;-export type BillingPortalSessionLazyQueryHookResult = ReturnType<typeof useBillingPortalSessionLazyQuery>;-export type BillingPortalSessionQueryResult = Apollo.QueryResult<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>;export const CheckoutSessionDocument = gql`mutation CheckoutSession($recurringInterval: SubscriptionInterval!, $successUrlPath: String, $plan: BillingPlanKey!, $requirePaymentMethod: Boolean!) {checkoutSession(@@ -4491,45 +4423,38 @@ export function useEndSubscriptionTrialPeriodMutation(baseOptions?: Apollo.Mutatexport type EndSubscriptionTrialPeriodMutationHookResult = ReturnType<typeof useEndSubscriptionTrialPeriodMutation>;export type EndSubscriptionTrialPeriodMutationResult = Apollo.MutationResult<EndSubscriptionTrialPeriodMutation>;export type EndSubscriptionTrialPeriodMutationOptions = Apollo.BaseMutationOptions<EndSubscriptionTrialPeriodMutation, EndSubscriptionTrialPeriodMutationVariables>;-export const GetMeteredProductsUsageDocument = gql`- query GetMeteredProductsUsage {- getMeteredProductsUsage {- productKey- usageQuantity- freeTierQuantity- freeTrialQuantity- unitPriceCents- totalCostCents+export const SwitchSubscriptionToEnterprisePlanDocument = gql`+ mutation SwitchSubscriptionToEnterprisePlan {+ switchToEnterprisePlan {+ success}}`;+export type SwitchSubscriptionToEnterprisePlanMutationFn = Apollo.MutationFunction<SwitchSubscriptionToEnterprisePlanMutation, SwitchSubscriptionToEnterprisePlanMutationVariables>;/**- * __useGetMeteredProductsUsageQuery__+ * __useSwitchSubscriptionToEnterprisePlanMutation__*- * To run a query within a React component, call `useGetMeteredProductsUsageQuery` and pass it any options that fit your needs.- * When your component renders, `useGetMeteredProductsUsageQuery` returns an object from Apollo Client that contains loading, error, and data properties- * you can use to render your UI.+ * To run a mutation, you first call `useSwitchSubscriptionToEnterprisePlanMutation` within a React component and pass it any options that fit your needs.+ * When your component renders, `useSwitchSubscriptionToEnterprisePlanMutation` returns a tuple that includes:+ * - A mutate function that you can call at any time to execute the mutation+ * - An object with fields that represent the current status of the mutation's execution*- * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;** @example- * const { data, loading, error } = useGetMeteredProductsUsageQuery({+ * const [switchSubscriptionToEnterprisePlanMutation, { data, loading, error }] = useSwitchSubscriptionToEnterprisePlanMutation({* variables: {* },* });*/-export function useGetMeteredProductsUsageQuery(baseOptions?: Apollo.QueryHookOptions<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>) {+export function useSwitchSubscriptionToEnterprisePlanMutation(baseOptions?: Apollo.MutationHookOptions<SwitchSubscriptionToEnterprisePlanMutation, SwitchSubscriptionToEnterprisePlanMutationVariables>) {const options = {...defaultOptions, ...baseOptions}- return Apollo.useQuery<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>(GetMeteredProductsUsageDocument, options);+ return Apollo.useMutation<SwitchSubscriptionToEnterprisePlanMutation, SwitchSubscriptionToEnterprisePlanMutationVariables>(SwitchSubscriptionToEnterprisePlanDocument, options);}-export function useGetMeteredProductsUsageLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>) {- const options = {...defaultOptions, ...baseOptions}- return Apollo.useLazyQuery<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>(GetMeteredProductsUsageDocument, options);- }-export type GetMeteredProductsUsageQueryHookResult = ReturnType<typeof useGetMeteredProductsUsageQuery>;-export type GetMeteredProductsUsageLazyQueryHookResult = ReturnType<typeof useGetMeteredProductsUsageLazyQuery>;-export type GetMeteredProductsUsageQueryResult = Apollo.QueryResult<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>;+export type SwitchSubscriptionToEnterprisePlanMutationHookResult = ReturnType<typeof useSwitchSubscriptionToEnterprisePlanMutation>;+export type SwitchSubscriptionToEnterprisePlanMutationResult = Apollo.MutationResult<SwitchSubscriptionToEnterprisePlanMutation>;+export type SwitchSubscriptionToEnterprisePlanMutationOptions = Apollo.BaseMutationOptions<SwitchSubscriptionToEnterprisePlanMutation, SwitchSubscriptionToEnterprisePlanMutationVariables>;export const SwitchSubscriptionToYearlyIntervalDocument = gql`mutation SwitchSubscriptionToYearlyInterval {switchToYearlyInterval {@@ -4562,6 +4487,124 @@ export function useSwitchSubscriptionToYearlyIntervalMutation(baseOptions?: Apolexport type SwitchSubscriptionToYearlyIntervalMutationHookResult = ReturnType<typeof useSwitchSubscriptionToYearlyIntervalMutation>;export type SwitchSubscriptionToYearlyIntervalMutationResult = Apollo.MutationResult<SwitchSubscriptionToYearlyIntervalMutation>;export type SwitchSubscriptionToYearlyIntervalMutationOptions = Apollo.BaseMutationOptions<SwitchSubscriptionToYearlyIntervalMutation, SwitchSubscriptionToYearlyIntervalMutationVariables>;+export const BillingBaseProductPricesDocument = gql`+ query billingBaseProductPrices {+ plans {+ planKey+ baseProduct {+ name+ prices {+ ... on BillingPriceLicensedDTO {+ unitAmount+ stripePriceId+ recurringInterval+ }+ }+ }+ }+}+ `;++/**+ * __useBillingBaseProductPricesQuery__+ *+ * To run a query within a React component, call `useBillingBaseProductPricesQuery` and pass it any options that fit your needs.+ * When your component renders, `useBillingBaseProductPricesQuery` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useBillingBaseProductPricesQuery({+ * variables: {+ * },+ * });+ */+export function useBillingBaseProductPricesQuery(baseOptions?: Apollo.QueryHookOptions<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>) {+ const options = {...defaultOptions, ...baseOptions}+ return Apollo.useQuery<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>(BillingBaseProductPricesDocument, options);+ }+export function useBillingBaseProductPricesLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>) {+ const options = {...defaultOptions, ...baseOptions}+ return Apollo.useLazyQuery<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>(BillingBaseProductPricesDocument, options);+ }+export type BillingBaseProductPricesQueryHookResult = ReturnType<typeof useBillingBaseProductPricesQuery>;+export type BillingBaseProductPricesLazyQueryHookResult = ReturnType<typeof useBillingBaseProductPricesLazyQuery>;+export type BillingBaseProductPricesQueryResult = Apollo.QueryResult<BillingBaseProductPricesQuery, BillingBaseProductPricesQueryVariables>;+export const BillingPortalSessionDocument = gql`+ query BillingPortalSession($returnUrlPath: String) {+ billingPortalSession(returnUrlPath: $returnUrlPath) {+ url+ }+}+ `;++/**+ * __useBillingPortalSessionQuery__+ *+ * To run a query within a React component, call `useBillingPortalSessionQuery` and pass it any options that fit your needs.+ * When your component renders, `useBillingPortalSessionQuery` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useBillingPortalSessionQuery({+ * variables: {+ * returnUrlPath: // value for 'returnUrlPath'+ * },+ * });+ */+export function useBillingPortalSessionQuery(baseOptions?: Apollo.QueryHookOptions<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>) {+ const options = {...defaultOptions, ...baseOptions}+ return Apollo.useQuery<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>(BillingPortalSessionDocument, options);+ }+export function useBillingPortalSessionLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>) {+ const options = {...defaultOptions, ...baseOptions}+ return Apollo.useLazyQuery<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>(BillingPortalSessionDocument, options);+ }+export type BillingPortalSessionQueryHookResult = ReturnType<typeof useBillingPortalSessionQuery>;+export type BillingPortalSessionLazyQueryHookResult = ReturnType<typeof useBillingPortalSessionLazyQuery>;+export type BillingPortalSessionQueryResult = Apollo.QueryResult<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>;+export const GetMeteredProductsUsageDocument = gql`+ query GetMeteredProductsUsage {+ getMeteredProductsUsage {+ productKey+ usageQuantity+ freeTierQuantity+ freeTrialQuantity+ unitPriceCents+ totalCostCents+ }+}+ `;++/**+ * __useGetMeteredProductsUsageQuery__+ *+ * To run a query within a React component, call `useGetMeteredProductsUsageQuery` and pass it any options that fit your needs.+ * When your component renders, `useGetMeteredProductsUsageQuery` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useGetMeteredProductsUsageQuery({+ * variables: {+ * },+ * });+ */+export function useGetMeteredProductsUsageQuery(baseOptions?: Apollo.QueryHookOptions<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>) {+ const options = {...defaultOptions, ...baseOptions}+ return Apollo.useQuery<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>(GetMeteredProductsUsageDocument, options);+ }+export function useGetMeteredProductsUsageLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>) {+ const options = {...defaultOptions, ...baseOptions}+ return Apollo.useLazyQuery<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>(GetMeteredProductsUsageDocument, options);+ }+export type GetMeteredProductsUsageQueryHookResult = ReturnType<typeof useGetMeteredProductsUsageQuery>;+export type GetMeteredProductsUsageLazyQueryHookResult = ReturnType<typeof useGetMeteredProductsUsageLazyQuery>;+export type GetMeteredProductsUsageQueryResult = Apollo.QueryResult<GetMeteredProductsUsageQuery, GetMeteredProductsUsageQueryVariables>;export const GetClientConfigDocument = gql`query GetClientConfig {clientConfig {diff --git a/packages/twenty-front/src/modules/billing/components/SettingsBillingMonthlyCreditsSection.tsx b/packages/twenty-front/src/modules/billing/components/SettingsBillingMonthlyCreditsSection.tsxindex e02d8b71b90..182dbfd8092 100644--- a/packages/twenty-front/src/modules/billing/components/SettingsBillingMonthlyCreditsSection.tsx+++ b/packages/twenty-front/src/modules/billing/components/SettingsBillingMonthlyCreditsSection.tsx@@ -10,18 +10,7 @@ import { BACKGROUND_LIGHT, COLOR } from 'twenty-ui/theme';import { SubscriptionStatus } from '~/generated/graphql';import { formatAmount } from '~/utils/format/formatAmount';import { formatNumber } from '~/utils/format/number';--const StyledMonthlyCreditsContainer = styled.div`- border-radius: ${({ theme }) => theme.border.radius.md};- border: 1px solid ${({ theme }) => theme.border.color.medium};- background-color: ${({ theme }) => theme.background.secondary};- padding: ${({ theme }) => theme.spacing(3)};- width: 100%;-- display: flex;- flex-direction: column;- gap: ${({ theme }) => theme.spacing(3)};-`;+import { SubscriptionInfoContainer } from '@/billing/components/SubscriptionInfoContainer';const StyledLineSeparator = styled.div`width: 100%;@@ -57,7 +46,7 @@ export const SettingsBillingMonthlyCreditsSection = () => {title={t`Monthly Credits`}description={t`Track your monthly workflow credit consumption.`}/>- <StyledMonthlyCreditsContainer>+ <SubscriptionInfoContainer><SettingsBillingLabelValueItemlabel={t`Free Credits Used`}value={`${formattedFreeUsageQuantity}/${formatAmount(includedFreeQuantity)}`}@@ -91,7 +80,7 @@ export const SettingsBillingMonthlyCreditsSection = () => {value={`$${formatNumber(totalCostCents / 100, 2)}`}/>)}- </StyledMonthlyCreditsContainer>+ </SubscriptionInfoContainer></Section>);};diff --git a/packages/twenty-front/src/modules/billing/components/SettingsBillingSubscriptionInfo.tsx b/packages/twenty-front/src/modules/billing/components/SettingsBillingSubscriptionInfo.tsxnew file mode 100644index 00000000000..c5f17ff4207--- /dev/null+++ b/packages/twenty-front/src/modules/billing/components/SettingsBillingSubscriptionInfo.tsx@@ -0,0 +1,238 @@+import { SubscriptionInfoContainer } from '@/billing/components/SubscriptionInfoContainer';+import { SubscriptionInfoRowContainer } from '@/billing/components/SubscriptionInfoRowContainer';++import {+ H2Title,+ IconCalendarEvent,+ IconTag,+ IconUsers,+ IconArrowUp,+} from 'twenty-ui/display';+import { Button } from 'twenty-ui/input';+import { Section } from 'twenty-ui/layout';+import styled from '@emotion/styled';+import { useLingui } from '@lingui/react/macro';+import {+ BillingPlanKey,+ BillingPlanOutput,+ BillingProductKey,+ SubscriptionInterval,+ SubscriptionStatus,+ useBillingBaseProductPricesQuery,+ useSwitchSubscriptionToEnterprisePlanMutation,+ useSwitchSubscriptionToYearlyIntervalMutation,+} from '~/generated/graphql';+import { useRecoilState } from 'recoil';+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';+import { Tag } from 'twenty-ui/components';+import { useModal } from '@/ui/layout/modal/hooks/useModal';+import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';+import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal';+import { formatMonthlyPrices } from '@/billing/utils/formatMonthlyPrices';+import { isDefined } from 'twenty-shared/utils';+import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';+import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';++const SWITCH_BILLING_INTERVAL_MODAL_ID = 'switch-billing-interval-modal';++const SWITCH_BILLING_PLAN_MODAL_ID = 'switch-billing-plan-modal';++const StyledSwitchButtonContainer = styled.div`+ align-items: center;+ display: flex;+ gap: ${({ theme }) => theme.spacing(2)};+ margin-top: ${({ theme }) => theme.spacing(4)};+`;++export const SettingsBillingSubscriptionInfo = () => {+ const { t } = useLingui();++ const { openModal } = useModal();++ const { enqueueSnackBar } = useSnackBar();++ const subscriptionStatus = useSubscriptionStatus();++ const { data: pricesData } = useBillingBaseProductPricesQuery();++ const [switchToYearlyInterval] =+ useSwitchSubscriptionToYearlyIntervalMutation();++ const [switchToEnterprisePlan] =+ useSwitchSubscriptionToEnterprisePlanMutation();++ const [currentWorkspace, setCurrentWorkspace] = useRecoilState(+ currentWorkspaceState,+ );++ const isMonthlyPlan =+ currentWorkspace?.currentBillingSubscription?.interval ===+ SubscriptionInterval.Month;++ const isYearlyPlan =+ currentWorkspace?.currentBillingSubscription?.interval ===+ SubscriptionInterval.Year;++ const isProPlan =+ currentWorkspace?.currentBillingSubscription?.metadata['plan'] ===+ BillingPlanKey.PRO;++ const isEnterprisePlan =+ currentWorkspace?.currentBillingSubscription?.metadata['plan'] ===+ BillingPlanKey.ENTERPRISE;++ const canSwitchSubscription =+ subscriptionStatus !== SubscriptionStatus.PastDue;++ const planTag = isProPlan ? (+ <Tag color={'sky'} text={t`Pro`} />+ ) : isEnterprisePlan ? (+ <Tag color={'purple'} text={t`Organization`} />+ ) : undefined;++ const intervalLabel = isMonthlyPlan+ ? t`Monthly`+ : isYearlyPlan+ ? t`Yearly`+ : undefined;++ const seats =+ currentWorkspace?.currentBillingSubscription?.billingSubscriptionItems?.find(+ (item) =>+ item.billingProduct?.metadata.productKey ===+ BillingProductKey.BASE_PRODUCT,+ )?.quantity as number | undefined;++ const baseProductPrices = pricesData?.plans as BillingPlanOutput[];++ const formattedPrices = formatMonthlyPrices(baseProductPrices);++ const yearlyPrice =+ formattedPrices?.[+ currentWorkspace?.currentBillingSubscription?.metadata[+ 'plan'+ ] as BillingPlanKey+ ]?.[SubscriptionInterval.Year];++ const enterprisePrice =+ formattedPrices?.[BillingPlanKey.ENTERPRISE]?.[+ currentWorkspace?.currentBillingSubscription?.interval as+ | SubscriptionInterval.Month+ | SubscriptionInterval.Year+ ];++ const switchInterval = async () => {+ try {+ await switchToYearlyInterval();+ if (isDefined(currentWorkspace?.currentBillingSubscription)) {+ const newCurrentWorkspace = {+ ...currentWorkspace,+ currentBillingSubscription: {+ ...currentWorkspace?.currentBillingSubscription,+ interval: SubscriptionInterval.Year,+ },+ };+ setCurrentWorkspace(newCurrentWorkspace);+ }+ enqueueSnackBar(t`Subscription has been switched to Yearly.`, {+ variant: SnackBarVariant.Success,+ });+ } catch (error: any) {+ enqueueSnackBar(t`Error while switching subscription to Yearly.`, {+ variant: SnackBarVariant.Error,+ });+ }+ };++ const switchPlan = async () => {+ try {+ await switchToEnterprisePlan();+ if (isDefined(currentWorkspace?.currentBillingSubscription)) {+ const newCurrentWorkspace = {+ ...currentWorkspace,+ currentBillingSubscription: {+ ...currentWorkspace?.currentBillingSubscription,+ metadata: {+ ...currentWorkspace?.currentBillingSubscription.metadata,+ plan: BillingPlanKey.ENTERPRISE,+ },+ },+ };+ setCurrentWorkspace(newCurrentWorkspace);+ }+ enqueueSnackBar(t`Subscription has been switched to Organization Plan.`, {+ variant: SnackBarVariant.Success,+ });+ } catch (error: any) {+ enqueueSnackBar(+ t`Error while switching subscription to Organization Plan.`,+ {+ variant: SnackBarVariant.Error,+ },+ );+ }+ };++ return (+ <Section>+ <H2Title title={t`Subscription`} description={t`About my subscription`} />+ <SubscriptionInfoContainer>+ <SubscriptionInfoRowContainer+ label={t`Plan`}+ Icon={IconTag}+ value={planTag}+ />+ <SubscriptionInfoRowContainer+ label={t`Billing interval`}+ Icon={IconCalendarEvent}+ value={intervalLabel}+ />+ <SubscriptionInfoRowContainer+ label={t`Seats`}+ Icon={IconUsers}+ value={seats}+ />+ </SubscriptionInfoContainer>+ <StyledSwitchButtonContainer>+ {isMonthlyPlan && (+ <Button+ Icon={IconArrowUp}+ title={t`Switch to Yearly`}+ variant="secondary"+ onClick={() => openModal(SWITCH_BILLING_INTERVAL_MODAL_ID)}+ disabled={!canSwitchSubscription}+ />+ )}+ {isProPlan && (+ <Button+ Icon={IconArrowUp}+ title={t`Switch to Organization`}+ variant="secondary"+ onClick={() => openModal(SWITCH_BILLING_PLAN_MODAL_ID)}+ disabled={!canSwitchSubscription}+ />+ )}+ </StyledSwitchButtonContainer>+ <ConfirmationModal+ modalId={SWITCH_BILLING_INTERVAL_MODAL_ID}+ title={t`Change to Yearly?`}+ subtitle={t`You will be charged $${yearlyPrice} per user per month billed annually. A prorata with your current subscription will be applied.`}+ onConfirmClick={switchInterval}+ confirmButtonText={t`Confirm`}+ confirmButtonAccent={'blue'}+ />+ <ConfirmationModal+ modalId={SWITCH_BILLING_PLAN_MODAL_ID}+ title={t`Change to Organization Plan?`}+ subtitle={+ isYearlyPlan+ ? t`You will be charged $${enterprisePrice} per user per month billed annually.`+ : t`You will be charged $${enterprisePrice} per user per month.`+ }+ onConfirmClick={switchPlan}+ confirmButtonText={t`Confirm`}+ confirmButtonAccent={'blue'}+ />+ </Section>+ );+};diff --git a/packages/twenty-front/src/modules/billing/components/SubscriptionInfoContainer.tsx b/packages/twenty-front/src/modules/billing/components/SubscriptionInfoContainer.tsxnew file mode 100644index 00000000000..3cf74d26367--- /dev/null+++ b/packages/twenty-front/src/modules/billing/components/SubscriptionInfoContainer.tsx@@ -0,0 +1,14 @@+import styled from '@emotion/styled';++const StyledSubscriptionInfoContainer = styled.div`+ background-color: ${({ theme }) => theme.background.secondary};+ border: 1px solid ${({ theme }) => theme.border.color.medium};+ border-radius: ${({ theme }) => theme.border.radius.md};+ display: flex;+ flex-direction: column;+ gap: ${({ theme }) => theme.spacing(3)};+ padding: ${({ theme }) => theme.spacing(3)};+ width: 100%;+`;++export { StyledSubscriptionInfoContainer as SubscriptionInfoContainer };diff --git a/packages/twenty-front/src/modules/billing/components/SubscriptionInfoRowContainer.tsx b/packages/twenty-front/src/modules/billing/components/SubscriptionInfoRowContainer.tsxnew file mode 100644index 00000000000..e1eaf11aef6--- /dev/null+++ b/packages/twenty-front/src/modules/billing/components/SubscriptionInfoRowContainer.tsx@@ -0,0 +1,48 @@+import { IconComponent } from 'twenty-ui/display';+import React from 'react';+import styled from '@emotion/styled';+import { useTheme } from '@emotion/react';++type SubscriptionInfoRowContainerProps = {+ Icon: IconComponent;+ label: string;+ value: React.ReactNode;+};++const StyledContainer = styled.div`+ align-items: center;+ gap: ${({ theme }) => theme.spacing(1)};+ color: ${({ theme }) => theme.font.color.primary};+ display: flex;+`;++const StyledIconLabelContainer = styled.div`+ align-items: center;+ gap: ${({ theme }) => theme.spacing(1)};+ color: ${({ theme }) => theme.font.color.tertiary};+ display: flex;+ width: 120px;+`;++const StyledLabelContainer = styled.div`+ text-overflow: ellipsis;+ overflow: hidden;+ white-space: nowrap;+`;++export const SubscriptionInfoRowContainer = ({+ Icon,+ label,+ value,+}: SubscriptionInfoRowContainerProps) => {+ const theme = useTheme();+ return (+ <StyledContainer>+ <StyledIconLabelContainer>+ <Icon size={theme.icon.size.md} />+ <StyledLabelContainer>{label}</StyledLabelContainer>+ </StyledIconLabelContainer>+ {value}+ </StyledContainer>+ );+};diff --git a/packages/twenty-front/src/modules/billing/graphql/checkoutSession.ts b/packages/twenty-front/src/modules/billing/graphql/mutations/checkoutSession.tssimilarity index 100%rename from packages/twenty-front/src/modules/billing/graphql/checkoutSession.tsrename to packages/twenty-front/src/modules/billing/graphql/mutations/checkoutSession.tsdiff --git a/packages/twenty-front/src/modules/billing/graphql/endSubscriptionTrialPeriod.ts b/packages/twenty-front/src/modules/billing/graphql/mutations/endSubscriptionTrialPeriod.tssimilarity index 100%rename from packages/twenty-front/src/modules/billing/graphql/endSubscriptionTrialPeriod.tsrename to packages/twenty-front/src/modules/billing/graphql/mutations/endSubscriptionTrialPeriod.tsdiff --git a/packages/twenty-front/src/modules/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.ts b/packages/twenty-front/src/modules/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.tsnew file mode 100644index 00000000000..56ea2c6c241--- /dev/null+++ b/packages/twenty-front/src/modules/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.ts@@ -0,0 +1,9 @@+import { gql } from '@apollo/client';++export const SWITCH_SUBSCRIPTION_TO_ENTERPRISE_PLAN = gql`+ mutation SwitchSubscriptionToEnterprisePlan {+ switchToEnterprisePlan {+ success+ }+ }+`;diff --git a/packages/twenty-front/src/modules/billing/graphql/switchSubscriptionToYearlyInterval.ts b/packages/twenty-front/src/modules/billing/graphql/mutations/switchSubscriptionToYearlyInterval.tssimilarity index 100%rename from packages/twenty-front/src/modules/billing/graphql/switchSubscriptionToYearlyInterval.tsrename to packages/twenty-front/src/modules/billing/graphql/mutations/switchSubscriptionToYearlyInterval.tsdiff --git a/packages/twenty-front/src/modules/billing/graphql/billingBaseProductPrices.ts b/packages/twenty-front/src/modules/billing/graphql/queries/billingBaseProductPrices.tssimilarity index 100%rename from packages/twenty-front/src/modules/billing/graphql/billingBaseProductPrices.tsrename to packages/twenty-front/src/modules/billing/graphql/queries/billingBaseProductPrices.tsdiff --git a/packages/twenty-front/src/modules/billing/graphql/billingPortalSession.ts b/packages/twenty-front/src/modules/billing/graphql/queries/billingPortalSession.tssimilarity index 100%rename from packages/twenty-front/src/modules/billing/graphql/billingPortalSession.tsrename to packages/twenty-front/src/modules/billing/graphql/queries/billingPortalSession.tsdiff --git a/packages/twenty-front/src/modules/billing/graphql/getMeteredProductsUsage.ts b/packages/twenty-front/src/modules/billing/graphql/queries/getMeteredProductsUsage.tssimilarity index 100%rename from packages/twenty-front/src/modules/billing/graphql/getMeteredProductsUsage.tsrename to packages/twenty-front/src/modules/billing/graphql/queries/getMeteredProductsUsage.tsdiff --git a/packages/twenty-front/src/modules/billing/utils/formatMonthlyPrices.ts b/packages/twenty-front/src/modules/billing/utils/formatMonthlyPrices.tsnew file mode 100644index 00000000000..2262c4996c2--- /dev/null+++ b/packages/twenty-front/src/modules/billing/utils/formatMonthlyPrices.ts@@ -0,0 +1,46 @@+import {+ BillingPlanKey,+ SubscriptionInterval,+ BillingPlanOutput,+ BillingPriceLicensedDto,+} from '~/generated/graphql';+import { isDefined } from 'twenty-shared/utils';++export const formatMonthlyPrices = (plans: BillingPlanOutput[] | undefined) => {+ if (!isDefined(plans)) {+ return;+ }++ const enterprisePlan = plans.find(+ (plan) => plan.planKey === BillingPlanKey.ENTERPRISE,+ );++ const enterpriseYearPrice = enterprisePlan?.baseProduct.prices?.find(+ (price) => price.recurringInterval === SubscriptionInterval.Year,+ ) as BillingPriceLicensedDto;++ const enterpriseMonthPrice = enterprisePlan?.baseProduct.prices?.find(+ (price) => price.recurringInterval === SubscriptionInterval.Month,+ ) as BillingPriceLicensedDto;++ const proPlan = plans.find((plan) => plan.planKey === BillingPlanKey.PRO);++ const proYearPrice = proPlan?.baseProduct.prices?.find(+ (price) => price.recurringInterval === SubscriptionInterval.Year,+ ) as BillingPriceLicensedDto;++ const proMonthPrice = proPlan?.baseProduct.prices?.find(+ (price) => price.recurringInterval === SubscriptionInterval.Month,+ ) as BillingPriceLicensedDto;++ return {+ [BillingPlanKey.ENTERPRISE]: {+ [SubscriptionInterval.Year]: enterpriseYearPrice?.unitAmount / 100 / 12,+ [SubscriptionInterval.Month]: enterpriseMonthPrice?.unitAmount / 100,+ },+ [BillingPlanKey.PRO]: {+ [SubscriptionInterval.Year]: proYearPrice?.unitAmount / 100 / 12,+ [SubscriptionInterval.Month]: proMonthPrice?.unitAmount / 100,+ },+ };+};diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useColumnDefinitionsFromFieldMetadata.test.ts b/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useColumnDefinitionsFromFieldMetadata.test.tsindex 4a4133ab213..1d362b3f885 100644--- a/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useColumnDefinitionsFromFieldMetadata.test.ts+++ b/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useColumnDefinitionsFromFieldMetadata.test.ts@@ -38,11 +38,13 @@ const Wrapper = getJestMetadataAndApolloMocksAndActionMenuWrapper({id: '1',interval: SubscriptionInterval.Month,status: SubscriptionStatus.Active,+ metadata: {},},billingSubscriptions: [{id: '1',status: SubscriptionStatus.Active,+ metadata: {},},],});diff --git a/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.tsindex f515b5f59b1..9634e4e6738 100644--- a/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts+++ b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts@@ -37,7 +37,7 @@ const renderHooks = (result.current.setCurrentWorkspace({...mockCurrentWorkspace,currentBillingSubscription: withCurrentBillingSubscription- ? { id: v4(), status: SubscriptionStatus.Active }+ ? { id: v4(), status: SubscriptionStatus.Active, metadata: {} }: undefined,workspaceMembersCount: withOneWorkspaceMember ? 1 : 2,});diff --git a/packages/twenty-front/src/modules/users/graphql/fragments/userQueryFragment.ts b/packages/twenty-front/src/modules/users/graphql/fragments/userQueryFragment.tsindex 16161188006..a299bff9973 100644--- a/packages/twenty-front/src/modules/users/graphql/fragments/userQueryFragment.ts+++ b/packages/twenty-front/src/modules/users/graphql/fragments/userQueryFragment.ts@@ -60,9 +60,11 @@ export const USER_QUERY_FRAGMENT = gql`idstatusinterval+ metadatabillingSubscriptionItems {idhasReachedCurrentPeriodCap+ quantitybillingProduct {namedescription@@ -77,6 +79,7 @@ export const USER_QUERY_FRAGMENT = gql`billingSubscriptions {idstatus+ metadata}workspaceMembersCountdefaultRole {diff --git a/packages/twenty-front/src/modules/workspace/hooks/__tests__/useSubscriptionStatus.test.ts b/packages/twenty-front/src/modules/workspace/hooks/__tests__/useSubscriptionStatus.test.tsindex 821f2fa7b4f..edc5af1165f 100644--- a/packages/twenty-front/src/modules/workspace/hooks/__tests__/useSubscriptionStatus.test.ts+++ b/packages/twenty-front/src/modules/workspace/hooks/__tests__/useSubscriptionStatus.test.ts@@ -50,6 +50,7 @@ describe('useSubscriptionStatus', () => {currentBillingSubscription: {id: v4(),status: subscriptionStatus,+ metadata: {},},});});diff --git a/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx b/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsxindex b03abb1816c..3ce5df19c06 100644--- a/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx+++ b/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx@@ -3,7 +3,7 @@ import { Meta, StoryObj } from '@storybook/react';import { within } from '@storybook/testing-library';import { HttpResponse, graphql } from 'msw';-import { BILLING_BASE_PRODUCT_PRICES } from '@/billing/graphql/billingBaseProductPrices';+import { BILLING_BASE_PRODUCT_PRICES } from '@/billing/graphql/queries/billingBaseProductPrices';import { AppPath } from '@/types/AppPath';import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';import {diff --git a/packages/twenty-front/src/pages/settings/SettingsBilling.tsx b/packages/twenty-front/src/pages/settings/SettingsBilling.tsxindex 5bbffc9eca5..6cd1678bbd6 100644--- a/packages/twenty-front/src/pages/settings/SettingsBilling.tsx+++ b/packages/twenty-front/src/pages/settings/SettingsBilling.tsx@@ -1,56 +1,41 @@import { Trans, useLingui } from '@lingui/react/macro';-import { useRecoilValue, useSetRecoilState } from 'recoil';+import { useRecoilValue } from 'recoil';import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import { SettingsBillingMonthlyCreditsSection } from '@/billing/components/SettingsBillingMonthlyCreditsSection';import { useRedirect } from '@/domain-manager/hooks/useRedirect';import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';import { SettingsPath } from '@/types/SettingsPath';-import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';-import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';-import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal';-import { useModal } from '@/ui/layout/modal/hooks/useModal';import { SubMenuTopBarContainer } from '@/ui/layout/page/components/SubMenuTopBarContainer';import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';import { isDefined } from 'twenty-shared/utils';-import {- H2Title,- IconCalendarEvent,- IconCircleX,- IconCreditCard,-} from 'twenty-ui/display';+import { H2Title, IconCircleX, IconCreditCard } from 'twenty-ui/display';import { Button } from 'twenty-ui/input';import { Section } from 'twenty-ui/layout';import {- SubscriptionInterval,SubscriptionStatus,useBillingPortalSessionQuery,- useSwitchSubscriptionToYearlyIntervalMutation,} from '~/generated/graphql';import { getSettingsPath } from '~/utils/navigation/getSettingsPath';--const SWITCH_BILLING_INTERVAL_MODAL_ID = 'switch-billing-interval-modal';+import { SettingsBillingSubscriptionInfo } from '@/billing/components/SettingsBillingSubscriptionInfo';export const SettingsBilling = () => {const { t } = useLingui();const { redirect } = useRedirect();- const { enqueueSnackBar } = useSnackBar();-const currentWorkspace = useRecoilValue(currentWorkspaceState);+const subscriptions = currentWorkspace?.billingSubscriptions;+const hasSubscriptions = (subscriptions?.length ?? 0) > 0;const subscriptionStatus = useSubscriptionStatus();+const hasNotCanceledCurrentSubscription =isDefined(subscriptionStatus) &&subscriptionStatus !== SubscriptionStatus.Canceled;- const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);-- const [switchToYearlyInterval] =- useSwitchSubscriptionToYearlyIntervalMutation();const { data, loading } = useBillingPortalSessionQuery({variables: {returnUrlPath: '/settings/billing',@@ -67,31 +52,6 @@ export const SettingsBilling = () => {}};- const { openModal } = useModal();-- const switchInterval = async () => {- try {- await switchToYearlyInterval();- if (isDefined(currentWorkspace?.currentBillingSubscription)) {- const newCurrentWorkspace = {- ...currentWorkspace,- currentBillingSubscription: {- ...currentWorkspace?.currentBillingSubscription,- interval: SubscriptionInterval.Year,- },- };- setCurrentWorkspace(newCurrentWorkspace);- }- enqueueSnackBar(t`Subscription has been switched to yearly.`, {- variant: SnackBarVariant.Success,- });- } catch (error: any) {- enqueueSnackBar(t`Error while switching subscription to yearly.`, {- variant: SnackBarVariant.Error,- });- }- };-return (<SubMenuTopBarContainertitle={t`Billing`}@@ -104,12 +64,15 @@ export const SettingsBilling = () => {]}><SettingsPageContainer>+ {hasNotCanceledCurrentSubscription && (+ <SettingsBillingSubscriptionInfo />+ )}{hasNotCanceledCurrentSubscription && (<SettingsBillingMonthlyCreditsSection />)}<Section><H2Title- title={t`Manage your subscription`}+ title={t`Manage billing information`}description={t`Edit payment method, see your invoices and more`}/><Button@@ -120,45 +83,23 @@ export const SettingsBilling = () => {disabled={billingPortalButtonDisabled}/></Section>- {currentWorkspace?.currentBillingSubscription?.interval ===- SubscriptionInterval.Month && (+ {hasNotCanceledCurrentSubscription && (<Section><H2Title- title={t`Edit billing interval`}- description={t`Switch from monthly to yearly`}+ title={t`Cancel your subscription`}+ description={t`Your workspace will be disabled`}/><Button- Icon={IconCalendarEvent}- title={t`Switch to yearly`}+ Icon={IconCircleX}+ title={t`Cancel Plan`}variant="secondary"- onClick={() => openModal(SWITCH_BILLING_INTERVAL_MODAL_ID)}- disabled={!hasNotCanceledCurrentSubscription}+ accent="danger"+ onClick={openBillingPortal}+ disabled={billingPortalButtonDisabled}/></Section>)}- <Section>- <H2Title- title={t`Cancel your subscription`}- description={t`Your workspace will be disabled`}- />- <Button- Icon={IconCircleX}- title={t`Cancel Plan`}- variant="secondary"- accent="danger"- onClick={openBillingPortal}- disabled={!hasNotCanceledCurrentSubscription}- />- </Section></SettingsPageContainer>- <ConfirmationModal- modalId={SWITCH_BILLING_INTERVAL_MODAL_ID}- title={t`Switch billing to yearly`}- subtitle={t`Are you sure that you want to change your billing interval? You will be charged immediately for the full year.`}- onConfirmClick={switchInterval}- confirmButtonText={t`Change to yearly`}- confirmButtonAccent={'blue'}- /></SubMenuTopBarContainer>);};diff --git a/packages/twenty-front/src/testing/mock-data/users.ts b/packages/twenty-front/src/testing/mock-data/users.tsindex 65f2163b897..85a6189656b 100644--- a/packages/twenty-front/src/testing/mock-data/users.ts+++ b/packages/twenty-front/src/testing/mock-data/users.ts@@ -79,12 +79,14 @@ export const mockCurrentWorkspace: Workspace = {id: '7efbc3f7-6e5e-4128-957e-8d86808cdf6a',interval: SubscriptionInterval.Month,status: SubscriptionStatus.Active,+ metadata: {},},billingSubscriptions: [{__typename: 'BillingSubscription',id: '7efbc3f7-6e5e-4128-957e-8d86808cdf6a',status: SubscriptionStatus.Active,+ metadata: {},},],workspaceMembersCount: 1,diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.exception.tsindex da7328f7126..e2d66913394 100644--- a/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts@@ -25,4 +25,5 @@ export enum BillingExceptionCode {BILLING_STRIPE_ERROR = 'BILLING_STRIPE_ERROR',BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD = 'BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD',BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE = 'BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE',+ BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE = 'BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE',}diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.tsindex 12fd6519040..4f352b75ccd 100644--- a/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts@@ -124,6 +124,17 @@ export class BillingResolver {return { success: true };}+ @Mutation(() => BillingUpdateOutput)+ @UseGuards(+ WorkspaceAuthGuard,+ SettingsPermissionsGuard(SettingPermissionType.WORKSPACE),+ )+ async switchToEnterprisePlan(@AuthWorkspace() workspace: Workspace) {+ await this.billingSubscriptionService.switchToEnterprisePlan(workspace);++ return { success: true };+ }+@Query(() => [BillingPlanOutput])@UseGuards(WorkspaceAuthGuard)async plans(): Promise<BillingPlanOutput[]> {diff --git a/packages/twenty-server/src/engine/core-modules/billing/dtos/outputs/billing-subscription-item.output.ts b/packages/twenty-server/src/engine/core-modules/billing/dtos/outputs/billing-subscription-item.output.tsindex 4bc90bf8f49..1231543cc4b 100644--- a/packages/twenty-server/src/engine/core-modules/billing/dtos/outputs/billing-subscription-item.output.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/dtos/outputs/billing-subscription-item.output.ts@@ -15,6 +15,9 @@ export class BillingSubscriptionItemDTO {@Field(() => Boolean)hasReachedCurrentPeriodCap: boolean;+ @Field(() => Number, { nullable: true })+ quantity: number | null;+@Field(() => BillingProductDTO, { nullable: true })billingProduct: BillingProductDTO;}diff --git a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-subscription.entity.ts b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-subscription.entity.tsindex d5e0ce41868..fc74bcf697d 100644--- a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-subscription.entity.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-subscription.entity.ts@@ -16,6 +16,7 @@ import {Relation,UpdateDateColumn,} from 'typeorm';+import graphqlTypeJson from 'graphql-type-json';import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';import { BillingSubscriptionItemDTO } from 'src/engine/core-modules/billing/dtos/outputs/billing-subscription-item.output';@@ -115,6 +116,7 @@ export class BillingSubscription {})currentPeriodStart: Date;+ @Field(() => graphqlTypeJson)@Column({ nullable: false, type: 'jsonb', default: {} })metadata: Stripe.Metadata;diff --git a/packages/twenty-server/src/engine/core-modules/billing/filters/billing-api-exception.filter.ts b/packages/twenty-server/src/engine/core-modules/billing/filters/billing-api-exception.filter.tsindex 8b8055c08ab..9d912d9974e 100644--- a/packages/twenty-server/src/engine/core-modules/billing/filters/billing-api-exception.filter.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/filters/billing-api-exception.filter.ts@@ -55,6 +55,8 @@ export class BillingRestApiExceptionFilter implements ExceptionFilter {case BillingExceptionCode.BILLING_METER_EVENT_FAILED:case BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD:case BillingExceptionCode.BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE:+ case BillingExceptionCode.BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE:+ case BillingExceptionCode.BILLING_MISSING_REQUEST_BODY:return this.httpExceptionHandlerService.handleError(exception,response,diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.tsindex 71f80b446aa..795de7ad163 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.ts@@ -66,7 +66,7 @@ export class BillingPlanService {where: {active: true,},- relations: ['billingPrices'],+ relations: ['billingPrices.billingProduct'],});return planKeys.map((planKey) => {diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-product.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-product.service.tsindex c3f49935e2e..ce2320e41fd 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-product.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-product.service.ts@@ -11,25 +11,39 @@ import { BillingProduct } from 'src/engine/core-modules/billing/entities/billingimport { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { SubscriptionInterval } from 'src/engine/core-modules/billing/enums/billing-subscription-interval.enum';import { BillingPlanService } from 'src/engine/core-modules/billing/services/billing-plan.service';+@Injectable()export class BillingProductService {protected readonly logger = new Logger(BillingProductService.name);constructor(private readonly billingPlanService: BillingPlanService) {}- getProductPricesByInterval({+ async getProductPrices({+ interval,+ planKey,+ }: {+ interval: SubscriptionInterval;+ planKey: BillingPlanKey;+ }): Promise<BillingPrice[]> {+ const billingProducts = await this.getProductsByPlan(planKey);++ return this.getProductPricesByInterval({+ interval,+ billingProductsByPlan: billingProducts,+ });+ }++ private getProductPricesByInterval({interval,billingProductsByPlan,}: {interval: SubscriptionInterval;billingProductsByPlan: BillingProduct[];}): BillingPrice[] {- const billingPrices = billingProductsByPlan.flatMap((product) =>+ return billingProductsByPlan.flatMap((product) =>product.billingPrices.filter((price) => price.interval === interval && price.active,),);-- return billingPrices;}async getProductsByPlan(planKey: BillingPlanKey): Promise<BillingProduct[]> {diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.tsindex c5ba4378e2f..8b39fc4f91d 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts@@ -31,6 +31,8 @@ import { getPlanKeyFromSubscription } from 'src/engine/core-modules/billing/utilimport { getSubscriptionStatus } from 'src/engine/core-modules/billing/webhooks/utils/transform-stripe-subscription-event-to-database-subscription.util';import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';+import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+@Injectable()export class BillingSubscriptionService {protected readonly logger = new Logger(BillingSubscriptionService.name);@@ -166,15 +168,47 @@ export class BillingSubscriptionService {);}- const newInterval = SubscriptionInterval.Year;+ const interval = SubscriptionInterval.Year;const planKey = getPlanKeyFromSubscription(billingSubscription);- const billingProductsByPlan =- await this.billingProductService.getProductsByPlan(planKey);++ const pricesPerPlanArray =+ await this.billingProductService.getProductPrices({+ interval,+ planKey,+ });++ const subscriptionItemsToUpdate = this.getSubscriptionItemsToUpdate(+ billingSubscription,+ pricesPerPlanArray,+ );++ await this.stripeSubscriptionService.updateSubscriptionItems(+ billingSubscription.stripeSubscriptionId,+ subscriptionItemsToUpdate,+ );+ }++ async switchToEnterprisePlan(workspace: Workspace) {+ const billingSubscription = await this.getCurrentBillingSubscriptionOrThrow(+ { workspaceId: workspace.id },+ );++ if (billingSubscription.metadata?.plan === BillingPlanKey.ENTERPRISE) {+ throw new BillingException(+ 'Cannot switch from Organization to Pro plan',+ BillingExceptionCode.BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE,+ );+ }++ const planKey = BillingPlanKey.ENTERPRISE;++ const interval = billingSubscription.interval as SubscriptionInterval;+const pricesPerPlanArray =- this.billingProductService.getProductPricesByInterval({- interval: newInterval,- billingProductsByPlan,+ await this.billingProductService.getProductPrices({+ interval,+ planKey,});const subscriptionItemsToUpdate = this.getSubscriptionItemsToUpdate(@@ -186,16 +220,23 @@ export class BillingSubscriptionService {billingSubscription.stripeSubscriptionId,subscriptionItemsToUpdate,);++ await this.stripeSubscriptionService.updateSubscription(+ billingSubscription.stripeSubscriptionId,+ { metadata: { ...billingSubscription?.metadata, plan: planKey } },+ );}private getSubscriptionItemsToUpdate(billingSubscription: BillingSubscription,billingPricesPerPlanAndIntervalArray: BillingPrice[],): BillingSubscriptionItem[] {- const subscriptionItemsToUpdate =- billingSubscription.billingSubscriptionItems.map((subscriptionItem) => {+ return billingSubscription.billingSubscriptionItems.map(+ (subscriptionItem) => {const matchingPrice = billingPricesPerPlanAndIntervalArray.find(- (price) => price.stripeProductId === subscriptionItem.stripeProductId,+ (price) =>+ price.billingProduct.metadata.priceUsageBased ===+ subscriptionItem.billingProduct.metadata.priceUsageBased,);if (!matchingPrice) {@@ -208,10 +249,10 @@ export class BillingSubscriptionService {return {...subscriptionItem,stripePriceId: matchingPrice.stripePriceId,+ stripeProductId: matchingPrice.stripeProductId,};- });-- return subscriptionItemsToUpdate;+ },+ );}async endTrialPeriod(workspace: Workspace) {