Skip to content

The open alternative to Salesforce, designed for AI.

feat(usage-limit): create and edit limits from settings > billing (#25742)

Etienne25af73f293ef
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index 9420a57f7db..912eaf66b7f 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -9111,6 +9111,20 @@ export type CreateSubscriptionPaymentIntentMutationVariables = Exact<{
export type CreateSubscriptionPaymentIntentMutation = { __typename?: 'Mutation', createSubscriptionPaymentIntent: { __typename?: 'BillingPaymentIntent', clientSecret: string, paymentIntentType: string } };
+export type CreateUsageLimitMutationVariables = Exact<{
+ input: CreateUsageLimitInput;
+}>;
+
+
+export type CreateUsageLimitMutation = { __typename?: 'Mutation', createUsageLimit: { __typename?: 'UsageLimit', id: string } };
+
+export type DeleteUsageLimitMutationVariables = Exact<{
+ usageLimitId: Scalars['UUID']['input'];
+}>;
+
+
+export type DeleteUsageLimitMutation = { __typename?: 'Mutation', deleteUsageLimit: boolean };
+
export type EndSubscriptionTrialPeriodMutationVariables = Exact<{ [key: string]: never; }>;
@@ -9145,6 +9159,13 @@ export type SwitchSubscriptionIntervalMutation = { __typename?: 'Mutation', swit
| { __typename?: 'BillingMeteredProduct', name: string, description: string, images?: Array<string> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }
}> | null }, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: string, status: SubscriptionStatus, metadata: any, cancelAt?: string | null, phases: Array<{ __typename?: 'BillingSubscriptionSchedulePhase', start_date: number, end_date: number, items: Array<{ __typename?: 'BillingSubscriptionSchedulePhaseItem', price: string, quantity?: number | null }> }> }> } };
+export type UpdateUsageLimitMutationVariables = Exact<{
+ input: UpdateUsageLimitInput;
+}>;
+
+
+export type UpdateUsageLimitMutation = { __typename?: 'Mutation', updateUsageLimit: { __typename?: 'UsageLimit', id: string } };
+
export type BillingPortalSessionQueryVariables = Exact<{
returnUrlPath?: InputMaybe<Scalars['String']['input']>;
forPaymentMethodUpdate?: InputMaybe<Scalars['Boolean']['input']>;
@@ -9163,6 +9184,18 @@ export type ListPlansQueryVariables = Exact<{ [key: string]: never; }>;
export type ListPlansQuery = { __typename?: 'Query', listPlans: Array<{ __typename?: 'BillingPlan', planKey: BillingPlanKey, baseProducts: Array<{ __typename?: 'BillingLicensedProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceLicensed', stripePriceId: string, unitAmount: number, recurringInterval: SubscriptionInterval, priceUsageType: BillingUsageType, creditAmount?: number | null, isSellable: boolean }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }>, resourceCreditProducts: Array<{ __typename?: 'BillingLicensedProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceLicensed', stripePriceId: string, unitAmount: number, recurringInterval: SubscriptionInterval, priceUsageType: BillingUsageType, creditAmount?: number | null, isSellable: boolean }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }>, meteredProducts: Array<{ __typename?: 'BillingMeteredProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceMetered', priceUsageType: BillingUsageType, recurringInterval: SubscriptionInterval, stripePriceId: string, tiers: Array<{ __typename?: 'BillingPriceTier', flatAmount?: number | null, unitAmount?: number | null, upTo?: number | null }> }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }> }> };
+export type UsageQuotaDefinitionsQueryVariables = Exact<{ [key: string]: never; }>;
+
+
+export type UsageQuotaDefinitionsQuery = { __typename?: 'Query', usageQuotaDefinitions: { __typename?: 'UsageQuotaDefinitions', isIntraWorkspaceLimitEntitled: boolean, hasAllowancePeriod: boolean, definitions: Array<{ __typename?: 'UsageQuotaDefinition', resourceType: UsageResourceType, allowedOperationTypes: Array<UsageOperationType>, allowedSpenderTypes: Array<string>, allowedMeters: Array<string> }> } };
+
+export type UsageQuotaScopeConsumptionQueryVariables = Exact<{
+ input: UsageQuotaScopeInput;
+}>;
+
+
+export type UsageQuotaScopeConsumptionQuery = { __typename?: 'Query', usageQuotaScopeConsumption?: { __typename?: 'UsageQuotaScopeConsumption', consumedValue?: any | null, periodStart: string, periodEnd: string } | null };
+
export type UsageQuotasWithConsumptionQueryVariables = Exact<{ [key: string]: never; }>;
@@ -10139,13 +10172,18 @@ export const CancelSwitchResourceCreditPriceDocument = {"kind":"Document","defin
export const CheckoutSessionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CheckoutSession"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"recurringInterval"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SubscriptionInterval"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"successUrlPath"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"plan"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPlanKey"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"requirePaymentMethod"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"checkoutSession"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"recurringInterval"},"value":{"kind":"Variable","name":{"kind":"Name","value":"recurringInterval"}}},{"kind":"Argument","name":{"kind":"Name","value":"successUrlPath"},"value":{"kind":"Variable","name":{"kind":"Name","value":"successUrlPath"}}},{"kind":"Argument","name":{"kind":"Name","value":"plan"},"value":{"kind":"Variable","name":{"kind":"Name","value":"plan"}}},{"kind":"Argument","name":{"kind":"Name","value":"requirePaymentMethod"},"value":{"kind":"Variable","name":{"kind":"Name","value":"requirePaymentMethod"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<CheckoutSessionMutation, CheckoutSessionMutationVariables>;
export const CreateBillingPaymentMethodSetupIntentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateBillingPaymentMethodSetupIntent"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createBillingPaymentMethodSetupIntent"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"clientSecret"}}]}}]}}]} as unknown as DocumentNode<CreateBillingPaymentMethodSetupIntentMutation, CreateBillingPaymentMethodSetupIntentMutationVariables>;
export const CreateSubscriptionPaymentIntentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateSubscriptionPaymentIntent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"recurringInterval"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SubscriptionInterval"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"plan"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPlanKey"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"idempotencyKey"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createSubscriptionPaymentIntent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"recurringInterval"},"value":{"kind":"Variable","name":{"kind":"Name","value":"recurringInterval"}}},{"kind":"Argument","name":{"kind":"Name","value":"plan"},"value":{"kind":"Variable","name":{"kind":"Name","value":"plan"}}},{"kind":"Argument","name":{"kind":"Name","value":"idempotencyKey"},"value":{"kind":"Variable","name":{"kind":"Name","value":"idempotencyKey"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"clientSecret"}},{"kind":"Field","name":{"kind":"Name","value":"paymentIntentType"}}]}}]}}]} as unknown as DocumentNode<CreateSubscriptionPaymentIntentMutation, CreateSubscriptionPaymentIntentMutationVariables>;
+export const CreateUsageLimitDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateUsageLimit"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateUsageLimitInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createUsageLimit"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<CreateUsageLimitMutation, CreateUsageLimitMutationVariables>;
+export const DeleteUsageLimitDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteUsageLimit"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"usageLimitId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteUsageLimit"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"usageLimitId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"usageLimitId"}}}]}]}}]} as unknown as DocumentNode<DeleteUsageLimitMutation, DeleteUsageLimitMutationVariables>;
export const EndSubscriptionTrialPeriodDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"EndSubscriptionTrialPeriod"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"endSubscriptionTrialPeriod"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"hasPaymentMethod"}},{"kind":"Field","name":{"kind":"Name","value":"billingPortalUrl"}},{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<EndSubscriptionTrialPeriodMutation, EndSubscriptionTrialPeriodMutationVariables>;
export const SetResourceCreditSubscriptionPriceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SetResourceCreditSubscriptionPrice"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"priceId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"setResourceCreditSubscriptionPrice"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"priceId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"priceId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SetResourceCreditSubscriptionPriceMutation, SetResourceCreditSubscriptionPriceMutationVariables>;
export const SwitchBillingPlanDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SwitchBillingPlan"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"switchBillingPlan"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SwitchBillingPlanMutation, SwitchBillingPlanMutationVariables>;
export const SwitchSubscriptionIntervalDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SwitchSubscriptionInterval"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"switchSubscriptionInterval"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SwitchSubscriptionIntervalMutation, SwitchSubscriptionIntervalMutationVariables>;
+export const UpdateUsageLimitDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateUsageLimit"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateUsageLimitInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateUsageLimit"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<UpdateUsageLimitMutation, UpdateUsageLimitMutationVariables>;
export const BillingPortalSessionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"BillingPortalSession"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"returnUrlPath"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"forPaymentMethodUpdate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"billingPortalSession"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"returnUrlPath"},"value":{"kind":"Variable","name":{"kind":"Name","value":"returnUrlPath"}}},{"kind":"Argument","name":{"kind":"Name","value":"forPaymentMethodUpdate"},"value":{"kind":"Variable","name":{"kind":"Name","value":"forPaymentMethodUpdate"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>;
export const GetResourceCreditUsageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetResourceCreditUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getResourceCreditUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"usedCredits"}},{"kind":"Field","name":{"kind":"Name","value":"grantedCredits"}},{"kind":"Field","name":{"kind":"Name","value":"rolloverCredits"}},{"kind":"Field","name":{"kind":"Name","value":"totalGrantedCredits"}},{"kind":"Field","name":{"kind":"Name","value":"unitPriceCents"}}]}}]}}]} as unknown as DocumentNode<GetResourceCreditUsageQuery, GetResourceCreditUsageQueryVariables>;
export const ListPlansDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"listPlans"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"listPlans"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"baseProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingLicensedProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceLicensedFragment"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"resourceCreditProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingLicensedProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceLicensedFragment"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"meteredProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingMeteredProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceMeteredFragment"}}]}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingPriceLicensedFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPriceLicensed"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"recurringInterval"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageType"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"isSellable"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingPriceMeteredFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPriceMetered"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"priceUsageType"}},{"kind":"Field","name":{"kind":"Name","value":"recurringInterval"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"tiers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"flatAmount"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"upTo"}}]}}]}}]} as unknown as DocumentNode<ListPlansQuery, ListPlansQueryVariables>;
+export const UsageQuotaDefinitionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UsageQuotaDefinitions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"usageQuotaDefinitions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"definitions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"resourceType"}},{"kind":"Field","name":{"kind":"Name","value":"allowedOperationTypes"}},{"kind":"Field","name":{"kind":"Name","value":"allowedSpenderTypes"}},{"kind":"Field","name":{"kind":"Name","value":"allowedMeters"}}]}},{"kind":"Field","name":{"kind":"Name","value":"isIntraWorkspaceLimitEntitled"}},{"kind":"Field","name":{"kind":"Name","value":"hasAllowancePeriod"}}]}}]}}]} as unknown as DocumentNode<UsageQuotaDefinitionsQuery, UsageQuotaDefinitionsQueryVariables>;
+export const UsageQuotaScopeConsumptionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UsageQuotaScopeConsumption"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UsageQuotaScopeInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"usageQuotaScopeConsumption"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodStart"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}}]}}]}}]} as unknown as DocumentNode<UsageQuotaScopeConsumptionQuery, UsageQuotaScopeConsumptionQueryVariables>;
export const UsageQuotasWithConsumptionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UsageQuotasWithConsumption"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"usageQuotasWithConsumption"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"resourceType"}},{"kind":"Field","name":{"kind":"Name","value":"operationType"}},{"kind":"Field","name":{"kind":"Name","value":"spenderType"}},{"kind":"Field","name":{"kind":"Name","value":"spenderId"}},{"kind":"Field","name":{"kind":"Name","value":"spenderLabel"}},{"kind":"Field","name":{"kind":"Name","value":"periodUnit"}},{"kind":"Field","name":{"kind":"Name","value":"meter"}},{"kind":"Field","name":{"kind":"Name","value":"limitValue"}},{"kind":"Field","name":{"kind":"Name","value":"isEnforced"}},{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"remainingValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodStart"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}}]}}]}}]} as unknown as DocumentNode<UsageQuotasWithConsumptionQuery, UsageQuotasWithConsumptionQueryVariables>;
export const AssignRoleToApiKeyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"AssignRoleToApiKey"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"apiKeyId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"roleId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"assignRoleToApiKey"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"apiKeyId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"apiKeyId"}}},{"kind":"Argument","name":{"kind":"Name","value":"roleId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"roleId"}}}]}]}}]} as unknown as DocumentNode<AssignRoleToApiKeyMutation, AssignRoleToApiKeyMutationVariables>;
export const CreateApiKeyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateApiKey"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateApiKeyInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createApiKey"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ApiKeyFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ApiKeyFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ApiKey"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}},{"kind":"Field","name":{"kind":"Name","value":"revokedAt"}},{"kind":"Field","name":{"kind":"Name","value":"role"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}}]}}]}}]} as unknown as DocumentNode<CreateApiKeyMutation, CreateApiKeyMutationVariables>;
diff --git a/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx b/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx
index ff4d0c21f64..413ecb6146c 100644
--- a/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx
+++ b/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx
@@ -464,6 +464,20 @@ const SettingsBillingLimits = lazy(() =>
})),
);
+const SettingsBillingNewLimit = lazy(() =>
+ import('~/pages/settings/billing/SettingsBillingNewLimit').then((module) => ({
+ default: module.SettingsBillingNewLimit,
+ })),
+);
+
+const SettingsBillingLimitEdit = lazy(() =>
+ import('~/pages/settings/billing/SettingsBillingLimitEdit').then(
+ (module) => ({
+ default: module.SettingsBillingLimitEdit,
+ }),
+ ),
+);
+
const SettingsUsageUserDetail = lazy(() =>
import('~/pages/settings/billing/SettingsUsageUserDetail').then((module) => ({
default: module.SettingsUsageUserDetail,
@@ -797,6 +811,14 @@ const createSettingsRouteElements = ({
path={SettingsPath.BillingLimits}
element={<SettingsBillingLimits />}
/>
+ <Route
+ path={SettingsPath.BillingNewLimit}
+ element={<SettingsBillingNewLimit />}
+ />
+ <Route
+ path={SettingsPath.BillingLimitEdit}
+ element={<SettingsBillingLimitEdit />}
+ />
<Route
path={SettingsPath.Subdomain}
element={<SettingsSubdomainPage />}
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitEditForm.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitEditForm.tsx
new file mode 100644
index 00000000000..63ce92ced73
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitEditForm.tsx
@@ -0,0 +1,155 @@
+import { CombinedGraphQLErrors } from '@apollo/client/errors';
+import { Trans, useLingui } from '@lingui/react/macro';
+import { useState } from 'react';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath, isDefined } from 'twenty-shared/utils';
+import { IconTrash } from 'twenty-ui/icon';
+import { Button } from 'twenty-ui/input';
+import { Section } from 'twenty-ui/layout';
+import { H2Title } from 'twenty-ui/typography';
+
+import { SettingsBillingLimitForm } from '@/settings/billing/components/SettingsBillingLimitForm';
+import { useDeleteUsageLimit } from '@/settings/billing/hooks/useDeleteUsageLimit';
+import { useUpdateUsageLimit } from '@/settings/billing/hooks/useUpdateUsageLimit';
+import { useUsageQuotaDefinitions } from '@/settings/billing/hooks/useUsageQuotaDefinitions';
+import { useUsageQuotaScopeConsumption } from '@/settings/billing/hooks/useUsageQuotaScopeConsumption';
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { type UsageQuotaWithConsumption } from '@/settings/billing/types/UsageQuotaWithConsumption';
+import { buildCreateUsageLimitInput } from '@/settings/billing/utils/buildCreateUsageLimitInput';
+import { buildUsageLimitFormValues } from '@/settings/billing/utils/buildUsageLimitFormValues';
+import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
+import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
+import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
+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 { useNavigateSettings } from '~/hooks/useNavigateSettings';
+
+const DELETE_MODAL_ID = 'usage-limit-edit-delete';
+
+type SettingsBillingLimitEditFormProps = {
+ usageLimitId: string;
+ quota: UsageQuotaWithConsumption;
+};
+
+export const SettingsBillingLimitEditForm = ({
+ usageLimitId,
+ quota,
+}: SettingsBillingLimitEditFormProps) => {
+ const { t } = useLingui();
+ const navigate = useNavigateSettings();
+ const { enqueueErrorSnackBar, enqueueSuccessSnackBar } = useSnackBar();
+ const { usageQuotaDefinitions, loading: definitionsLoading } =
+ useUsageQuotaDefinitions();
+ const { updateUsageLimit, loading: isSaving } = useUpdateUsageLimit();
+ const { deleteUsageLimit, loading: isDeleting } = useDeleteUsageLimit();
+ const { openModal, closeModal } = useModal();
+
+ const [values, setValues] = useState<UsageLimitFormValues>(
+ buildUsageLimitFormValues(quota),
+ );
+
+ const input = buildCreateUsageLimitInput(values);
+ const { scopeConsumption } = useUsageQuotaScopeConsumption(values);
+
+ const handleDelete = async () => {
+ try {
+ await deleteUsageLimit({ variables: { usageLimitId } });
+ enqueueSuccessSnackBar({ message: t`Limit deleted.` });
+ navigate(SettingsPath.BillingLimits);
+ } catch {
+ enqueueErrorSnackBar({ message: t`Failed to delete the limit.` });
+ } finally {
+ closeModal(DELETE_MODAL_ID);
+ }
+ };
+
+ const handleSave = async () => {
+ if (!isDefined(input)) {
+ return;
+ }
+
+ try {
+ await updateUsageLimit({
+ variables: { input: { id: usageLimitId, payload: input } },
+ });
+
+ enqueueSuccessSnackBar({ message: t`Limit updated.` });
+ navigate(SettingsPath.BillingLimits);
+ } catch (error) {
+ const serverMessage =
+ error instanceof CombinedGraphQLErrors
+ ? error.errors[0]?.message
+ : undefined;
+
+ enqueueErrorSnackBar({
+ message: serverMessage ?? t`Failed to update the limit.`,
+ });
+ }
+ };
+
+ return (
+ <SettingsPageLayout
+ title={t`Edit limit`}
+ links={[
+ {
+ children: <Trans>Workspace</Trans>,
+ href: getSettingsPath(SettingsPath.General),
+ },
+ {
+ children: <Trans>Billing</Trans>,
+ href: getSettingsPath(SettingsPath.Billing),
+ },
+ {
+ children: <Trans>Limits</Trans>,
+ href: getSettingsPath(SettingsPath.BillingLimits),
+ },
+ { children: <Trans>Edit limit</Trans> },
+ ]}
+ actionButton={
+ <SaveAndCancelButtons
+ onSave={handleSave}
+ onCancel={() => navigate(SettingsPath.BillingLimits)}
+ isSaveDisabled={!isDefined(input)}
+ isLoading={isSaving}
+ />
+ }
+ >
+ <SettingsPageContainer>
+ {definitionsLoading || !isDefined(usageQuotaDefinitions) ? null : (
+ <>
+ <SettingsBillingLimitForm
+ definitions={usageQuotaDefinitions}
+ values={values}
+ scopeConsumption={scopeConsumption}
+ onChange={setValues}
+ />
+ <Section>
+ <H2Title
+ title={t`Danger zone`}
+ description={t`Spending stays capped by your plan allowance and the other limits.`}
+ />
+ <Button
+ Icon={IconTrash}
+ title={t`Delete limit`}
+ variant="secondary"
+ accent="danger"
+ size="small"
+ disabled={isDeleting}
+ onClick={() => openModal(DELETE_MODAL_ID)}
+ />
+ <ConfirmationModal
+ modalInstanceId={DELETE_MODAL_ID}
+ title={t`Delete this limit?`}
+ subtitle={t`Spending will only be capped by your plan allowance and the other limits.`}
+ confirmButtonText={t`Delete`}
+ loading={isDeleting}
+ onConfirmClick={handleDelete}
+ />
+ </Section>
+ </>
+ )}
+ </SettingsPageContainer>
+ </SettingsPageLayout>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitForm.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitForm.tsx
new file mode 100644
index 00000000000..420e2f5942d
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitForm.tsx
@@ -0,0 +1,269 @@
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { INTERNAL_CREDITS_PER_DISPLAY_CREDIT } from 'twenty-shared/constants';
+import { isDefined } from 'twenty-shared/utils';
+import { Section } from 'twenty-ui/layout';
+import { AppTooltip, TooltipDelay } from 'twenty-ui/surfaces';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
+import { H2Title } from 'twenty-ui/typography';
+
+import { SettingsBillingLimitUsageSelect } from '@/settings/billing/components/SettingsBillingLimitUsageSelect';
+import { SettingsBillingLimitAmount } from '@/settings/billing/components/internal/SettingsBillingLimitAmount';
+import { StyledSettingsBillingFieldLabel } from '@/settings/billing/components/internal/SettingsBillingFieldLabel';
+import { SettingsBillingLimitSpenderSelect } from '@/settings/billing/components/SettingsBillingLimitSpenderSelect';
+import { USAGE_LIMIT_METER_ICONS } from '@/settings/billing/constants/UsageLimitMeterIcons';
+import { USAGE_LIMIT_METER_LABELS } from '@/settings/billing/constants/UsageLimitMeterLabels';
+import { USAGE_LIMIT_PERIOD_ICONS } from '@/settings/billing/constants/UsageLimitPeriodIcons';
+import { USAGE_LIMIT_PERIOD_SPAN_LABELS } from '@/settings/billing/constants/UsageLimitPeriodSpanLabels';
+import { USAGE_LIMIT_PERIOD_UNIT_LABELS } from '@/settings/billing/constants/UsageLimitPeriodUnitLabels';
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { type UsageLimitMeter } from '@/settings/billing/types/UsageLimitMeter';
+import { type UsageLimitPeriodUnit } from '@/settings/billing/types/UsageLimitPeriodUnit';
+import { useUsageLimitFormatter } from '@/settings/billing/hooks/useUsageLimitFormatter';
+import { type UsageQuotaScopeConsumption } from '@/settings/billing/types/UsageQuotaScopeConsumption';
+import { computeUsageLimitProgress } from '@/settings/billing/utils/computeUsageLimitProgress';
+import { getUsageLimitFormOptions } from '@/settings/billing/utils/getUsageLimitFormOptions';
+import { getUsageLimitRingColor } from '@/settings/billing/utils/getUsageLimitRingColor';
+import { Select } from '@/ui/input/components/Select';
+import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
+import { ProgressRing } from '@/ui/feedback/progress-ring/components/ProgressRing';
+import {
+ type UsageQuotaDefinitionsQuery,
+ UsageOperationType,
+ type UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const RING_ANCHOR_ID = 'usage-limit-form-ring';
+
+const StyledRow = styled.div`
+ display: grid;
+ gap: ${themeCssVariables.spacing[4]};
+ grid-template-columns: 1fr 1fr;
+`;
+
+const StyledTooltipRow = styled.div`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[1]};
+ white-space: nowrap;
+`;
+
+const StyledMeterRow = styled.div`
+ display: grid;
+ gap: ${themeCssVariables.spacing[2]};
+ grid-template-columns: 1fr 1fr;
+`;
+
+const StyledAmountField = styled.div`
+ flex: 1;
+ min-width: 0;
+`;
+
+const StyledRingAnchor = styled.div`
+ align-items: center;
+ display: flex;
+`;
+
+type SettingsBillingLimitFormProps = {
+ definitions: UsageQuotaDefinitionsQuery['usageQuotaDefinitions'];
+ values: UsageLimitFormValues;
+ scopeConsumption: UsageQuotaScopeConsumption | null;
+ onChange: (values: UsageLimitFormValues) => void;
+};
+
+export const SettingsBillingLimitForm = ({
+ definitions,
+ values,
+ scopeConsumption,
+ onChange,
+}: SettingsBillingLimitFormProps) => {
+ const { t } = useLingui();
+ const { formatLimitValue } = useUsageLimitFormatter();
+
+ const options = getUsageLimitFormOptions({ definitions, values });
+
+ const handleScopeChange = ({
+ resourceType,
+ operationType,
+ }: {
+ resourceType: UsageResourceType;
+ operationType: UsageOperationType;
+ }) => {
+ const isNewResource = resourceType !== values.resourceType;
+ const nextValues: UsageLimitFormValues = isNewResource
+ ? {
+ ...values,
+ resourceType,
+ operationType,
+ spenderType: null,
+ spenderId: '',
+ meter: null,
+ periodUnit: 'month',
+ }
+ : { ...values, operationType };
+
+ const nextOptions = getUsageLimitFormOptions({
+ definitions,
+ values: nextValues,
+ });
+
+ onChange({
+ ...nextValues,
+ spenderType: isNewResource
+ ? (nextOptions.spenderTypes[0] ?? null)
+ : nextValues.spenderType,
+ meter:
+ isDefined(nextValues.meter) &&
+ nextOptions.meters.includes(nextValues.meter)
+ ? nextValues.meter
+ : (nextOptions.meters[0] ?? null),
+ });
+ };
+
+ const isCreditsMeter = values.meter === 'creditsUsedMicro';
+ const consumedValue = scopeConsumption?.consumedValue ?? null;
+ const limitValue = Number(values.limitValue);
+ const progress = computeUsageLimitProgress({
+ limitValue: isCreditsMeter
+ ? limitValue * INTERNAL_CREDITS_PER_DISPLAY_CREDIT
+ : limitValue,
+ consumedValue,
+ });
+ const consumedPercentage = progress?.consumedPercentage ?? 0;
+ const isExhausted = progress?.remainingValue === 0;
+ const hasConsumption = isDefined(consumedValue) && consumedValue > 0;
+ const consumedText = isDefined(consumedValue)
+ ? formatLimitValue({
+ value: consumedValue,
+ meter: values.meter ?? '',
+ operationType: values.operationType ?? UsageOperationType.ALL,
+ })
+ : '';
+ const periodSpanLabel = isDefined(values.periodUnit)
+ ? t(USAGE_LIMIT_PERIOD_SPAN_LABELS[values.periodUnit])
+ : '';
+
+ const hasResource = isDefined(values.resourceType);
+
+ const placeholderOption = hasResource
+ ? undefined
+ : { value: null, label: t`Choose a usage first` };
+
+ return (
+ <>
+ <Section>
+ <H2Title
+ title={t`Scope`}
+ description={t`The usage this limit applies to.`}
+ />
+ <StyledRow>
+ <SettingsBillingLimitUsageSelect
+ definitions={definitions}
+ resourceType={values.resourceType}
+ operationType={values.operationType}
+ onChange={handleScopeChange}
+ />
+ <SettingsBillingLimitSpenderSelect
+ allowedSpenderTypes={options.spenderTypes}
+ isIntraWorkspaceLimitEntitled={
+ definitions.isIntraWorkspaceLimitEntitled
+ }
+ spenderType={values.spenderType}
+ spenderId={values.spenderId}
+ isDisabled={!hasResource}
+ onChange={(spender) => onChange({ ...values, ...spender })}
+ />
+ </StyledRow>
+ </Section>
+ <Section>
+ <H2Title
+ title={t`Limit`}
+ description={t`How much can be spent, and how often it resets.`}
+ />
+ <StyledRow>
+ <StyledAmountField>
+ <StyledSettingsBillingFieldLabel>
+ {isCreditsMeter ? t`Credits` : t`Amount`}
+ </StyledSettingsBillingFieldLabel>
+ <SettingsTextInput
+ instanceId="usage-limit-value"
+ placeholder={isCreditsMeter ? '100' : '1000'}
+ type="number"
+ min={0}
+ value={values.limitValue}
+ onChange={(limitValue) => onChange({ ...values, limitValue })}
+ fullWidth
+ disabled={!hasResource}
+ RightIcon={() => (
+ <StyledRingAnchor id={RING_ANCHOR_ID}>
+ <ProgressRing
+ value={consumedPercentage}
+ barColor={getUsageLimitRingColor({
+ consumedPercentage,
+ isExhausted,
+ })}
+ />
+ </StyledRingAnchor>
+ )}
+ />
+ <AppTooltip
+ anchorSelect={`#${RING_ANCHOR_ID}`}
+ place="top"
+ delay={TooltipDelay.shortDelay}
+ positionStrategy="fixed"
+ >
+ {hasConsumption ? (
+ <StyledTooltipRow>
+ {t`Used`}
+ <SettingsBillingLimitAmount
+ text={consumedText}
+ isCreditsMeter={isCreditsMeter}
+ />
+ {`· ${periodSpanLabel}`}
+ </StyledTooltipRow>
+ ) : (
+ t`Nothing counted against this scope yet`
+ )}
+ </AppTooltip>
+ </StyledAmountField>
+ <StyledMeterRow>
+ <Select
+ dropdownId="usage-limit-meter"
+ label={t`Meter`}
+ fullWidth
+ disabled={options.meters.length <= 1}
+ value={values.meter ?? undefined}
+ options={options.meters.map((meter: UsageLimitMeter) => ({
+ value: meter,
+ label: t(USAGE_LIMIT_METER_LABELS[meter]),
+ Icon: USAGE_LIMIT_METER_ICONS[meter],
+ }))}
+ emptyOption={placeholderOption}
+ onChange={(meter) =>
+ isDefined(meter) && onChange({ ...values, meter })
+ }
+ />
+ <Select
+ dropdownId="usage-limit-period-unit"
+ label={t`Period`}
+ fullWidth
+ disabled={!hasResource}
+ value={values.periodUnit ?? undefined}
+ options={options.periodUnits.map(
+ (periodUnit: UsageLimitPeriodUnit) => ({
+ value: periodUnit,
+ label: t(USAGE_LIMIT_PERIOD_UNIT_LABELS[periodUnit]),
+ Icon: USAGE_LIMIT_PERIOD_ICONS[periodUnit],
+ }),
+ )}
+ emptyOption={placeholderOption}
+ onChange={(periodUnit) =>
+ isDefined(periodUnit) && onChange({ ...values, periodUnit })
+ }
+ />
+ </StyledMeterRow>
+ </StyledRow>
+ </Section>
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
new file mode 100644
index 00000000000..47b8b749b77
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
@@ -0,0 +1,292 @@
+import { useLingui } from '@lingui/react/macro';
+import { useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { Avatar } from 'twenty-ui/data-display';
+import { IconChevronLeft } from 'twenty-ui/icon';
+import { MenuItemSelect, MenuItemSelectAvatar } from 'twenty-ui/navigation';
+
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
+import { SettingsBillingLimitNestedSelect } from '@/settings/billing/components/internal/SettingsBillingLimitNestedSelect';
+import { AVATAR_SPENDER_TYPES } from '@/settings/billing/constants/AvatarSpenderTypes';
+import { USAGE_LIMIT_SPENDER_TYPE_ICONS } from '@/settings/billing/constants/UsageLimitSpenderTypeIcons';
+import { USAGE_LIMIT_SPENDER_TYPE_LABELS } from '@/settings/billing/constants/UsageLimitSpenderTypeLabels';
+import { USAGE_LIMIT_SPENDER_TYPE_POOL_LABELS } from '@/settings/billing/constants/UsageLimitSpenderTypePoolLabels';
+import {
+ type UsageLimitSpenderOption,
+ useUsageLimitSpenderOptions,
+} from '@/settings/billing/hooks/useUsageLimitSpenderOptions';
+import { type UsageLimitSpenderType } from '@/settings/billing/types/UsageLimitSpenderType';
+import { getUsageLimitSpenderGroups } from '@/settings/billing/utils/getUsageLimitSpenderGroups';
+import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
+import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader/DropdownMenuHeader';
+import { DropdownMenuHeaderLeftComponent } from '@/ui/layout/dropdown/components/DropdownMenuHeader/internal/DropdownMenuHeaderLeftComponent';
+import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
+import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator';
+import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
+import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
+
+const SPENDER_DROPDOWN_ID = 'usage-limit-spender';
+
+type SettingsBillingLimitSpenderSelectProps = {
+ allowedSpenderTypes: string[];
+ isIntraWorkspaceLimitEntitled: boolean;
+ spenderType: UsageLimitSpenderType | null;
+ spenderId: string;
+ isDisabled?: boolean;
+ onChange: (spender: {
+ spenderType: UsageLimitSpenderType;
+ spenderId: string;
+ }) => void;
+};
+
+export const SettingsBillingLimitSpenderSelect = ({
+ allowedSpenderTypes,
+ isIntraWorkspaceLimitEntitled,
+ spenderType,
+ spenderId,
+ isDisabled = false,
+ onChange,
+}: SettingsBillingLimitSpenderSelectProps) => {
+ const { t } = useLingui();
+ const { closeDropdown } = useCloseDropdown();
+ const currentWorkspace = useAtomStateValue(currentWorkspaceState);
+
+ const [browsedSpenderType, setBrowsedSpenderType] =
+ useState<UsageLimitSpenderType | null>(null);
+
+ const groups = getUsageLimitSpenderGroups(allowedSpenderTypes);
+
+ const listedSpenderType = browsedSpenderType ?? undefined;
+ const { spenderOptionsByType, loading } = useUsageLimitSpenderOptions(
+ [listedSpenderType, spenderType].filter(isDefined),
+ );
+
+ const listedSpenderOptions = isDefined(listedSpenderType)
+ ? (spenderOptionsByType[listedSpenderType] ?? [])
+ : [];
+ const selectedSpenderOptions = isDefined(spenderType)
+ ? (spenderOptionsByType[spenderType] ?? [])
+ : [];
+
+ const workspaceName = currentWorkspace?.displayName ?? t`Workspace`;
+ const workspaceAvatarUrl = getAbsoluteImageUrl(
+ currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
+ );
+
+ const resetNavigation = () => setBrowsedSpenderType(null);
+
+ const handleSelect = (
+ nextSpenderType: UsageLimitSpenderType,
+ nextSpenderId: string,
+ ) => {
+ onChange({ spenderType: nextSpenderType, spenderId: nextSpenderId });
+ resetNavigation();
+ closeDropdown(SPENDER_DROPDOWN_ID);
+ };
+
+ const getSelectedLabel = (): string => {
+ if (!isDefined(spenderType)) {
+ return t`Choose a spender`;
+ }
+
+ if (spenderType === 'workspace') {
+ return workspaceName;
+ }
+
+ if (spenderId === '') {
+ return t(USAGE_LIMIT_SPENDER_TYPE_POOL_LABELS[spenderType]);
+ }
+
+ return (
+ selectedSpenderOptions.find((option) => option.id === spenderId)?.label ??
+ t(USAGE_LIMIT_SPENDER_TYPE_LABELS[spenderType])
+ );
+ };
+
+ const renderSelectedAvatar = () => {
+ if (spenderType === 'workspace') {
+ return (
+ <Avatar
+ placeholder={workspaceName}
+ avatarUrl={workspaceAvatarUrl}
+ type="squared"
+ size="md"
+ />
+ );
+ }
+
+ if (
+ !isDefined(spenderType) ||
+ spenderId === '' ||
+ !AVATAR_SPENDER_TYPES.includes(spenderType)
+ ) {
+ return undefined;
+ }
+
+ const selectedOption = selectedSpenderOptions.find(
+ (option) => option.id === spenderId,
+ );
+
+ return (
+ <Avatar
+ placeholder={selectedOption?.label ?? ''}
+ avatarUrl={selectedOption?.avatarUrl}
+ type={spenderType === 'userWorkspace' ? 'rounded' : 'squared'}
+ size="md"
+ />
+ );
+ };
+
+ const renderOption = (
+ kind: UsageLimitSpenderType,
+ option: UsageLimitSpenderOption,
+ ) => {
+ const selected = spenderType === kind && spenderId === option.id;
+
+ if (AVATAR_SPENDER_TYPES.includes(kind)) {
+ return (
+ <MenuItemSelectAvatar
+ key={option.id}
+ text={option.label}
+ selected={selected}
+ avatar={
+ <Avatar
+ placeholder={option.label}
+ avatarUrl={option.avatarUrl}
+ type={kind === 'userWorkspace' ? 'rounded' : 'squared'}
+ size="md"
+ />
+ }
+ onClick={() => handleSelect(kind, option.id)}
+ />
+ );
+ }
+
+ return (
+ <MenuItemSelect
+ key={option.id}
+ LeftIcon={USAGE_LIMIT_SPENDER_TYPE_ICONS[kind]}
+ text={option.label}
+ selected={selected}
+ onClick={() => handleSelect(kind, option.id)}
+ />
+ );
+ };
+
+ const renderOptionList = (kind: UsageLimitSpenderType) => (
+ <>
+ <MenuItemSelect
+ text={t(USAGE_LIMIT_SPENDER_TYPE_POOL_LABELS[kind])}
+ selected={spenderType === kind && spenderId === ''}
+ onClick={() => handleSelect(kind, '')}
+ />
+ {loading ? (
+ <MenuItemSelect text={t`Loading…`} selected={false} disabled />
+ ) : (
+ listedSpenderOptions.map((option) => renderOption(kind, option))
+ )}
+ </>
+ );
+
+ const renderBackHeader = (title: string, onBack: () => void) => (
+ <DropdownMenuHeader
+ StartComponent={
+ <DropdownMenuHeaderLeftComponent
+ onClick={onBack}
+ Icon={IconChevronLeft}
+ />
+ }
+ >
+ {title}
+ </DropdownMenuHeader>
+ );
+
+ const renderSubSpenderContent = (kind: UsageLimitSpenderType) => (
+ <DropdownContent>
+ {renderBackHeader(t(USAGE_LIMIT_SPENDER_TYPE_LABELS[kind]), () =>
+ setBrowsedSpenderType(null),
+ )}
+ <DropdownMenuItemsContainer>
+ {renderOptionList(kind)}
+ </DropdownMenuItemsContainer>
+ </DropdownContent>
+ );
+
+ const workspaceGroup = groups.find((group) => group.id === 'workspace');
+ const otherGroups = groups.filter((group) => group.id !== 'workspace');
+
+ const renderRootContent = () => (
+ <DropdownContent>
+ {isDefined(workspaceGroup) && (
+ <DropdownMenuItemsContainer>
+ <MenuItemSelectAvatar
+ text={workspaceName}
+ contextualText={t`Workspace`}
+ selected={spenderType === 'workspace'}
+ avatar={
+ <Avatar
+ placeholder={workspaceName}
+ avatarUrl={workspaceAvatarUrl}
+ type="squared"
+ size="md"
+ />
+ }
+ onClick={() => handleSelect('workspace', '')}
+ />
+ </DropdownMenuItemsContainer>
+ )}
+ {isDefined(workspaceGroup) && otherGroups.length > 0 && (
+ <DropdownMenuSeparator />
+ )}
+ {otherGroups.length > 0 && (
+ <DropdownMenuItemsContainer>
+ {otherGroups.map((group) => (
+ <MenuItemSelect
+ key={group.id}
+ LeftIcon={group.Icon}
+ text={t(group.label)}
+ selected={false}
+ hasSubMenu
+ disabled={!isIntraWorkspaceLimitEntitled}
+ contextualText={
+ isIntraWorkspaceLimitEntitled ? undefined : t`Organization plan`
+ }
+ contextualTextPosition="right"
+ onClick={() => setBrowsedSpenderType(group.spenderType)}
+ />
+ ))}
+ </DropdownMenuItemsContainer>
+ )}
+ </DropdownContent>
+ );
+
+ const renderContent = () => {
+ if (isDefined(browsedSpenderType)) {
+ return renderSubSpenderContent(browsedSpenderType);
+ }
+
+ return renderRootContent();
+ };
+
+ return (
+ <SettingsBillingLimitNestedSelect
+ dropdownId={SPENDER_DROPDOWN_ID}
+ label={t`Spender`}
+ selectedLabel={getSelectedLabel()}
+ selectedContextualText={
+ spenderType === 'workspace' ? t`Workspace` : undefined
+ }
+ SelectedIcon={
+ isDefined(spenderType)
+ ? USAGE_LIMIT_SPENDER_TYPE_ICONS[spenderType]
+ : undefined
+ }
+ SelectedAvatar={renderSelectedAvatar()}
+ isDisabled={isDisabled}
+ onClose={resetNavigation}
+ dropdownComponents={renderContent()}
+ />
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitUsageSelect.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitUsageSelect.tsx
new file mode 100644
index 00000000000..ce078a0b420
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitUsageSelect.tsx
@@ -0,0 +1,139 @@
+import { useLingui } from '@lingui/react/macro';
+import { useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { IconChevronLeft } from 'twenty-ui/icon';
+import { MenuItemSelect } from 'twenty-ui/navigation';
+
+import { SettingsBillingLimitNestedSelect } from '@/settings/billing/components/internal/SettingsBillingLimitNestedSelect';
+import { USAGE_LIMIT_OPERATION_TYPE_ICONS } from '@/settings/billing/constants/UsageLimitOperationTypeIcons';
+import { USAGE_LIMIT_RESOURCE_TYPE_ICONS } from '@/settings/billing/constants/UsageLimitResourceTypeIcons';
+import { USAGE_LIMIT_RESOURCE_TYPE_LABELS } from '@/settings/billing/constants/UsageLimitResourceTypeLabels';
+import { getUsageLimitOperationTypes } from '@/settings/billing/utils/getUsageLimitOperationTypes';
+import { USAGE_OPERATION_TYPE_LABELS } from '@/settings/usage/constants/UsageOperationTypeLabels';
+import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';
+import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader/DropdownMenuHeader';
+import { DropdownMenuHeaderLeftComponent } from '@/ui/layout/dropdown/components/DropdownMenuHeader/internal/DropdownMenuHeaderLeftComponent';
+import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
+import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';
+import {
+ type UsageOperationType,
+ type UsageQuotaDefinitionsQuery,
+ type UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const USAGE_DROPDOWN_ID = 'usage-limit-usage';
+
+type SettingsBillingLimitUsageSelectProps = {
+ definitions: UsageQuotaDefinitionsQuery['usageQuotaDefinitions'];
+ resourceType: UsageResourceType | null;
+ operationType: UsageOperationType | null;
+ onChange: (scope: {
+ resourceType: UsageResourceType;
+ operationType: UsageOperationType;
+ }) => void;
+};
+
+export const SettingsBillingLimitUsageSelect = ({
+ definitions,
+ resourceType,
+ operationType,
+ onChange,
+}: SettingsBillingLimitUsageSelectProps) => {
+ const { t } = useLingui();
+ const { closeDropdown } = useCloseDropdown();
+
+ const [browsedResourceType, setBrowsedResourceType] =
+ useState<UsageResourceType | null>(null);
+
+ const browsedDefinition = definitions.definitions.find(
+ (definition) => definition.resourceType === browsedResourceType,
+ );
+
+ const handleSelect = (nextOperationType: UsageOperationType) => {
+ if (!isDefined(browsedResourceType)) {
+ return;
+ }
+
+ onChange({
+ resourceType: browsedResourceType,
+ operationType: nextOperationType,
+ });
+ setBrowsedResourceType(null);
+ closeDropdown(USAGE_DROPDOWN_ID);
+ };
+
+ const operationLabel = isDefined(operationType)
+ ? t(USAGE_OPERATION_TYPE_LABELS[operationType])
+ : t`All operations`;
+
+ const selectedLabel = isDefined(resourceType)
+ ? `${t(USAGE_LIMIT_RESOURCE_TYPE_LABELS[resourceType])} · ${operationLabel}`
+ : t`Choose a usage`;
+
+ return (
+ <SettingsBillingLimitNestedSelect
+ dropdownId={USAGE_DROPDOWN_ID}
+ label={t`Usage`}
+ selectedLabel={selectedLabel}
+ SelectedIcon={
+ isDefined(resourceType)
+ ? USAGE_LIMIT_RESOURCE_TYPE_ICONS[resourceType]
+ : undefined
+ }
+ onClose={() => setBrowsedResourceType(null)}
+ dropdownComponents={
+ isDefined(browsedResourceType) && isDefined(browsedDefinition) ? (
+ <DropdownContent>
+ <DropdownMenuHeader
+ StartComponent={
+ <DropdownMenuHeaderLeftComponent
+ onClick={() => setBrowsedResourceType(null)}
+ Icon={IconChevronLeft}
+ />
+ }
+ >
+ {t(USAGE_LIMIT_RESOURCE_TYPE_LABELS[browsedResourceType])}
+ </DropdownMenuHeader>
+ <DropdownMenuItemsContainer>
+ {getUsageLimitOperationTypes(browsedDefinition).map(
+ (candidate) => (
+ <MenuItemSelect
+ key={candidate}
+ LeftIcon={USAGE_LIMIT_OPERATION_TYPE_ICONS[candidate]}
+ text={t(USAGE_OPERATION_TYPE_LABELS[candidate])}
+ selected={
+ resourceType === browsedResourceType &&
+ operationType === candidate
+ }
+ onClick={() => handleSelect(candidate)}
+ />
+ ),
+ )}
+ </DropdownMenuItemsContainer>
+ </DropdownContent>
+ ) : (
+ <DropdownContent>
+ <DropdownMenuItemsContainer>
+ {definitions.definitions.map((definition) => (
+ <MenuItemSelect
+ key={definition.resourceType}
+ LeftIcon={
+ USAGE_LIMIT_RESOURCE_TYPE_ICONS[definition.resourceType]
+ }
+ text={t(
+ USAGE_LIMIT_RESOURCE_TYPE_LABELS[definition.resourceType],
+ )}
+ selected={false}
+ hasSubMenu
+ onClick={() =>
+ setBrowsedResourceType(definition.resourceType)
+ }
+ />
+ ))}
+ </DropdownMenuItemsContainer>
+ </DropdownContent>
+ )
+ }
+ />
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsContent.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsContent.tsx
index 5c81e80ce40..48ef42c472c 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsContent.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsContent.tsx
@@ -1,12 +1,13 @@
import { useLingui } from '@lingui/react/macro';
-import { isDefined } from 'twenty-shared/utils';
+import { Navigate } from 'react-router-dom';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath, isDefined } from 'twenty-shared/utils';
import { Section } from 'twenty-ui/layout';
import { H2Title } from 'twenty-ui/typography';
import { SettingsBillingLimitsTable } from '@/settings/billing/components/SettingsBillingLimitsTable';
import { useUsageQuotasWithConsumption } from '@/settings/billing/hooks/useUsageQuotasWithConsumption';
import { hasKnownUsageLimitSpender } from '@/settings/billing/utils/hasKnownUsageLimitSpender';
-import { SettingsEmptyPlaceholder } from '@/settings/components/SettingsEmptyPlaceholder';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
export const SettingsBillingLimitsContent = () => {
@@ -35,17 +36,7 @@ export const SettingsBillingLimitsContent = () => {
if (quotas.length === 0) {
return (
- <SettingsPageContainer>
- <Section>
- <H2Title
- title={t`Limits`}
- description={t`Caps on what your workspace can spend and who they apply to`}
- />
- <SettingsEmptyPlaceholder>
- {t`No limit yet.`}
- </SettingsEmptyPlaceholder>
- </Section>
- </SettingsPageContainer>
+ <Navigate to={getSettingsPath(SettingsPath.BillingNewLimit)} replace />
);
}
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsTable.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsTable.tsx
index e8eeb1ea55b..ced03919fab 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsTable.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitsTable.tsx
@@ -1,6 +1,7 @@
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { type ReactNode, useContext, useState } from 'react';
+import { SettingsPath } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { SearchInput } from 'twenty-ui/input';
import { AppTooltip, TooltipDelay } from 'twenty-ui/surfaces';
@@ -19,6 +20,7 @@ import { SettingsNameCellSecondaryLabel } from '@/settings/components/SettingsNa
import { SettingsTableListSection } from '@/settings/components/SettingsTableListSection';
import { ProgressRing } from '@/ui/feedback/progress-ring/components/ProgressRing';
import { type UsageResourceType } from '~/generated-metadata/graphql';
+import { useNavigateSettings } from '~/hooks/useNavigateSettings';
const GRID_AUTO_COLUMNS = '1.2fr 1fr 120px 96px';
@@ -173,6 +175,7 @@ export const SettingsBillingLimitsTable = ({
quotas,
}: SettingsBillingLimitsTableProps) => {
const { t } = useLingui();
+ const navigate = useNavigateSettings();
const [searchText, setSearchText] = useState('');
const [resourceType, setResourceType] = useState<UsageResourceType | null>(
@@ -242,6 +245,10 @@ export const SettingsBillingLimitsTable = ({
{ label: t`Used`, align: 'right', Cell: UsedCell },
]}
gridAutoColumns={GRID_AUTO_COLUMNS}
+ showRowChevron
+ onRowClick={(row) =>
+ navigate(SettingsPath.BillingLimitEdit, { usageLimitId: row.id })
+ }
/>
{filteredRows.length === 0 && (
<SettingsEmptyPlaceholder>
diff --git a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx
new file mode 100644
index 00000000000..b89e17a1ee0
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx
@@ -0,0 +1,81 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { SettingsBillingLimitForm } from '@/settings/billing/components/SettingsBillingLimitForm';
+import { EMPTY_USAGE_LIMIT_FORM_VALUES } from '@/settings/billing/constants/EmptyUsageLimitFormValues';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const DEFINITIONS = {
+ __typename: 'UsageQuotaDefinitions' as const,
+ definitions: [
+ {
+ __typename: 'UsageQuotaDefinition' as const,
+ resourceType: UsageResourceType.AI,
+ allowedOperationTypes: [
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.AI_WORKFLOW_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ],
+ allowedSpenderTypes: ['workspace', 'userWorkspace', 'apiKey'],
+ allowedMeters: ['creditsUsedMicro', 'quantity'],
+ },
+ ],
+ isIntraWorkspaceLimitEntitled: true,
+ hasAllowancePeriod: true,
+};
+
+const FILLED_VALUES = {
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.AI_CHAT_TOKEN,
+ spenderType: 'workspace' as const,
+ spenderId: '',
+ meter: 'creditsUsedMicro' as const,
+ periodUnit: 'month' as const,
+ limitValue: '100',
+};
+
+const meta: Meta<typeof SettingsBillingLimitForm> = {
+ title: 'Modules/Settings/Billing/SettingsBillingLimitForm',
+ component: SettingsBillingLimitForm,
+ decorators: [ComponentDecorator],
+ args: {
+ definitions: DEFINITIONS,
+ values: EMPTY_USAGE_LIMIT_FORM_VALUES,
+ scopeConsumption: null,
+ onChange: () => {},
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof SettingsBillingLimitForm>;
+
+export const Empty: Story = {};
+
+export const Filled: Story = {
+ args: { values: FILLED_VALUES },
+};
+
+export const WithConsumption: Story = {
+ args: {
+ values: FILLED_VALUES,
+ scopeConsumption: {
+ consumedValue: 62_000_000,
+ periodStart: '2026-09-01T00:00:00.000Z',
+ periodEnd: '2026-10-01T00:00:00.000Z',
+ },
+ },
+};
+
+export const AllOperations: Story = {
+ args: {
+ values: {
+ ...FILLED_VALUES,
+ operationType: UsageOperationType.ALL,
+ periodUnit: 'allowancePeriod',
+ limitValue: '1000',
+ },
+ },
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx
new file mode 100644
index 00000000000..ba363637a1f
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx
@@ -0,0 +1,40 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { SettingsBillingLimitSpenderSelect } from '@/settings/billing/components/SettingsBillingLimitSpenderSelect';
+
+const meta: Meta<typeof SettingsBillingLimitSpenderSelect> = {
+ title: 'Modules/Settings/Billing/SettingsBillingLimitSpenderSelect',
+ component: SettingsBillingLimitSpenderSelect,
+ decorators: [ComponentDecorator],
+ args: {
+ allowedSpenderTypes: [
+ 'workspace',
+ 'userWorkspace',
+ 'apiKey',
+ 'application',
+ 'agent',
+ ],
+ isIntraWorkspaceLimitEntitled: true,
+ spenderType: 'workspace',
+ spenderId: '',
+ onChange: () => {},
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof SettingsBillingLimitSpenderSelect>;
+
+export const WorkspaceWide: Story = {};
+
+export const AllUsers: Story = {
+ args: { spenderType: 'userWorkspace', spenderId: '' },
+};
+
+export const WorkspaceOnlyPlan: Story = {
+ args: { isIntraWorkspaceLimitEntitled: false },
+};
+
+export const ReadOnly: Story = {
+ args: { isDisabled: true },
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitUsageSelect.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitUsageSelect.stories.tsx
new file mode 100644
index 00000000000..85292b2b9aa
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitUsageSelect.stories.tsx
@@ -0,0 +1,58 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { SettingsBillingLimitUsageSelect } from '@/settings/billing/components/SettingsBillingLimitUsageSelect';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const DEFINITIONS = {
+ __typename: 'UsageQuotaDefinitions' as const,
+ definitions: [
+ {
+ __typename: 'UsageQuotaDefinition' as const,
+ resourceType: UsageResourceType.AI,
+ allowedOperationTypes: [
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.AI_WORKFLOW_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ],
+ allowedSpenderTypes: ['workspace', 'userWorkspace', 'apiKey'],
+ allowedMeters: ['creditsUsedMicro', 'quantity'],
+ },
+ ],
+ isIntraWorkspaceLimitEntitled: true,
+ hasAllowancePeriod: true,
+};
+
+const meta: Meta<typeof SettingsBillingLimitUsageSelect> = {
+ title: 'Modules/Settings/Billing/SettingsBillingLimitUsageSelect',
+ component: SettingsBillingLimitUsageSelect,
+ decorators: [ComponentDecorator],
+ args: {
+ definitions: DEFINITIONS,
+ resourceType: null,
+ operationType: null,
+ onChange: () => {},
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof SettingsBillingLimitUsageSelect>;
+
+export const Empty: Story = {};
+
+export const Chosen: Story = {
+ args: {
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.AI_CHAT_TOKEN,
+ },
+};
+
+export const AllOperations: Story = {
+ args: {
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.ALL,
+ },
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingFieldLabel.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingFieldLabel.tsx
new file mode 100644
index 00000000000..99c7a94721e
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingFieldLabel.tsx
@@ -0,0 +1,10 @@
+import { styled } from '@linaria/react';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
+
+export const StyledSettingsBillingFieldLabel = styled.span`
+ color: ${themeCssVariables.font.color.light};
+ display: block;
+ font-size: ${themeCssVariables.font.size.xs};
+ font-weight: ${themeCssVariables.font.weight.semiBold};
+ margin-bottom: ${themeCssVariables.spacing[1]};
+`;
diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingLimitNestedSelect.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingLimitNestedSelect.tsx
new file mode 100644
index 00000000000..aa06a171251
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingLimitNestedSelect.tsx
@@ -0,0 +1,68 @@
+import { styled } from '@linaria/react';
+import { type ReactNode } from 'react';
+import { type IconComponent } from 'twenty-ui/icon';
+
+import { StyledSettingsBillingFieldLabel } from '@/settings/billing/components/internal/SettingsBillingFieldLabel';
+import { SelectControl } from '@/ui/input/components/SelectControl';
+import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
+
+const StyledContainer = styled.div`
+ width: 100%;
+`;
+
+type SettingsBillingLimitNestedSelectProps = {
+ dropdownId: string;
+ label: string;
+ selectedLabel: string;
+ selectedContextualText?: string;
+ SelectedIcon?: IconComponent;
+ SelectedAvatar?: ReactNode;
+ isDisabled?: boolean;
+ dropdownComponents: ReactNode;
+ onClose?: () => void;
+};
+
+export const SettingsBillingLimitNestedSelect = ({
+ dropdownId,
+ label,
+ selectedLabel,
+ selectedContextualText,
+ SelectedIcon,
+ SelectedAvatar,
+ isDisabled = false,
+ dropdownComponents,
+ onClose,
+}: SettingsBillingLimitNestedSelectProps) => {
+ const selectedOption = {
+ value: selectedLabel,
+ label: selectedLabel,
+ contextualText: selectedContextualText,
+ Icon: SelectedIcon,
+ };
+
+ return (
+ <StyledContainer>
+ <StyledSettingsBillingFieldLabel>{label}</StyledSettingsBillingFieldLabel>
+ {isDisabled ? (
+ <SelectControl
+ selectedOption={selectedOption}
+ LeftComponent={SelectedAvatar}
+ isDisabled
+ />
+ ) : (
+ <Dropdown
+ dropdownId={dropdownId}
+ dropdownPlacement="bottom-start"
+ onClose={onClose}
+ clickableComponent={
+ <SelectControl
+ selectedOption={selectedOption}
+ LeftComponent={SelectedAvatar}
+ />
+ }
+ dropdownComponents={dropdownComponents}
+ />
+ )}
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/EmptyUsageLimitFormValues.ts b/packages/twenty-front/src/modules/settings/billing/constants/EmptyUsageLimitFormValues.ts
new file mode 100644
index 00000000000..445faefa53a
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/EmptyUsageLimitFormValues.ts
@@ -0,0 +1,11 @@
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+
+export const EMPTY_USAGE_LIMIT_FORM_VALUES: UsageLimitFormValues = {
+ resourceType: null,
+ operationType: null,
+ spenderType: 'workspace',
+ spenderId: '',
+ meter: null,
+ periodUnit: null,
+ limitValue: '',
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitMeterIcons.ts b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitMeterIcons.ts
new file mode 100644
index 00000000000..8b6c602b272
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitMeterIcons.ts
@@ -0,0 +1,8 @@
+import { IconCoins, type IconComponent, IconNumber123 } from 'twenty-ui/icon';
+
+import { type UsageLimitMeter } from '@/settings/billing/types/UsageLimitMeter';
+
+export const USAGE_LIMIT_METER_ICONS: Record<UsageLimitMeter, IconComponent> = {
+ creditsUsedMicro: IconCoins,
+ quantity: IconNumber123,
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitMeterLabels.ts b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitMeterLabels.ts
new file mode 100644
index 00000000000..34a4fd1e178
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitMeterLabels.ts
@@ -0,0 +1,12 @@
+import { type MessageDescriptor } from '@lingui/core';
+import { msg } from '@lingui/core/macro';
+
+import { type UsageLimitMeter } from '@/settings/billing/types/UsageLimitMeter';
+
+export const USAGE_LIMIT_METER_LABELS: Record<
+ UsageLimitMeter,
+ MessageDescriptor
+> = {
+ creditsUsedMicro: msg`Credits`,
+ quantity: msg`Operations`,
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodIcons.ts b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodIcons.ts
new file mode 100644
index 00000000000..db893b2432a
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodIcons.ts
@@ -0,0 +1,19 @@
+import {
+ IconCalendarMonth,
+ IconCalendarRepeat,
+ IconCalendarWeek,
+ type IconComponent,
+ IconSun,
+} from 'twenty-ui/icon';
+
+import { type UsageLimitPeriodUnit } from '@/settings/billing/types/UsageLimitPeriodUnit';
+
+export const USAGE_LIMIT_PERIOD_ICONS: Record<
+ UsageLimitPeriodUnit,
+ IconComponent
+> = {
+ day: IconSun,
+ week: IconCalendarWeek,
+ month: IconCalendarMonth,
+ allowancePeriod: IconCalendarRepeat,
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodSpanLabels.ts b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodSpanLabels.ts
new file mode 100644
index 00000000000..1e48c062813
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodSpanLabels.ts
@@ -0,0 +1,14 @@
+import { type MessageDescriptor } from '@lingui/core';
+import { msg } from '@lingui/core/macro';
+
+import { type UsageLimitPeriodUnit } from '@/settings/billing/types/UsageLimitPeriodUnit';
+
+export const USAGE_LIMIT_PERIOD_SPAN_LABELS: Record<
+ UsageLimitPeriodUnit,
+ MessageDescriptor
+> = {
+ day: msg`Today`,
+ week: msg`This week`,
+ month: msg`This month`,
+ allowancePeriod: msg`This billing period`,
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodUnitLabels.ts b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodUnitLabels.ts
new file mode 100644
index 00000000000..fcefadb3016
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitPeriodUnitLabels.ts
@@ -0,0 +1,14 @@
+import { type MessageDescriptor } from '@lingui/core';
+import { msg } from '@lingui/core/macro';
+
+import { type UsageLimitPeriodUnit } from '@/settings/billing/types/UsageLimitPeriodUnit';
+
+export const USAGE_LIMIT_PERIOD_UNIT_LABELS: Record<
+ UsageLimitPeriodUnit,
+ MessageDescriptor
+> = {
+ day: msg`Day`,
+ week: msg`Week`,
+ month: msg`Month`,
+ allowancePeriod: msg`Billing period`,
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitSpenderGroups.ts b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitSpenderGroups.ts
new file mode 100644
index 00000000000..b005f79f839
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/constants/UsageLimitSpenderGroups.ts
@@ -0,0 +1,45 @@
+import { type MessageDescriptor } from '@lingui/core';
+import { msg } from '@lingui/core/macro';
+import {
+ IconApps,
+ type IconComponent,
+ IconKey,
+ IconSettings,
+ IconUsers,
+} from 'twenty-ui/icon';
+
+import { type UsageLimitSpenderType } from '@/settings/billing/types/UsageLimitSpenderType';
+
+export type UsageLimitSpenderGroup = {
+ id: string;
+ label: MessageDescriptor;
+ Icon: IconComponent;
+ spenderType: UsageLimitSpenderType;
+};
+
+export const USAGE_LIMIT_SPENDER_GROUPS: UsageLimitSpenderGroup[] = [
+ {
+ id: 'workspace',
+ label: msg`Workspace`,
+ Icon: IconSettings,
+ spenderType: 'workspace',
+ },
+ {
+ id: 'user',
+ label: msg`User`,
+ Icon: IconUsers,
+ spenderType: 'userWorkspace',
+ },
+ {
+ id: 'application',
+ label: msg`Application`,
+ Icon: IconApps,
+ spenderType: 'application',
+ },
+ {
+ id: 'apiKey',
+ label: msg`API key`,
+ Icon: IconKey,
+ spenderType: 'apiKey',
+ },
+];
diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/mutations/createUsageLimit.ts b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/createUsageLimit.ts
new file mode 100644
index 00000000000..43470cb1988
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/createUsageLimit.ts
@@ -0,0 +1,9 @@
+import { gql } from '@apollo/client';
+
+export const CREATE_USAGE_LIMIT = gql`
+ mutation CreateUsageLimit($input: CreateUsageLimitInput!) {
+ createUsageLimit(input: $input) {
+ id
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/mutations/deleteUsageLimit.ts b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/deleteUsageLimit.ts
new file mode 100644
index 00000000000..0db3d6c7dfe
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/deleteUsageLimit.ts
@@ -0,0 +1,7 @@
+import { gql } from '@apollo/client';
+
+export const DELETE_USAGE_LIMIT = gql`
+ mutation DeleteUsageLimit($usageLimitId: UUID!) {
+ deleteUsageLimit(usageLimitId: $usageLimitId)
+ }
+`;
diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/mutations/updateUsageLimit.ts b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/updateUsageLimit.ts
new file mode 100644
index 00000000000..97fe5b97e08
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/updateUsageLimit.ts
@@ -0,0 +1,9 @@
+import { gql } from '@apollo/client';
+
+export const UPDATE_USAGE_LIMIT = gql`
+ mutation UpdateUsageLimit($input: UpdateUsageLimitInput!) {
+ updateUsageLimit(input: $input) {
+ id
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/queries/usageQuotaDefinitions.ts b/packages/twenty-front/src/modules/settings/billing/graphql/queries/usageQuotaDefinitions.ts
new file mode 100644
index 00000000000..ca19e72707e
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/graphql/queries/usageQuotaDefinitions.ts
@@ -0,0 +1,16 @@
+import { gql } from '@apollo/client';
+
+export const USAGE_QUOTA_DEFINITIONS = gql`
+ query UsageQuotaDefinitions {
+ usageQuotaDefinitions {
+ definitions {
+ resourceType
+ allowedOperationTypes
+ allowedSpenderTypes
+ allowedMeters
+ }
+ isIntraWorkspaceLimitEntitled
+ hasAllowancePeriod
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/queries/usageQuotaScopeConsumption.ts b/packages/twenty-front/src/modules/settings/billing/graphql/queries/usageQuotaScopeConsumption.ts
new file mode 100644
index 00000000000..9a818071d4e
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/graphql/queries/usageQuotaScopeConsumption.ts
@@ -0,0 +1,11 @@
+import { gql } from '@apollo/client';
+
+export const USAGE_QUOTA_SCOPE_CONSUMPTION = gql`
+ query UsageQuotaScopeConsumption($input: UsageQuotaScopeInput!) {
+ usageQuotaScopeConsumption(input: $input) {
+ consumedValue
+ periodStart
+ periodEnd
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useCreateUsageLimit.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useCreateUsageLimit.ts
new file mode 100644
index 00000000000..9cc700517a8
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useCreateUsageLimit.ts
@@ -0,0 +1,17 @@
+import { useMutation } from '@apollo/client/react';
+
+import {
+ CreateUsageLimitDocument,
+ UsageQuotasWithConsumptionDocument,
+} from '~/generated-metadata/graphql';
+
+export const useCreateUsageLimit = () => {
+ const [createUsageLimit, { loading }] = useMutation(
+ CreateUsageLimitDocument,
+ {
+ refetchQueries: [UsageQuotasWithConsumptionDocument],
+ },
+ );
+
+ return { createUsageLimit, loading };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useDeleteUsageLimit.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useDeleteUsageLimit.ts
new file mode 100644
index 00000000000..5b0d07dab84
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useDeleteUsageLimit.ts
@@ -0,0 +1,17 @@
+import { useMutation } from '@apollo/client/react';
+
+import {
+ DeleteUsageLimitDocument,
+ UsageQuotasWithConsumptionDocument,
+} from '~/generated-metadata/graphql';
+
+export const useDeleteUsageLimit = () => {
+ const [deleteUsageLimit, { loading }] = useMutation(
+ DeleteUsageLimitDocument,
+ {
+ refetchQueries: [UsageQuotasWithConsumptionDocument],
+ },
+ );
+
+ return { deleteUsageLimit, loading };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useUpdateUsageLimit.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useUpdateUsageLimit.ts
new file mode 100644
index 00000000000..5b5db6e6910
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useUpdateUsageLimit.ts
@@ -0,0 +1,17 @@
+import { useMutation } from '@apollo/client/react';
+
+import {
+ UpdateUsageLimitDocument,
+ UsageQuotasWithConsumptionDocument,
+} from '~/generated-metadata/graphql';
+
+export const useUpdateUsageLimit = () => {
+ const [updateUsageLimit, { loading }] = useMutation(
+ UpdateUsageLimitDocument,
+ {
+ refetchQueries: [UsageQuotasWithConsumptionDocument],
+ },
+ );
+
+ return { updateUsageLimit, loading };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useUsageQuotaDefinitions.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useUsageQuotaDefinitions.ts
new file mode 100644
index 00000000000..2b085614f5c
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useUsageQuotaDefinitions.ts
@@ -0,0 +1,12 @@
+import { useQuery } from '@apollo/client/react';
+
+import { UsageQuotaDefinitionsDocument } from '~/generated-metadata/graphql';
+
+export const useUsageQuotaDefinitions = () => {
+ const { data, loading } = useQuery(UsageQuotaDefinitionsDocument);
+
+ return {
+ usageQuotaDefinitions: data?.usageQuotaDefinitions,
+ loading,
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useUsageQuotaScopeConsumption.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useUsageQuotaScopeConsumption.ts
new file mode 100644
index 00000000000..281708338c5
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useUsageQuotaScopeConsumption.ts
@@ -0,0 +1,60 @@
+import { skipToken, useQuery } from '@apollo/client/react';
+import { useMemo } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { type UsageQuotaScopeConsumption } from '@/settings/billing/types/UsageQuotaScopeConsumption';
+import { buildUsageQuotaScopeInput } from '@/settings/billing/utils/buildUsageQuotaScopeInput';
+import { UsageQuotaScopeConsumptionDocument } from '~/generated-metadata/graphql';
+
+export const useUsageQuotaScopeConsumption = ({
+ resourceType,
+ operationType,
+ spenderType,
+ spenderId,
+ meter,
+ periodUnit,
+}: Omit<UsageLimitFormValues, 'limitValue'>): {
+ scopeConsumption: UsageQuotaScopeConsumption | null;
+ loading: boolean;
+} => {
+ const scopeInput = useMemo(
+ () =>
+ buildUsageQuotaScopeInput({
+ resourceType,
+ operationType,
+ spenderType,
+ spenderId,
+ meter,
+ periodUnit,
+ }),
+ [resourceType, operationType, spenderType, spenderId, meter, periodUnit],
+ );
+
+ const { data, loading } = useQuery(
+ UsageQuotaScopeConsumptionDocument,
+ isDefined(scopeInput) ? { variables: { input: scopeInput } } : skipToken,
+ );
+
+ const scopeConsumption = data?.usageQuotaScopeConsumption;
+
+ if (
+ !isDefined(scopeInput) ||
+ !isDefined(scopeConsumption) ||
+ !isDefined(scopeConsumption.periodStart) ||
+ !isDefined(scopeConsumption.periodEnd)
+ ) {
+ return { scopeConsumption: null, loading };
+ }
+
+ return {
+ scopeConsumption: {
+ consumedValue: isDefined(scopeConsumption.consumedValue)
+ ? Number(scopeConsumption.consumedValue)
+ : null,
+ periodStart: scopeConsumption.periodStart,
+ periodEnd: scopeConsumption.periodEnd,
+ },
+ loading,
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/types/UsageLimitFormValues.ts b/packages/twenty-front/src/modules/settings/billing/types/UsageLimitFormValues.ts
new file mode 100644
index 00000000000..4e74a0f8cc8
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/types/UsageLimitFormValues.ts
@@ -0,0 +1,17 @@
+import { type UsageLimitMeter } from '@/settings/billing/types/UsageLimitMeter';
+import { type UsageLimitPeriodUnit } from '@/settings/billing/types/UsageLimitPeriodUnit';
+import { type UsageLimitSpenderType } from '@/settings/billing/types/UsageLimitSpenderType';
+import {
+ type UsageOperationType,
+ type UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+export type UsageLimitFormValues = {
+ resourceType: UsageResourceType | null;
+ operationType: UsageOperationType | null;
+ spenderType: UsageLimitSpenderType | null;
+ spenderId: string;
+ meter: UsageLimitMeter | null;
+ periodUnit: UsageLimitPeriodUnit | null;
+ limitValue: string;
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/types/UsageQuotaScopeConsumption.ts b/packages/twenty-front/src/modules/settings/billing/types/UsageQuotaScopeConsumption.ts
new file mode 100644
index 00000000000..dca61edb076
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/types/UsageQuotaScopeConsumption.ts
@@ -0,0 +1,5 @@
+export type UsageQuotaScopeConsumption = {
+ consumedValue: number | null;
+ periodStart: string;
+ periodEnd: string;
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildCreateUsageLimitInput.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildCreateUsageLimitInput.test.ts
new file mode 100644
index 00000000000..e661e91369d
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildCreateUsageLimitInput.test.ts
@@ -0,0 +1,77 @@
+import { EMPTY_USAGE_LIMIT_FORM_VALUES } from '@/settings/billing/constants/EmptyUsageLimitFormValues';
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { buildCreateUsageLimitInput } from '@/settings/billing/utils/buildCreateUsageLimitInput';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const buildValues = (
+ overrides: Partial<UsageLimitFormValues> = {},
+): UsageLimitFormValues => ({
+ ...EMPTY_USAGE_LIMIT_FORM_VALUES,
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.ALL,
+ spenderType: 'workspace',
+ meter: 'creditsUsedMicro',
+ periodUnit: 'month',
+ limitValue: '100',
+ ...overrides,
+});
+
+describe('buildCreateUsageLimitInput', () => {
+ it('returns null while the scope is incomplete', () => {
+ expect(
+ buildCreateUsageLimitInput(EMPTY_USAGE_LIMIT_FORM_VALUES),
+ ).toBeNull();
+ expect(
+ buildCreateUsageLimitInput(buildValues({ spenderType: null })),
+ ).toBeNull();
+ });
+
+ it('always builds a one-period quota without burst', () => {
+ expect(
+ buildCreateUsageLimitInput(buildValues({ limitValue: '12.5' })),
+ ).toEqual({
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.ALL,
+ spenderType: 'workspace',
+ spenderId: null,
+ limitKind: 'quota',
+ periodCount: 1,
+ periodUnit: 'month',
+ meter: 'creditsUsedMicro',
+ limitValue: 12_500_000,
+ burstValue: null,
+ });
+ });
+
+ it('keeps a quantity quota as an integer and rejects fractions', () => {
+ expect(
+ buildCreateUsageLimitInput(
+ buildValues({
+ operationType: UsageOperationType.WEB_SEARCH,
+ meter: 'quantity',
+ limitValue: '200',
+ }),
+ ),
+ ).toEqual(expect.objectContaining({ limitValue: 200, meter: 'quantity' }));
+ expect(
+ buildCreateUsageLimitInput(
+ buildValues({ meter: 'quantity', limitValue: '2.5' }),
+ ),
+ ).toBeNull();
+ });
+
+ it('only keeps a spender id for a spender narrower than the workspace', () => {
+ expect(
+ buildCreateUsageLimitInput(
+ buildValues({ spenderType: 'userWorkspace', spenderId: ' user-1 ' }),
+ )?.spenderId,
+ ).toBe('user-1');
+ expect(
+ buildCreateUsageLimitInput(buildValues({ spenderId: 'ignored' }))
+ ?.spenderId,
+ ).toBeNull();
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildUsageLimitFormValues.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildUsageLimitFormValues.test.ts
new file mode 100644
index 00000000000..11302b6ed28
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildUsageLimitFormValues.test.ts
@@ -0,0 +1,59 @@
+import { buildUsageLimitFormValues } from '@/settings/billing/utils/buildUsageLimitFormValues';
+import { type UsageQuotaWithConsumption } from '@/settings/billing/types/UsageQuotaWithConsumption';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const buildItem = (
+ overrides: Partial<UsageQuotaWithConsumption> = {},
+): UsageQuotaWithConsumption => ({
+ __typename: 'UsageQuotaWithConsumption',
+ id: 'limit-1',
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.AI_CHAT_TOKEN,
+ spenderType: 'workspace',
+ spenderId: null,
+ spenderLabel: null,
+ periodUnit: 'month',
+ meter: 'creditsUsedMicro',
+ limitValue: 100_000_000,
+ isEnforced: true,
+ consumedValue: null,
+ remainingValue: null,
+ periodStart: null,
+ periodEnd: null,
+ ...overrides,
+});
+
+describe('buildUsageLimitFormValues', () => {
+ it('turns a credit quota back into whole credits', () => {
+ expect(buildUsageLimitFormValues(buildItem())).toEqual({
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.AI_CHAT_TOKEN,
+ spenderType: 'workspace',
+ spenderId: '',
+ meter: 'creditsUsedMicro',
+ periodUnit: 'month',
+ limitValue: '100',
+ });
+ });
+
+ it('keeps a quantity quota as it is stored and carries the spender id', () => {
+ expect(
+ buildUsageLimitFormValues(
+ buildItem({
+ meter: 'quantity',
+ limitValue: 200,
+ spenderType: 'userWorkspace',
+ spenderId: 'user-1',
+ }),
+ ),
+ ).toEqual(
+ expect.objectContaining({
+ limitValue: '200',
+ spenderId: 'user-1',
+ }),
+ );
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildUsageQuotaScopeInput.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildUsageQuotaScopeInput.test.ts
new file mode 100644
index 00000000000..3979a71f0b6
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/buildUsageQuotaScopeInput.test.ts
@@ -0,0 +1,59 @@
+import { EMPTY_USAGE_LIMIT_FORM_VALUES } from '@/settings/billing/constants/EmptyUsageLimitFormValues';
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { buildUsageQuotaScopeInput } from '@/settings/billing/utils/buildUsageQuotaScopeInput';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const buildValues = (
+ overrides: Partial<UsageLimitFormValues> = {},
+): UsageLimitFormValues => ({
+ ...EMPTY_USAGE_LIMIT_FORM_VALUES,
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.ALL,
+ spenderType: 'workspace',
+ meter: 'creditsUsedMicro',
+ periodUnit: 'month',
+ limitValue: '100',
+ ...overrides,
+});
+
+describe('buildUsageQuotaScopeInput', () => {
+ it('returns null while the scope is incomplete', () => {
+ expect(buildUsageQuotaScopeInput(EMPTY_USAGE_LIMIT_FORM_VALUES)).toBeNull();
+ expect(
+ buildUsageQuotaScopeInput(buildValues({ periodUnit: null })),
+ ).toBeNull();
+ });
+
+ it('builds the scope whatever the amount is worth', () => {
+ const scope = {
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.ALL,
+ spenderType: 'workspace',
+ spenderId: null,
+ meter: 'creditsUsedMicro',
+ periodUnit: 'month',
+ };
+
+ expect(buildUsageQuotaScopeInput(buildValues({ limitValue: '' }))).toEqual(
+ scope,
+ );
+ expect(buildUsageQuotaScopeInput(buildValues({ limitValue: '0' }))).toEqual(
+ scope,
+ );
+ });
+
+ it('only keeps a spender id for a spender narrower than the workspace', () => {
+ expect(
+ buildUsageQuotaScopeInput(
+ buildValues({ spenderType: 'userWorkspace', spenderId: ' user-1 ' }),
+ )?.spenderId,
+ ).toBe('user-1');
+ expect(
+ buildUsageQuotaScopeInput(buildValues({ spenderId: 'ignored' }))
+ ?.spenderId,
+ ).toBeNull();
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitFormOptions.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitFormOptions.test.ts
new file mode 100644
index 00000000000..2ec5c90c210
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitFormOptions.test.ts
@@ -0,0 +1,74 @@
+import { EMPTY_USAGE_LIMIT_FORM_VALUES } from '@/settings/billing/constants/EmptyUsageLimitFormValues';
+import { getUsageLimitFormOptions } from '@/settings/billing/utils/getUsageLimitFormOptions';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const DEFINITIONS = {
+ definitions: [
+ {
+ resourceType: UsageResourceType.AI,
+ allowedOperationTypes: [
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ],
+ allowedSpenderTypes: ['workspace', 'userWorkspace'],
+ allowedMeters: ['creditsUsedMicro', 'quantity'],
+ },
+ ],
+ isIntraWorkspaceLimitEntitled: true,
+ hasAllowancePeriod: false,
+};
+
+describe('getUsageLimitFormOptions', () => {
+ it('lists resources and nothing else until one is chosen', () => {
+ const options = getUsageLimitFormOptions({
+ definitions: DEFINITIONS,
+ values: EMPTY_USAGE_LIMIT_FORM_VALUES,
+ });
+
+ expect(options.resourceTypes).toEqual([UsageResourceType.AI]);
+ expect(options.operationTypes).toEqual([]);
+ expect(options.periodUnits).toEqual([]);
+ });
+
+ it('offers "all operations" to credit quotas and pins their meter', () => {
+ const options = getUsageLimitFormOptions({
+ definitions: DEFINITIONS,
+ values: {
+ ...EMPTY_USAGE_LIMIT_FORM_VALUES,
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.ALL,
+ },
+ });
+
+ expect(options.operationTypes).toEqual([
+ UsageOperationType.ALL,
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ]);
+ expect(options.meters).toEqual(['creditsUsedMicro']);
+ expect(options.spenderTypes).toEqual(['workspace', 'userWorkspace']);
+ expect(options.periodUnits).toEqual(['day', 'week', 'month']);
+ });
+
+ it('adds the billing period once the workspace has one', () => {
+ const options = getUsageLimitFormOptions({
+ definitions: { ...DEFINITIONS, hasAllowancePeriod: true },
+ values: {
+ ...EMPTY_USAGE_LIMIT_FORM_VALUES,
+ resourceType: UsageResourceType.AI,
+ operationType: UsageOperationType.WEB_SEARCH,
+ },
+ });
+
+ expect(options.periodUnits).toEqual([
+ 'day',
+ 'week',
+ 'month',
+ 'allowancePeriod',
+ ]);
+ expect(options.meters).toEqual(['creditsUsedMicro', 'quantity']);
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts
new file mode 100644
index 00000000000..c12cebf864f
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitOperationTypes.test.ts
@@ -0,0 +1,37 @@
+import { getUsageLimitOperationTypes } from '@/settings/billing/utils/getUsageLimitOperationTypes';
+import {
+ UsageOperationType,
+ UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+const buildDefinition = (allowedMeters: string[]) => ({
+ __typename: 'UsageQuotaDefinition' as const,
+ resourceType: UsageResourceType.AI,
+ allowedOperationTypes: [
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ],
+ allowedSpenderTypes: ['workspace'],
+ allowedMeters,
+});
+
+describe('getUsageLimitOperationTypes', () => {
+ it('offers "all operations" first when the resource is metered in credits', () => {
+ expect(
+ getUsageLimitOperationTypes(
+ buildDefinition(['creditsUsedMicro', 'quantity']),
+ ),
+ ).toEqual([
+ UsageOperationType.ALL,
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ]);
+ });
+
+ it('lists only the real operations without a credits meter', () => {
+ expect(getUsageLimitOperationTypes(buildDefinition(['quantity']))).toEqual([
+ UsageOperationType.AI_CHAT_TOKEN,
+ UsageOperationType.WEB_SEARCH,
+ ]);
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitSpenderGroups.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitSpenderGroups.test.ts
new file mode 100644
index 00000000000..2634e409176
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getUsageLimitSpenderGroups.test.ts
@@ -0,0 +1,29 @@
+import { getUsageLimitSpenderGroups } from '@/settings/billing/utils/getUsageLimitSpenderGroups';
+
+describe('getUsageLimitSpenderGroups', () => {
+ it('keeps the groups in menu order', () => {
+ const groups = getUsageLimitSpenderGroups([
+ 'apiKey',
+ 'workspace',
+ 'userWorkspace',
+ 'application',
+ ]);
+
+ expect(groups.map((group) => group.id)).toEqual([
+ 'workspace',
+ 'user',
+ 'application',
+ 'apiKey',
+ ]);
+ });
+
+ it('drops a group the resource does not accept', () => {
+ const groups = getUsageLimitSpenderGroups(['workspace', 'apiKey']);
+
+ expect(groups.map((group) => group.id)).toEqual(['workspace', 'apiKey']);
+ });
+
+ it('returns nothing when no spender is allowed', () => {
+ expect(getUsageLimitSpenderGroups([])).toEqual([]);
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/buildCreateUsageLimitInput.ts b/packages/twenty-front/src/modules/settings/billing/utils/buildCreateUsageLimitInput.ts
new file mode 100644
index 00000000000..f82b412ac0d
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/buildCreateUsageLimitInput.ts
@@ -0,0 +1,48 @@
+import { INTERNAL_CREDITS_PER_DISPLAY_CREDIT } from 'twenty-shared/constants';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { buildUsageQuotaScopeInput } from '@/settings/billing/utils/buildUsageQuotaScopeInput';
+import { type CreateUsageLimitInput } from '~/generated-metadata/graphql';
+
+const parsePositiveInteger = (value: string): number | null => {
+ const parsed = Number(value);
+
+ return Number.isInteger(parsed) && parsed >= 1 ? parsed : null;
+};
+
+const parsePositiveNumber = (value: string): number | null => {
+ const parsed = Number(value);
+
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
+};
+
+export const buildCreateUsageLimitInput = (
+ values: UsageLimitFormValues,
+): CreateUsageLimitInput | null => {
+ const scope = buildUsageQuotaScopeInput(values);
+
+ if (!isDefined(scope)) {
+ return null;
+ }
+
+ const isCreditsMeter = scope.meter === 'creditsUsedMicro';
+
+ const limitValue = isCreditsMeter
+ ? parsePositiveNumber(values.limitValue)
+ : parsePositiveInteger(values.limitValue);
+
+ if (!isDefined(limitValue)) {
+ return null;
+ }
+
+ return {
+ ...scope,
+ limitKind: 'quota',
+ periodCount: 1,
+ limitValue: isCreditsMeter
+ ? Math.round(limitValue * INTERNAL_CREDITS_PER_DISPLAY_CREDIT)
+ : limitValue,
+ burstValue: null,
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/buildUsageLimitFormValues.ts b/packages/twenty-front/src/modules/settings/billing/utils/buildUsageLimitFormValues.ts
new file mode 100644
index 00000000000..34dc4c36063
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/buildUsageLimitFormValues.ts
@@ -0,0 +1,37 @@
+import { INTERNAL_CREDITS_PER_DISPLAY_CREDIT } from 'twenty-shared/constants';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { type UsageQuotaWithConsumption } from '@/settings/billing/types/UsageQuotaWithConsumption';
+import { USAGE_LIMIT_METER_LABELS } from '@/settings/billing/constants/UsageLimitMeterLabels';
+import { USAGE_LIMIT_PERIOD_UNIT_LABELS } from '@/settings/billing/constants/UsageLimitPeriodUnitLabels';
+import { USAGE_LIMIT_SPENDER_TYPE_LABELS } from '@/settings/billing/constants/UsageLimitSpenderTypeLabels';
+import { isKeyOfRecord } from '@/settings/billing/utils/isKeyOfRecord';
+
+export const buildUsageLimitFormValues = (
+ item: UsageQuotaWithConsumption,
+): UsageLimitFormValues => {
+ const limitValue = Number(item.limitValue);
+
+ return {
+ resourceType: item.resourceType ?? null,
+ operationType: item.operationType,
+ spenderType: isKeyOfRecord(
+ USAGE_LIMIT_SPENDER_TYPE_LABELS,
+ item.spenderType,
+ )
+ ? item.spenderType
+ : null,
+ spenderId: item.spenderId ?? '',
+ meter: isKeyOfRecord(USAGE_LIMIT_METER_LABELS, item.meter)
+ ? item.meter
+ : null,
+ periodUnit: isKeyOfRecord(USAGE_LIMIT_PERIOD_UNIT_LABELS, item.periodUnit)
+ ? item.periodUnit
+ : null,
+ limitValue:
+ isDefined(item.meter) && item.meter === 'creditsUsedMicro'
+ ? String(limitValue / INTERNAL_CREDITS_PER_DISPLAY_CREDIT)
+ : String(limitValue),
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/buildUsageQuotaScopeInput.ts b/packages/twenty-front/src/modules/settings/billing/utils/buildUsageQuotaScopeInput.ts
new file mode 100644
index 00000000000..ef54c4d6016
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/buildUsageQuotaScopeInput.ts
@@ -0,0 +1,36 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { type UsageQuotaScopeInput } from '~/generated-metadata/graphql';
+
+export const buildUsageQuotaScopeInput = ({
+ resourceType,
+ operationType,
+ spenderType,
+ spenderId,
+ meter,
+ periodUnit,
+}: Omit<UsageLimitFormValues, 'limitValue'>): UsageQuotaScopeInput | null => {
+ if (
+ !isDefined(resourceType) ||
+ !isDefined(operationType) ||
+ !isDefined(spenderType) ||
+ !isDefined(meter) ||
+ !isDefined(periodUnit)
+ ) {
+ return null;
+ }
+
+ return {
+ resourceType,
+ operationType,
+ spenderType,
+ spenderId:
+ spenderType !== 'workspace' && isNonEmptyString(spenderId.trim())
+ ? spenderId.trim()
+ : null,
+ meter,
+ periodUnit,
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitFormOptions.ts b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitFormOptions.ts
new file mode 100644
index 00000000000..415994b2b74
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitFormOptions.ts
@@ -0,0 +1,80 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import { USAGE_LIMIT_METER_LABELS } from '@/settings/billing/constants/UsageLimitMeterLabels';
+import { USAGE_LIMIT_PERIOD_UNITS } from '@/settings/billing/constants/UsageLimitPeriodUnits';
+import { USAGE_LIMIT_SPENDER_TYPE_LABELS } from '@/settings/billing/constants/UsageLimitSpenderTypeLabels';
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { type UsageLimitMeter } from '@/settings/billing/types/UsageLimitMeter';
+import { type UsageLimitPeriodUnit } from '@/settings/billing/types/UsageLimitPeriodUnit';
+import { type UsageLimitSpenderType } from '@/settings/billing/types/UsageLimitSpenderType';
+import { getUsageLimitOperationTypes } from '@/settings/billing/utils/getUsageLimitOperationTypes';
+import { isKeyOfRecord } from '@/settings/billing/utils/isKeyOfRecord';
+import {
+ UsageOperationType,
+ type UsageQuotaDefinitionsQuery,
+ type UsageResourceType,
+} from '~/generated-metadata/graphql';
+
+type UsageLimitDefinitions =
+ UsageQuotaDefinitionsQuery['usageQuotaDefinitions'];
+
+type UsageLimitFormOptions = {
+ resourceTypes: UsageResourceType[];
+ operationTypes: UsageOperationType[];
+ spenderTypes: UsageLimitSpenderType[];
+ meters: UsageLimitMeter[];
+ periodUnits: UsageLimitPeriodUnit[];
+};
+
+export const getUsageLimitFormOptions = ({
+ definitions,
+ values,
+}: {
+ definitions: UsageLimitDefinitions;
+ values: UsageLimitFormValues;
+}): UsageLimitFormOptions => {
+ const resourceTypes = [
+ ...new Set(
+ definitions.definitions.map((definition) => definition.resourceType),
+ ),
+ ];
+
+ const definition = definitions.definitions.find(
+ (candidate) => candidate.resourceType === values.resourceType,
+ );
+
+ if (!isDefined(definition)) {
+ return {
+ resourceTypes,
+ operationTypes: [],
+ spenderTypes: [],
+ meters: [],
+ periodUnits: [],
+ };
+ }
+
+ const operationTypes = getUsageLimitOperationTypes(definition);
+
+ const meters = definition.allowedMeters
+ .filter((meter) => isKeyOfRecord(USAGE_LIMIT_METER_LABELS, meter))
+ .filter(
+ (meter) =>
+ values.operationType !== UsageOperationType.ALL ||
+ meter === 'creditsUsedMicro',
+ );
+
+ const periodUnits = USAGE_LIMIT_PERIOD_UNITS.filter(
+ (periodUnit) =>
+ periodUnit !== 'allowancePeriod' || definitions.hasAllowancePeriod,
+ );
+
+ return {
+ resourceTypes,
+ operationTypes,
+ spenderTypes: definition.allowedSpenderTypes.filter((spenderType) =>
+ isKeyOfRecord(USAGE_LIMIT_SPENDER_TYPE_LABELS, spenderType),
+ ),
+ meters,
+ periodUnits,
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts
new file mode 100644
index 00000000000..7198d5ccb18
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitOperationTypes.ts
@@ -0,0 +1,14 @@
+import {
+ UsageOperationType,
+ type UsageQuotaDefinitionsQuery,
+} from '~/generated-metadata/graphql';
+
+type UsageLimitDefinition =
+ UsageQuotaDefinitionsQuery['usageQuotaDefinitions']['definitions'][number];
+
+export const getUsageLimitOperationTypes = (
+ definition: UsageLimitDefinition,
+): UsageOperationType[] =>
+ definition.allowedMeters.includes('creditsUsedMicro')
+ ? [UsageOperationType.ALL, ...definition.allowedOperationTypes]
+ : definition.allowedOperationTypes;
diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitSpenderGroups.ts b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitSpenderGroups.ts
new file mode 100644
index 00000000000..b963d938289
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/utils/getUsageLimitSpenderGroups.ts
@@ -0,0 +1,11 @@
+import {
+ USAGE_LIMIT_SPENDER_GROUPS,
+ type UsageLimitSpenderGroup,
+} from '@/settings/billing/constants/UsageLimitSpenderGroups';
+
+export const getUsageLimitSpenderGroups = (
+ allowedSpenderTypes: string[],
+): UsageLimitSpenderGroup[] =>
+ USAGE_LIMIT_SPENDER_GROUPS.filter((group) =>
+ allowedSpenderTypes.includes(group.spenderType),
+ );
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsTableListSection.tsx b/packages/twenty-front/src/modules/settings/components/SettingsTableListSection.tsx
index 774ce1a744e..d717340616b 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsTableListSection.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsTableListSection.tsx
@@ -42,6 +42,9 @@ const StyledFooter = styled.div`
const HEADER_PADDING = `0 ${themeCssVariables.spacing[2]} 0 ${themeCssVariables.spacing[2]}`;
+// an auto track resolves differently in the header and in the rows, so the chevron column is fixed
+const CHEVRON_COLUMN_WIDTH = themeCssVariables.spacing[8];
+
export type SettingsTableListSectionColumn<Item> = {
label: string;
align?: 'left' | 'right';
@@ -79,7 +82,7 @@ export const SettingsTableListSection = <
onFooterButtonClick,
}: SettingsTableListSectionProps<Item>) => {
const resolvedGridAutoColumns = showRowChevron
- ? `${gridAutoColumns} auto`
+ ? `${gridAutoColumns} ${CHEVRON_COLUMN_WIDTH}`
: gridAutoColumns;
return (
diff --git a/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimitEdit.tsx b/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimitEdit.tsx
new file mode 100644
index 00000000000..fc58be0f558
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimitEdit.tsx
@@ -0,0 +1,32 @@
+import { useParams } from 'react-router-dom';
+import { isDefined } from 'twenty-shared/utils';
+
+import { SettingsBillingLimitEditForm } from '@/settings/billing/components/SettingsBillingLimitEditForm';
+import { useUsageQuotasWithConsumption } from '@/settings/billing/hooks/useUsageQuotasWithConsumption';
+import { NotFound } from '~/pages/not-found/NotFound';
+
+export const SettingsBillingLimitEdit = () => {
+ const { usageLimitId = '' } = useParams();
+ const { usageQuotasWithConsumption, loading } =
+ useUsageQuotasWithConsumption();
+
+ if (loading) {
+ return null;
+ }
+
+ const quota = usageQuotasWithConsumption.find(
+ (candidate) => candidate.id === usageLimitId,
+ );
+
+ if (!isDefined(quota)) {
+ return <NotFound />;
+ }
+
+ return (
+ <SettingsBillingLimitEditForm
+ key={usageLimitId}
+ usageLimitId={usageLimitId}
+ quota={quota}
+ />
+ );
+};
diff --git a/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimits.tsx b/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimits.tsx
index 0c9782a2e45..d7e3c344ff2 100644
--- a/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimits.tsx
+++ b/packages/twenty-front/src/pages/settings/billing/SettingsBillingLimits.tsx
@@ -1,8 +1,30 @@
+import { useLingui } from '@lingui/react/macro';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath } from 'twenty-shared/utils';
+import { IconPlus } from 'twenty-ui/icon';
+import { Button } from 'twenty-ui/input';
+import { UndecoratedLink } from 'twenty-ui/navigation';
+
import { SettingsBillingLimitsContent } from '@/settings/billing/components/SettingsBillingLimitsContent';
import { SettingsBillingPageLayout } from '@/settings/billing/components/SettingsBillingPageLayout';
-export const SettingsBillingLimits = () => (
- <SettingsBillingPageLayout>
- <SettingsBillingLimitsContent />
- </SettingsBillingPageLayout>
-);
+export const SettingsBillingLimits = () => {
+ const { t } = useLingui();
+
+ return (
+ <SettingsBillingPageLayout
+ actionButton={
+ <UndecoratedLink to={getSettingsPath(SettingsPath.BillingNewLimit)}>
+ <Button
+ Icon={IconPlus}
+ title={t`New limit`}
+ accent="blue"
+ size="small"
+ />
+ </UndecoratedLink>
+ }
+ >
+ <SettingsBillingLimitsContent />
+ </SettingsBillingPageLayout>
+ );
+};
diff --git a/packages/twenty-front/src/pages/settings/billing/SettingsBillingNewLimit.tsx b/packages/twenty-front/src/pages/settings/billing/SettingsBillingNewLimit.tsx
new file mode 100644
index 00000000000..6049a37e17b
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/billing/SettingsBillingNewLimit.tsx
@@ -0,0 +1,95 @@
+import { CombinedGraphQLErrors } from '@apollo/client/errors';
+import { Trans, useLingui } from '@lingui/react/macro';
+import { useState } from 'react';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath, isDefined } from 'twenty-shared/utils';
+
+import { SettingsBillingLimitForm } from '@/settings/billing/components/SettingsBillingLimitForm';
+import { EMPTY_USAGE_LIMIT_FORM_VALUES } from '@/settings/billing/constants/EmptyUsageLimitFormValues';
+import { useCreateUsageLimit } from '@/settings/billing/hooks/useCreateUsageLimit';
+import { useUsageQuotaDefinitions } from '@/settings/billing/hooks/useUsageQuotaDefinitions';
+import { useUsageQuotaScopeConsumption } from '@/settings/billing/hooks/useUsageQuotaScopeConsumption';
+import { type UsageLimitFormValues } from '@/settings/billing/types/UsageLimitFormValues';
+import { buildCreateUsageLimitInput } from '@/settings/billing/utils/buildCreateUsageLimitInput';
+import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
+import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
+import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
+import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
+import { useNavigateSettings } from '~/hooks/useNavigateSettings';
+
+export const SettingsBillingNewLimit = () => {
+ const { t } = useLingui();
+ const navigate = useNavigateSettings();
+ const { enqueueErrorSnackBar, enqueueSuccessSnackBar } = useSnackBar();
+ const { usageQuotaDefinitions, loading: definitionsLoading } =
+ useUsageQuotaDefinitions();
+ const { createUsageLimit, loading: isSaving } = useCreateUsageLimit();
+
+ const [values, setValues] = useState<UsageLimitFormValues>(
+ EMPTY_USAGE_LIMIT_FORM_VALUES,
+ );
+
+ const input = buildCreateUsageLimitInput(values);
+ const { scopeConsumption } = useUsageQuotaScopeConsumption(values);
+
+ const handleSave = async () => {
+ if (!isDefined(input)) {
+ return;
+ }
+
+ try {
+ await createUsageLimit({ variables: { input } });
+ enqueueSuccessSnackBar({ message: t`Limit created.` });
+ navigate(SettingsPath.BillingLimits);
+ } catch (error) {
+ const serverMessage =
+ error instanceof CombinedGraphQLErrors
+ ? error.errors[0]?.message
+ : undefined;
+
+ enqueueErrorSnackBar({
+ message: serverMessage ?? t`Failed to create the limit.`,
+ });
+ }
+ };
+
+ return (
+ <SettingsPageLayout
+ title={t`New limit`}
+ links={[
+ {
+ children: <Trans>Workspace</Trans>,
+ href: getSettingsPath(SettingsPath.General),
+ },
+ {
+ children: <Trans>Billing</Trans>,
+ href: getSettingsPath(SettingsPath.Billing),
+ },
+ {
+ children: <Trans>Limits</Trans>,
+ href: getSettingsPath(SettingsPath.BillingLimits),
+ },
+ { children: <Trans>New limit</Trans> },
+ ]}
+ actionButton={
+ <SaveAndCancelButtons
+ onSave={handleSave}
+ onCancel={() => navigate(SettingsPath.BillingLimits)}
+ isSaveDisabled={!isDefined(input)}
+ isLoading={isSaving}
+ />
+ }
+ >
+ <SettingsPageContainer>
+ {definitionsLoading || !isDefined(usageQuotaDefinitions) ? null : (
+ <SettingsBillingLimitForm
+ definitions={usageQuotaDefinitions}
+ values={values}
+ scopeConsumption={scopeConsumption}
+ onChange={setValues}
+ />
+ )}
+ </SettingsPageContainer>
+ </SettingsPageLayout>
+ );
+};
diff --git a/packages/twenty-shared/src/types/SettingsPath.ts b/packages/twenty-shared/src/types/SettingsPath.ts
index 0eaf318ddec..43b50cea4b0 100644
--- a/packages/twenty-shared/src/types/SettingsPath.ts
+++ b/packages/twenty-shared/src/types/SettingsPath.ts
@@ -14,6 +14,8 @@ export enum SettingsPath {
Usage = 'billing/usage',
UsageUserDetail = 'billing/usage/user/:userWorkspaceId',
BillingLimits = 'billing/limits',
+ BillingNewLimit = 'billing/limits/new',
+ BillingLimitEdit = 'billing/limits/:usageLimitId/edit',
Enterprise = 'enterprise',
Objects = 'objects',
ObjectOverview = 'objects/overview',