1 import type { APP_NAMES, UPSELL_COMPONENT } from '@proton/shared/lib/constants';
2 import { APPS, APP_UPSELL_REF_PATH, PLANS } from '@proton/shared/lib/constants';
3 import { getPlan } from '@proton/shared/lib/helpers/subscription';
4 import type { Audience, Subscription, UserModel } from '@proton/shared/lib/interfaces';
7 * Add an upsell ref param to a URL
9 export const addUpsellPath = (link: string, upsellPath?: string) => {
14 const hasParams = link.includes('?');
15 return hasParams ? `${link}&ref=${upsellPath}` : `${link}?ref=${upsellPath}`;
18 export const getUpgradePath = ({
28 subscription?: Subscription;
31 target?: 'compare' | 'checkout';
33 const params = new URLSearchParams();
35 params.set('plan', plan);
38 params.set('audience', audience);
40 if (!user || user.isFree) {
41 if (app === APPS.PROTONVPN_SETTINGS) {
42 return `/dashboard${params.size ? `?${params}` : ''}`;
44 return `/upgrade${params.size ? `?${params}` : ''}`;
46 const currentPlan = getPlan(subscription);
47 // A plan is needed to open the subscription modal
48 if (!params.has('plan')) {
49 params.set('plan', currentPlan?.Name ?? PLANS.BUNDLE);
51 params.set('target', target ?? 'compare');
52 return `/dashboard?${params}`;
56 * Generate upsell ref from app component and feature
58 * @param app => Current app from which we open a link
59 * @param feature => feature identifier to include in the path
60 * @param component => Optional, ref component (e.g. banner, modal, button)
62 export const getUpsellRef = ({
68 app: APP_UPSELL_REF_PATH;
70 component?: UPSELL_COMPONENT;
73 const upsellComponent = component || '';
74 const upsellInSettings = isSettings ? '_settings' : '';
76 return `${app}${upsellComponent}${feature}${upsellInSettings}`;
80 * Generate upsell ref from the current app, the "feature" identifier, the "component" and the "from app"
82 * @param app => Current app from which we open a link
83 * @param feature => feature identifier to include in the path
84 * @param component => Optional, ref component (e.g. banner, modal, button)
85 * @param fromApp => Optional, "parent app" of the current app (e.g. in mail settings, app=account and fromApp=mail)
87 * Return a ref string like "upsell_mail-banner-auto-reply_settings"
89 export const getUpsellRefFromApp = ({
97 component?: UPSELL_COMPONENT;
100 if (app === APPS.PROTONMAIL) {
101 return getUpsellRef({ app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH, feature, component });
102 } else if (app === APPS.PROTONCALENDAR) {
103 return getUpsellRef({ app: APP_UPSELL_REF_PATH.CALENDAR_UPSELL_REF_PATH, feature, component });
104 } else if (app === APPS.PROTONDRIVE) {
105 return getUpsellRef({ app: APP_UPSELL_REF_PATH.DRIVE_UPSELL_REF_PATH, feature, component });
106 } else if (app === APPS.PROTONACCOUNT && fromApp) {
107 if (fromApp === APPS.PROTONMAIL) {
108 return getUpsellRef({
109 app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH,
114 } else if (fromApp === APPS.PROTONCALENDAR) {
115 return getUpsellRef({
116 app: APP_UPSELL_REF_PATH.CALENDAR_UPSELL_REF_PATH,
121 } else if (fromApp === APPS.PROTONDRIVE) {
122 return getUpsellRef({
123 app: APP_UPSELL_REF_PATH.DRIVE_UPSELL_REF_PATH,
128 } else if (fromApp === APPS.PROTONPASS) {
129 return getUpsellRef({
130 app: APP_UPSELL_REF_PATH.PASS_UPSELL_REF_PATH,
135 } else if (fromApp === APPS.PROTONVPN_SETTINGS) {
136 return getUpsellRef({ app: APP_UPSELL_REF_PATH.VPN_UPSELL_REF_PATH, feature, component, isSettings: true });