1 import { PLANS } from '@proton/payments';
2 import { getAppFromPathnameSafe } from '@proton/shared/lib/apps/slugHelper';
3 import { APPS } from '@proton/shared/lib/constants';
4 import { isManagedExternally } from '@proton/shared/lib/helpers/subscription';
5 import type { ProtonConfig, Subscription, UserModel } from '@proton/shared/lib/interfaces';
8 subscription?: Subscription;
10 protonConfig: ProtonConfig;
13 const isEligible = ({ subscription, user, protonConfig }: Props): boolean => {
14 const parentApp = getAppFromPathnameSafe(window.location.pathname);
15 const hasValidApp = protonConfig.APP_NAME === APPS.PROTONACCOUNT && parentApp === APPS.PROTONPASS;
17 const { canPay, isDelinquent, isFree } = user;
18 const notDelinquent = !isDelinquent;
19 const isNotExternal = !isManagedExternally(subscription);
20 const cohortPass2023 = subscription?.Plans?.some((plan) => plan.Name === PLANS.PASS) ?? false;
22 return hasValidApp && canPay && notDelinquent && isNotExternal && (isFree || cohortPass2023);
25 export default isEligible;