1 import { differenceInDays, fromUnixTime } from 'date-fns';
3 import { domIsBusy } from '@proton/shared/lib/busy';
4 import { APPS } from '@proton/shared/lib/constants';
5 import type { ProtonConfig, UserModel } from '@proton/shared/lib/interfaces';
9 protonConfig: ProtonConfig;
10 lastReminderTimestamp?: number;
14 const ACCOUNT_AGE_DAY_THESHOLD = 14;
15 const REMINDER_INTERVAL_DAYS = 90;
17 const isEligible = ({ user, protonConfig, lastReminderTimestamp, isVisited }: Props) => {
18 const { isFree, isDelinquent, CreateTime } = user;
19 const isNotDelinquent = !isDelinquent;
20 const hasValidApp = protonConfig.APP_NAME === APPS.PROTONMAIL;
22 const today = new Date();
23 const daysSinceAccountCreation = differenceInDays(today, fromUnixTime(CreateTime));
24 const lastReminderDate = lastReminderTimestamp ? fromUnixTime(lastReminderTimestamp) : daysSinceAccountCreation;
25 const daysSinceLastReminder = differenceInDays(today, lastReminderDate);
27 // We display the reminder every 90 days (three month)
28 const displaySixMonthReminder =
29 daysSinceAccountCreation >= REMINDER_INTERVAL_DAYS && daysSinceLastReminder >= REMINDER_INTERVAL_DAYS;
30 // We display the initial reminder after 14 days if the user hasn't seend the offer yet
31 const isAccountOlderThanInitialTheshold = !isVisited && daysSinceAccountCreation >= ACCOUNT_AGE_DAY_THESHOLD;
33 const isDomBusy = domIsBusy();
39 (isAccountOlderThanInitialTheshold || displaySixMonthReminder) &&
44 export default isEligible;