1 import { addDays, fromUnixTime, isBefore } from 'date-fns';
3 import { PLANS } from '@proton/payments';
4 import { APPS } from '@proton/shared/lib/constants';
5 import { getPlan, isManagedExternally, isTrial } from '@proton/shared/lib/helpers/subscription';
6 import type { ProtonConfig, Subscription, UserModel } from '@proton/shared/lib/interfaces';
10 subscription?: Subscription;
11 protonConfig: ProtonConfig;
14 const isEligible = ({ user, subscription, protonConfig }: Props) => {
15 const isValidApp = protonConfig?.APP_NAME === APPS.PROTONMAIL || protonConfig?.APP_NAME === APPS.PROTONACCOUNT;
16 const createDate = subscription?.CreateTime ? fromUnixTime(subscription.CreateTime) : new Date();
17 const plan = getPlan(subscription);
19 [PLANS.MAIL, PLANS.VPN].includes(plan?.Name as PLANS) &&
20 !isTrial(subscription) &&
21 isBefore(createDate, addDays(new Date(), -7)) &&
25 !isManagedExternally(subscription)
29 export default isEligible;