301 lines
11 KiB
TypeScript
301 lines
11 KiB
TypeScript
import { createVaP24aInterimFixtureViewModel } from "@hivegrid/ui-mock";
|
|
import {
|
|
buildSelfServiceSubscriptionPricePreviewVM,
|
|
type SelfServiceCheckoutPaymentMethodsVM,
|
|
type SelfServiceSubscriptionPageVM,
|
|
} from "@hivegrid/view-models";
|
|
|
|
import {
|
|
SelfServiceSubscriptionPage,
|
|
type SelfServiceSubscriptionActions,
|
|
type SelfServiceSubscriptionPlanAdvice,
|
|
type SelfServiceSubscriptionSelection,
|
|
} from "./SelfServiceSubscriptionPage";
|
|
|
|
const noOp = (): void => undefined;
|
|
|
|
/** Shared ready-state fixture for VA-P24a markup and Chromium baselines. */
|
|
export function VaP24aInterimVisualFixture({
|
|
onCheckout = noOp,
|
|
onPlanAdvice,
|
|
onPreview,
|
|
onEmailMarketingPreview,
|
|
onEmailMarketingCheckout = noOp,
|
|
activationMode = false,
|
|
activationTrialDays,
|
|
embedded = false,
|
|
canonicalPlans = false,
|
|
previewPaymentMethods,
|
|
initialEmailMarketingAddOnCode,
|
|
emptyCatalog = false,
|
|
onRetry = noOp,
|
|
}: {
|
|
onCheckout?: SelfServiceSubscriptionActions["onCheckout"];
|
|
onPlanAdvice?: SelfServiceSubscriptionActions["onPlanAdvice"];
|
|
onPreview?: SelfServiceSubscriptionActions["onPreview"];
|
|
onEmailMarketingPreview?: SelfServiceSubscriptionActions["onEmailMarketingPreview"];
|
|
onEmailMarketingCheckout?: SelfServiceSubscriptionActions["onEmailMarketingCheckout"];
|
|
activationMode?: boolean;
|
|
activationTrialDays?: number;
|
|
embedded?: boolean;
|
|
canonicalPlans?: boolean;
|
|
previewPaymentMethods?: SelfServiceCheckoutPaymentMethodsVM;
|
|
initialEmailMarketingAddOnCode?: string | null;
|
|
emptyCatalog?: boolean;
|
|
onRetry?: SelfServiceSubscriptionActions["onRetry"];
|
|
} = {}): React.JSX.Element {
|
|
const readyVm = createVaP24aInterimFixtureViewModel();
|
|
const [starterFixture, businessFixture] = readyVm.catalog.plans;
|
|
const fixtureTrialDays = activationTrialDays ?? 14;
|
|
const activationCatalog: SelfServiceSubscriptionPageVM["catalog"] = {
|
|
plans:
|
|
starterFixture && businessFixture
|
|
? [
|
|
{
|
|
...starterFixture,
|
|
id: "plan-core",
|
|
code: "core",
|
|
titleKey: "settings.subscription.checkout.plans.packages.starter.title",
|
|
descriptionKey: "settings.subscription.checkout.plans.packages.starter.description",
|
|
badge: "billing:selfServiceSubscription.fixture.business.badge",
|
|
packageTerms: {
|
|
packageId: "starter",
|
|
monthlyCents: 19_900,
|
|
annualSepaMonthlyEquivalentCents: 17_900,
|
|
officeSeatsIncluded: 2,
|
|
fieldSeatsIncluded: 5,
|
|
storageIncludedGb: 100,
|
|
storagePerAdditionalSeatGb: 10,
|
|
officeExtraMonthlyCents: 5_900,
|
|
fieldExtraMonthlyCents: 2_500,
|
|
officeExtraAnnualSepaCents: 5_310,
|
|
fieldExtraAnnualSepaCents: 2_250,
|
|
},
|
|
prices: starterFixture.prices.map((price, index) => ({
|
|
...price,
|
|
id: index === 0 ? "price-core-monthly" : "price-core-annual",
|
|
unitAmountCents: 19_900,
|
|
trialDays: fixtureTrialDays,
|
|
})),
|
|
},
|
|
{
|
|
...businessFixture,
|
|
id: "plan-swarm",
|
|
code: "swarm",
|
|
titleKey: "settings.subscription.checkout.plans.packages.team.title",
|
|
descriptionKey: "settings.subscription.checkout.plans.packages.team.description",
|
|
badge: null,
|
|
packageTerms: {
|
|
packageId: "team",
|
|
monthlyCents: 49_900,
|
|
annualSepaMonthlyEquivalentCents: 44_900,
|
|
officeSeatsIncluded: 5,
|
|
fieldSeatsIncluded: 15,
|
|
storageIncludedGb: 500,
|
|
storagePerAdditionalSeatGb: 20,
|
|
officeExtraMonthlyCents: 3_900,
|
|
fieldExtraMonthlyCents: 1_900,
|
|
officeExtraAnnualSepaCents: 3_510,
|
|
fieldExtraAnnualSepaCents: 1_710,
|
|
},
|
|
prices: businessFixture.prices.map((price, index) => ({
|
|
...price,
|
|
id: index === 0 ? "price-swarm-monthly" : "price-swarm-annual",
|
|
unitAmountCents: 49_900,
|
|
trialDays: fixtureTrialDays,
|
|
})),
|
|
},
|
|
{
|
|
...businessFixture,
|
|
id: "plan-colony",
|
|
code: "colony",
|
|
titleKey: "settings.subscription.checkout.plans.packages.business.title",
|
|
descriptionKey: "settings.subscription.checkout.plans.packages.business.description",
|
|
badge: null,
|
|
packageTerms: {
|
|
packageId: "business",
|
|
monthlyCents: 99_900,
|
|
annualSepaMonthlyEquivalentCents: 89_900,
|
|
officeSeatsIncluded: 10,
|
|
fieldSeatsIncluded: 30,
|
|
storageIncludedGb: 2_000,
|
|
storagePerAdditionalSeatGb: 40,
|
|
officeExtraMonthlyCents: 3_500,
|
|
fieldExtraMonthlyCents: 1_500,
|
|
officeExtraAnnualSepaCents: 3_150,
|
|
fieldExtraAnnualSepaCents: 1_350,
|
|
},
|
|
prices: businessFixture.prices.map((price, index) => ({
|
|
...price,
|
|
id: index === 0 ? "price-colony-monthly" : "price-colony-annual",
|
|
unitAmountCents: 99_900,
|
|
trialDays: fixtureTrialDays,
|
|
})),
|
|
},
|
|
]
|
|
: readyVm.catalog.plans,
|
|
};
|
|
let vm: SelfServiceSubscriptionPageVM = activationMode
|
|
? {
|
|
...readyVm,
|
|
catalog: activationCatalog,
|
|
overview: { status: "empty" },
|
|
currentSelection: null,
|
|
minimumSeatQuantity: 1,
|
|
minimumSeatQuantities: { office: 1, field: 0 },
|
|
preferredSelection: {
|
|
planId: "plan-core",
|
|
priceId: "price-core-monthly",
|
|
officeSeatQuantity: 2,
|
|
fieldSeatQuantity: 5,
|
|
},
|
|
storageAddOns: [
|
|
{ code: "storage_500gb", title: "Cloud-Speicher Plus · 500 GB", storageGb: 500, amountCents: 699, currency: "EUR" },
|
|
{ code: "storage_1tb", title: "Cloud-Speicher Plus · 1 TB", storageGb: 1_000, amountCents: 1_299, currency: "EUR" },
|
|
{ code: "storage_5tb", title: "Cloud-Speicher Plus · 5 TB", storageGb: 5_000, amountCents: 6_099, currency: "EUR" },
|
|
],
|
|
emailMarketingAddOns: readyVm.emailMarketingAddOns.map((addOn) => ({ ...addOn, active: false })),
|
|
usage: null,
|
|
}
|
|
: canonicalPlans
|
|
? {
|
|
...readyVm,
|
|
catalog: activationCatalog,
|
|
currentSelection: readyVm.currentSelection
|
|
? {
|
|
...readyVm.currentSelection,
|
|
planId: "plan-core",
|
|
priceId: "price-core-monthly",
|
|
planCode: "core",
|
|
}
|
|
: null,
|
|
storageAddOns: [
|
|
{ code: "storage_500gb", title: "Cloud-Speicher Plus · 500 GB", storageGb: 500, amountCents: 699, currency: "EUR" },
|
|
{ code: "storage_1tb", title: "Cloud-Speicher Plus · 1 TB", storageGb: 1_000, amountCents: 1_299, currency: "EUR" },
|
|
{ code: "storage_5tb", title: "Cloud-Speicher Plus · 5 TB", storageGb: 5_000, amountCents: 6_099, currency: "EUR" },
|
|
],
|
|
overview:
|
|
readyVm.overview.status === "ready"
|
|
? {
|
|
status: "ready",
|
|
data: {
|
|
...readyVm.overview.data,
|
|
planCode: "core",
|
|
},
|
|
}
|
|
: readyVm.overview,
|
|
}
|
|
: readyVm;
|
|
if (emptyCatalog) vm = { ...vm, catalog: { plans: [] }, preferredSelection: null };
|
|
|
|
const fixturePlanAdvice = ({
|
|
officeSeatQuantity,
|
|
fieldSeatQuantity,
|
|
}: {
|
|
officeSeatQuantity: number;
|
|
fieldSeatQuantity: number;
|
|
}): SelfServiceSubscriptionPlanAdvice => {
|
|
const plans = vm.catalog.plans.flatMap((plan) => {
|
|
const price = plan.prices.find((candidate) => candidate.billingPeriod === 3);
|
|
return price
|
|
? [
|
|
{
|
|
planId: plan.id,
|
|
priceId: price.id,
|
|
amountCents: price.unitAmountCents,
|
|
currency: price.currency,
|
|
billingPeriod: price.billingPeriod,
|
|
recommended: plan === vm.catalog.plans[0],
|
|
},
|
|
]
|
|
: [];
|
|
});
|
|
const recommended = plans.find((plan) => plan.recommended);
|
|
if (!recommended) throw new Error("Visual fixture has no monthly plan recommendation");
|
|
return {
|
|
plans,
|
|
selectedPriceId: recommended.priceId,
|
|
recommendedPriceId: recommended.priceId,
|
|
officeSeatQuantity,
|
|
fieldSeatQuantity,
|
|
};
|
|
};
|
|
const initialPlanAdvice =
|
|
activationMode && vm.catalog.plans.length > 0
|
|
? fixturePlanAdvice({
|
|
officeSeatQuantity: vm.preferredSelection?.officeSeatQuantity ?? vm.minimumSeatQuantities.office,
|
|
fieldSeatQuantity: vm.preferredSelection?.fieldSeatQuantity ?? vm.minimumSeatQuantities.field,
|
|
})
|
|
: null;
|
|
|
|
const actions: SelfServiceSubscriptionActions = {
|
|
onPlanAdvice: onPlanAdvice ?? (async (seatQuantities) => fixturePlanAdvice(seatQuantities)),
|
|
onPreview:
|
|
onPreview ??
|
|
((selection: SelfServiceSubscriptionSelection) => {
|
|
const selectedPlan = vm.catalog.plans.find((plan) => plan.id === selection.productId);
|
|
const selectedPrice = selectedPlan?.prices.find((price) => price.id === selection.priceId);
|
|
const currentPlanCode = vm.overview.status === "ready" ? vm.overview.data.planCode : null;
|
|
const currentPlan = vm.catalog.plans.find((plan) => plan.code === currentPlanCode) ?? null;
|
|
const currentPrice = currentPlan?.prices.find((price) => price.id === vm.currentSelection?.priceId) ?? null;
|
|
if (!selectedPlan || !selectedPrice) return Promise.reject(new Error("Visual fixture selection is not in the catalog"));
|
|
|
|
return Promise.resolve({
|
|
preview: buildSelfServiceSubscriptionPricePreviewVM({
|
|
currentPlan,
|
|
currentPrice,
|
|
currentSeatQuantity: 3,
|
|
currentPeriodEnd: "2026-08-15T00:00:00.000Z",
|
|
selectedPlan,
|
|
selectedPrice,
|
|
selectedSeatQuantity: Math.max(1, selection.officeSeatQuantity + selection.fieldSeatQuantity),
|
|
selectedOfficeSeatQuantity: selection.officeSeatQuantity,
|
|
selectedFieldSeatQuantity: selection.fieldSeatQuantity,
|
|
selectedStorageAddOnCodes: selection.storageAddOnCodes,
|
|
vatRateBasisPoints: 1_900,
|
|
policy: vm.managementPolicy,
|
|
}),
|
|
paymentMethods:
|
|
previewPaymentMethods ??
|
|
({
|
|
status: "ready",
|
|
methods: [
|
|
{ id: "ideal", label: "iDEAL" },
|
|
{ id: "creditcard", label: "Kreditkarte" },
|
|
],
|
|
} as const),
|
|
});
|
|
}),
|
|
onCheckout,
|
|
onCancel: noOp,
|
|
onEmailMarketingPreview:
|
|
onEmailMarketingPreview ??
|
|
((addOn) =>
|
|
Promise.resolve({
|
|
addOn,
|
|
paymentMethods: {
|
|
status: "ready",
|
|
methods: [
|
|
{ id: "ideal", label: "iDEAL" },
|
|
{ id: "creditcard", label: "Kreditkarte" },
|
|
],
|
|
},
|
|
})),
|
|
onEmailMarketingCheckout,
|
|
onOpenBilling: noOp,
|
|
onOpenCustomerPortal: noOp,
|
|
onRetry,
|
|
};
|
|
|
|
return (
|
|
<SelfServiceSubscriptionPage
|
|
vm={vm}
|
|
actions={actions}
|
|
activationMode={activationMode}
|
|
initialPlanAdvice={initialPlanAdvice}
|
|
embedded={embedded}
|
|
initialEmailMarketingAddOnCode={initialEmailMarketingAddOnCode}
|
|
/>
|
|
);
|
|
}
|