fix(billing): adapt current phase to current period (#15321)

Fix https://github.com/twentyhq/core-team-issues/issues/1748
This commit is contained in:
Antoine Moreaux
2025-10-24 15:44:08 +02:00
committed by GitHub
parent f65c4e4be9
commit 5442e9fc37
4 changed files with 27 additions and 105 deletions
@@ -4,11 +4,7 @@ import {
SubscriptionInterval,
SubscriptionStatus,
} from '~/generated-metadata/graphql';
import {
assertIsDefinedOrThrow,
capitalize,
isDefined,
} from 'twenty-shared/utils';
import { assertIsDefinedOrThrow, capitalize } from 'twenty-shared/utils';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';
import { useLingui } from '@lingui/react/macro';
@@ -52,18 +48,14 @@ export const useBillingWording = () => {
: t`year`;
const getBeautifiedRenewDate = () => {
const endDateFromPhase = currentBillingSubscription.phases?.[0]?.end_date;
const renewData = endDateFromPhase
? endDateFromPhase * 1000
: currentBillingSubscription.currentPeriodEnd
? new Date(currentBillingSubscription.currentPeriodEnd)
: undefined;
assertIsDefinedOrThrow(
currentBillingSubscription.currentPeriodEnd,
new Error(`No renew date defined for current subscription.`),
);
if (!isDefined(renewData)) {
throw new Error(`No renew date defined for current subscription.`);
}
return beautifyExactDate(renewData);
return beautifyExactDate(
new Date(currentBillingSubscription.currentPeriodEnd),
);
};
const getIntervalLabelAsAdjectiveCapitalize = (isMonthlyPlan: boolean) => {