1 import { differenceInDays, startOfDay } from 'date-fns';
7 } from '@proton/components/containers/desktop/freeTrial/constants';
8 import type { InboxDesktopFreeTrialReminders } from '@proton/shared/lib/desktop/desktopTypes';
10 export const shouldDisplay = (
12 differenceToTest: number,
14 alreadyDisplayed?: boolean
16 const endDate = new Date(expirationDay);
17 const daysDifference = differenceInDays(endDate, today);
18 return daysDifference === differenceToTest && !alreadyDisplayed;
21 export const shouldDisplayReminder = (trialEndDate: Date, remindFlag: InboxDesktopFreeTrialReminders) => {
22 const startOfToday = startOfDay(new Date());
24 const firstReminder = shouldDisplay(startOfToday, FIRST_REMINDER_DAYS, trialEndDate, remindFlag?.first);
25 const secondReminder = shouldDisplay(startOfToday, SECOND_REMINDER_DAYS, trialEndDate, remindFlag?.second);
26 const thirdReminder = shouldDisplay(startOfToday, THIRD_REMINDER_DAYS, trialEndDate, remindFlag?.third);
28 return firstReminder || secondReminder || thirdReminder;