1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/frontend/src/utils/instanceTrial.ts
Christopher Kolstad 53354224fc
chore: Bump biome and configure husky (#6589)
Upgrades biome to 1.6.1, and updates husky pre-commit hook.

Most changes here are making type imports explicit.
2024-03-18 13:58:05 +01:00

63 lines
1.6 KiB
TypeScript

import { parseISO, isPast } from 'date-fns';
import { type IInstanceStatus, InstanceState } from 'interfaces/instance';
import differenceInDays from 'date-fns/differenceInDays';
const TRIAL_EXPIRES_SOON_DAYS_THRESHOLD = 10;
export const isTrialInstance = (
instanceStatus: IInstanceStatus | undefined,
): boolean => {
return (
instanceStatus?.state === InstanceState.TRIAL ||
instanceStatus?.state === InstanceState.EXPIRED ||
instanceStatus?.state === InstanceState.CHURNED
);
};
export const trialHasExpired = (
instanceStatus: IInstanceStatus | undefined,
): boolean => {
if (
instanceStatus?.state === InstanceState.EXPIRED ||
instanceStatus?.state === InstanceState.CHURNED
) {
return true;
}
if (
instanceStatus?.state === InstanceState.TRIAL &&
instanceStatus?.trialExpiry
) {
return isPast(parseISO(instanceStatus.trialExpiry));
}
return false;
};
export const trialExpiresSoon = (
instanceStatus: IInstanceStatus | undefined,
) => {
if (
!instanceStatus ||
instanceStatus.state !== InstanceState.TRIAL ||
!instanceStatus.trialExpiry
) {
return false;
}
return (
differenceInDays(parseISO(instanceStatus.trialExpiry), new Date()) <=
TRIAL_EXPIRES_SOON_DAYS_THRESHOLD
);
};
export const canExtendTrial = (
instanceStatus: IInstanceStatus | undefined,
): boolean => {
return Boolean(
instanceStatus &&
instanceStatus.state === InstanceState.EXPIRED &&
!instanceStatus.trialExtended,
);
};