The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { type BillingPlanSwitches } from '@/settings/billing/types/BillingPlanSwitches';
import { type BillingSubscriptionChange } from '@/settings/billing/types/BillingSubscriptionChange';
import { assertUnreachable } from 'twenty-shared/utils';
import {
SubscriptionInterval,
SubscriptionStatus,
} from '~/generated-metadata/graphql';
export const isBillingSubscriptionChangeImmediate = ({
change,
currentPlan,
subscriptionStatus,
}: {
change: BillingSubscriptionChange;
currentPlan: BillingPlanSwitches;
subscriptionStatus: SubscriptionStatus | undefined;
}) => {
if (subscriptionStatus === SubscriptionStatus.Trialing) {
return true;
}
switch (change.type) {
case 'SWITCH_PLAN':
return !currentPlan.downgradePlanKeys.includes(change.targetPlanKey);
case 'SWITCH_INTERVAL':
return change.targetInterval === SubscriptionInterval.Year;
case 'CANCEL_PLAN_SWITCH':
case 'CANCEL_INTERVAL_SWITCH':
return true;
default:
return assertUnreachable(change);
}
};