mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
53354224fc
Upgrades biome to 1.6.1, and updates husky pre-commit hook. Most changes here are making type imports explicit.
63 lines
1.6 KiB
TypeScript
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,
|
|
);
|
|
};
|