1 import { useAuthStore } from '@proton/pass//components/Core/AuthStoreProvider';
2 import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider';
3 import { SAFARI_URL_SCHEME, type UpsellRef, UpsellRefPrefix } from '@proton/pass/constants';
5 /** Prefer navigating to signup from extension/desktop
6 * as we cannot guarantee the session exists */
7 export const PASS_UPGRADE_PATH = EXTENSION_BUILD || DESKTOP_BUILD ? 'pass/signup' : 'pass/dashboard';
9 /** `pathRef` will be passed to the upgrade link */
10 export const useNavigateToUpgrade = (options: {
16 upsellRef?: UpsellRef;
19 const { onLink, config, endpoint } = usePassCore();
20 const authStore = useAuthStore();
21 const searchParams = new URLSearchParams();
23 const refPrefix: UpsellRefPrefix = (() => {
26 return UpsellRefPrefix.Desktop;
28 return UpsellRefPrefix.Web;
30 return UpsellRefPrefix.Extension;
34 if (options.coupon) searchParams.append('coupon', options.coupon);
35 if (options.cycle) searchParams.append('cycle', options.cycle);
36 if (options.email) searchParams.append('email', options.email);
37 if (options.offer) searchParams.append('offer', 'true');
38 if (options.plan) searchParams.append('plan', options.plan);
39 if (options.upsellRef) searchParams.append('ref', `${refPrefix}_${options.upsellRef}`);
42 const localID = authStore?.getLocalID();
43 if (localID !== undefined) searchParams.append('u', localID.toString());
47 BUILD_TARGET === 'safari'
48 ? `${SAFARI_URL_SCHEME}//upgrade?${searchParams.toString()}`
49 : `${config.SSO_URL}/${options.path ?? PASS_UPGRADE_PATH}?${searchParams.toString()}`;
51 return () => onLink(upgradeHref, { replace: true });