Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / components / containers / offers / operations / passFamilyPlan2024Yearly / eligibility.ts
blob478a28d963266cc372f96483c7fe2dd53655aa55
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';
7 interface Props {
8     subscription?: Subscription;
9     user: UserModel;
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;