1 import type { OpenCallbackProps } from '@proton/components/containers/payments/subscription/SubscriptionModalProvider';
2 import { SUBSCRIPTION_STEPS } from '@proton/components/containers/payments/subscription/constants';
3 import type { SelectedPlan } from '@proton/payments';
4 import { type ADDON_NAMES, type PLANS, type PlanIDs, getScribeAddonNameByPlan } from '@proton/payments';
5 import { CYCLE } from '@proton/shared/lib/constants';
6 import { isScribeAddon, removeAddon } from '@proton/shared/lib/helpers/addons';
7 import type { UserModel } from '@proton/shared/lib/interfaces';
9 const getUpgradeCycles = (currentCycle = CYCLE.MONTHLY) => ({
11 minimumCycle: currentCycle,
12 maximumCycle: currentCycle === CYCLE.MONTHLY ? CYCLE.YEARLY : currentCycle,
15 const paidSingleUserUpsellConfig = (
18 addonName: ADDON_NAMES | undefined,
20 ): OpenCallbackProps => {
21 const cycles = getUpgradeCycles(cycle);
23 const planIDs: PlanIDs = {
28 planIDs[addonName] = 1;
34 step: SUBSCRIPTION_STEPS.CHECKOUT,
35 disablePlanSelection: true,
44 const paidMultipleUserUpsellConfig = (
46 addonName: ADDON_NAMES | undefined,
47 selectedPlan: SelectedPlan
48 ): OpenCallbackProps => {
49 const cycles = getUpgradeCycles(selectedPlan.cycle);
51 // if we already have scribe addons, then we will use the current number of scribes as starting addon number
53 // if we don't, then we will use the number of members as starting number for scribe addons
54 const addonsValue = selectedPlan.getTotalScribes() || selectedPlan.getTotalMembers();
56 const planIDs: PlanIDs = {
57 ...selectedPlan.planIDs,
60 planIDs[addonName] = addonsValue;
66 step: SUBSCRIPTION_STEPS.CHECKOUT,
67 disablePlanSelection: true,
76 export const getAssistantUpsellConfig = (
80 selectedPlan: SelectedPlan
81 ): OpenCallbackProps | undefined => {
87 const addonName = getScribeAddonNameByPlan(selectedPlan.name);
88 return paidMultipleUserUpsellConfig(upsellRef, addonName, selectedPlan);
92 const addonName = getScribeAddonNameByPlan(selectedPlan.name);
93 return paidSingleUserUpsellConfig(upsellRef, selectedPlan.name, addonName, selectedPlan.cycle);
99 export const getAssistantDowngradeConfig = (
101 selectedPlan: SelectedPlan
102 ): OpenCallbackProps | undefined => {
104 mode: 'upsell-modal',
106 * Removes only Scribe addons and keep all others
108 planIDs: removeAddon(selectedPlan.planIDs, isScribeAddon),
109 step: SUBSCRIPTION_STEPS.CHECKOUT,
110 disablePlanSelection: true,
111 cycle: selectedPlan.cycle,
112 maximumCycle: selectedPlan.cycle,
113 minimumCycle: selectedPlan.cycle,