Polish native cloud plans and trial presentation [skip ci]

This commit is contained in:
Maurice
2026-12-02 10:47:08 +01:00
parent 00fcb69423
commit 3438a2aa48
31 changed files with 195 additions and 616 deletions
+57 -105
View File
@@ -151,12 +151,11 @@ const I = {
globe: 'M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M2 12h20M12 2a15 15 0 0 1 0 20 15 15 0 0 1 0-20',
image:
'M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zM8.5 10a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zM21 15l-5-5L5 21',
spark: 'M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z',
mail: 'M4 5h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM3 7l9 6 9-6',
people:
'M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75',
shield: 'M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10',
check: 'M20 6 9 17l-5-5',
cross: 'M6 6l12 12M18 6 6 18',
lock: 'M6 11h12a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2zM8 11V8a4 4 0 0 1 8 0v3',
key: 'M7.5 20a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9zM10.7 12.3 21 2M16 7l3 3M14 9l2 2',
alert: 'M12 21.5a9.5 9.5 0 1 0 0-19 9.5 9.5 0 0 0 0 19zM12 7.5v5.5M12 16.5h.01',
@@ -315,7 +314,7 @@ function showWelcome(opts: { back?: boolean } = {}): void {
const perk = (glyph: string, title: string, sub: string) =>
el('div', {}, el('i', {}, icon(glyph, 17)), el('span', {}, el('b', {}, title), el('small', {}, sub)));
const trial = el('span', { className: 'trial-badge', hidden: true }, icon(I.spark, 12), t('native.trial.badge'));
const trial = el('span', { className: 'trial-badge', hidden: true }, t('native.trial.badge'));
const discover = el('button', { type: 'button', className: 'cta discover' }, t('native.welcome.discover'), trial);
discover.addEventListener('click', () => {
void tap();
@@ -668,7 +667,7 @@ interface CloudPlan {
yearlyCents?: number;
currency?: 'EUR' | 'USD';
aiDocuments: number;
aiDocumentLimit?: 0 | null;
aiDocumentLimit?: number | null;
aiAssistant?: 'planned' | 'included' | 'unavailable';
bookingMailImport?: boolean;
storageGb: number;
@@ -685,7 +684,7 @@ const SAMPLE_PLANS: CloudPlan[] = [
{
id: 'start',
name: 'Start',
monthlyCents: 499,
monthlyCents: 599,
yearlyCents: 4899,
currency: 'USD',
aiDocuments: 0,
@@ -695,7 +694,7 @@ const SAMPLE_PLANS: CloudPlan[] = [
{
id: 'plus',
name: 'Plus',
monthlyCents: 999,
monthlyCents: 1199,
yearlyCents: 9900,
currency: 'USD',
aiDocuments: 100,
@@ -793,22 +792,32 @@ async function loadOffer(list: CloudPlans): Promise<Offer> {
};
}
/** The plan the picker starts on and marks: the smallest one with AI documents, the one most trips want. */
function recommendedPlan(plans: CloudPlan[]): CloudPlan | undefined {
return plans.find((p) => p.aiDocuments > 0) ?? plans[0];
}
function planFeatures(plan: CloudPlan): HTMLLIElement[] {
const row = (label: string, value: string, glyph: string, unavailable = false) =>
el(
'li',
{ className: unavailable ? 'spec off' : 'spec' },
el('i', {}, icon(glyph, 16)),
el('b', {}, label),
el('bdi', {}, value)
);
const feature = (label: string, included: boolean) =>
row(
label,
t(included ? 'native.plans.included' : 'native.plans.notIncluded'),
included ? I.check : I.cross,
!included
);
/** The kind of trip each plan is for: a weekend away, a round trip, a long journey, the whole world. */
const TRIPS: Record<string, { titleKey: string; textKey: string }> = {
start: { titleKey: 'native.trip.start.title', textKey: 'native.trip.start.text' },
basis: { titleKey: 'native.trip.basis.title', textKey: 'native.trip.basis.text' },
plus: { titleKey: 'native.trip.plus.title', textKey: 'native.trip.plus.text' },
pro: { titleKey: 'native.trip.pro.title', textKey: 'native.trip.pro.text' },
};
/** A plan's trip, its title and one line; a plan the app does not know keeps its own name. */
function tripOf(plan: CloudPlan): { title: string; text: string } {
const trip = TRIPS[plan.id];
return trip ? { title: t(trip.titleKey), text: t(trip.textKey) } : { title: plan.name, text: '' };
const storage = plan.storageGb >= 1000 ? `${count(plan.storageGb / 1000)} TB` : `${count(plan.storageGb)} GB`;
const aiDocuments = plan.aiDocumentLimit === null || (plan.aiDocumentLimit ?? plan.aiDocuments) > 0;
return [
row(t('native.plans.storage'), storage, I.image),
feature(t('native.plans.aiLabel'), aiDocuments),
feature(t('native.plans.assistant'), plan.aiAssistant === 'included'),
feature(t('native.plans.mailImport'), plan.bookingMailImport === true),
row(t('native.plans.unlimitedSub'), t('native.plans.unlimited'), I.people),
];
}
function per(interval: 'month' | 'year'): string {
@@ -828,7 +837,7 @@ let resumeRestore: (() => void) | null = null;
let watchingTransactions = false;
/** Where the camera stood on the plan chosen last, for the screens that follow it. */
let chosenCamera: Camera = cameraForPlan(1);
/** The plan chosen last, so coming back to the plans finds it still chosen. */
/** Restore a choice when returning from setup. A fresh entry opens Plus. */
let chosenPlanId: string | null = null;
let chosenInterval: 'month' | 'year' = 'month';
@@ -898,9 +907,6 @@ function showPlans(opts: { back?: boolean } = {}): void {
const tiers = el('div', { className: 'tiers', role: 'radiogroup', hidden: true });
tiers.setAttribute('aria-label', t('native.plans.title'));
const title = el('h1', {});
const text = el('p', {});
const trip = el('div', { className: 'trip' }, title, text);
const monthBtn = el('button', { type: 'button', role: 'radio' }, t('native.plans.monthly'));
const yearBtn = el('button', { type: 'button', role: 'radio' }, t('native.plans.yearly'));
@@ -919,18 +925,18 @@ function showPlans(opts: { back?: boolean } = {}): void {
const equals = el('div', { className: 'equals' });
const trial = el('p', { className: 'trial-price', hidden: true });
const pricebox = el('div', { className: 'pricebox' }, cycle, price, equals, trial);
const specs = el('div', { className: 'specs' });
const specs = el('ul', { className: 'specs', role: 'list' });
const foot = el('div', { className: 'pad', hidden: true });
const legal = el('p', { className: 'legal' });
const loading = el('div', { className: 'loading' }, el('span', { className: 'spin' }));
const details = el('div', { className: 'stack', hidden: true }, trip, pricebox, specs);
const details = el('div', { className: 'stack', hidden: true }, pricebox, specs);
const choose = el('button', { type: 'button', className: 'cta', hidden: true });
const dock = el('div', { className: 'dock' }, choose);
const screen = show(
'plain',
chosenCamera,
opts.back ? chosenCamera : cameraForPlan(1),
{
back: () => showWelcome({ back: true }),
content: [el('div', { className: 'pad lift' }, tiers, loading, details), foot, dock],
@@ -977,20 +983,11 @@ function showPlans(opts: { back?: boolean } = {}): void {
yearBtn.setAttribute('aria-checked', String(interval === 'year'));
cycle.dataset.year = String(interval === 'year');
const { title: tripTitle, text: tripText } = tripOf(plan);
const recommended = recommendedPlan(plans)?.id === plan.id;
title.replaceChildren(
tripTitle,
...(recommended ? [el('span', { className: 'badge' }, t('native.plans.recommended'))] : [])
);
text.textContent = tripText;
text.hidden = !tripText;
const { label, buyable, freeTrial } = interval === 'month' ? month : year;
// No price yet (orders not open): the plan shows without one rather than with an empty one.
price.hidden = !label;
// An introductory offer states the free period and renewal price together.
price.hidden = !label || freeTrial;
pricePer.textContent = per(interval);
if (label) paintPrice(label, animate);
if (label && !freeTrial) paintPrice(label, animate);
// Without a price in either period (orders not open yet) the switch would choose between nothing.
pricebox.hidden = !month.label && !year.label;
@@ -1011,51 +1008,10 @@ function showPlans(opts: { back?: boolean } = {}): void {
? trialCancellation()
: t(onPlay ? 'native.plans.legalAndroid' : 'native.plans.legal');
const gb = plan.storageGb >= 1000 ? `${count(plan.storageGb / 1000)} TB` : `${count(plan.storageGb)} GB`;
const notIncluded = t('native.plans.aiNone');
const included = t('native.plans.included');
const assistant = plan.aiAssistant === 'included';
const tile = (glyph: string, big: string, small: string, off = false) =>
el(
'span',
{ className: off ? 'spec off' : 'spec' },
el('i', {}, icon(glyph, 17)),
el('span', {}, el('b', {}, big), el('small', {}, small))
);
specs.replaceChildren(
tile(I.image, gb, t('native.plans.storageFairUse')),
plan.aiDocuments > 0
? tile(
I.spark,
plan.aiDocumentLimit === null
? t('native.plans.unlimited')
: t('native.plans.aiPerMonth', { n: count(plan.aiDocuments) }),
t('native.plans.aiLabel')
)
: tile(I.spark, notIncluded, t('native.plans.aiLabel'), true),
tile(
I.spark,
assistant ? included : plan.aiAssistant === 'planned' ? t('native.plans.planned') : notIncluded,
t('native.plans.assistant'),
!assistant
),
tile(
I.mail,
plan.bookingMailImport ? included : notIncluded,
t('native.plans.mailImport'),
!plan.bookingMailImport
),
el(
'span',
{ className: 'spec wide' },
el('i', {}, icon(I.people, 17)),
el('span', {}, el('b', {}, t('native.plans.unlimited')), el('small', {}, t('native.plans.unlimitedSub'))),
el('em', {}, t('native.plans.inEveryPlan'))
)
);
specs.replaceChildren(...planFeatures(plan));
choose.hidden = !buyable;
choose.textContent = t('native.plans.choose', { trip: tripTitle });
choose.textContent = t('native.plans.choose', { plan: plan.name });
chosenCamera = cameraForPlan(index);
chosenPlanId = plan.id;
chosenInterval = interval;
@@ -1108,7 +1064,9 @@ function showPlans(opts: { back?: boolean } = {}): void {
}
offer = await loadOffer(list);
plans = list.plans;
selectedId = plans.find((p) => p.id === chosenPlanId)?.id ?? recommendedPlan(plans)?.id ?? null;
const previousId = opts.back ? chosenPlanId : null;
selectedId =
plans.find((p) => p.id === previousId)?.id ?? plans.find((p) => p.id === 'plus')?.id ?? plans[0]?.id ?? null;
tiers.replaceChildren(
...plans.map((p) => {
const b = el('button', { type: 'button', role: 'radio', dataset: { plan: p.id } }, p.name);
@@ -1360,25 +1318,25 @@ function showClaim(
void tap();
showPlans({ back: true });
});
const planPrice = !priceLabel
? null
: opts.freeTrial
? el('small', {}, trialPrice(priceLabel, interval))
: el('small', { dir: 'ltr' }, `${priceLabel} ${per(interval)}`);
const planRow = el(
'div',
{ className: 'plan-row' },
el(
'span',
{},
el('b', {}, plan.name),
...(priceLabel
? [
opts.freeTrial
? el('small', {}, trialPrice(priceLabel, interval))
: el('small', { dir: 'ltr' }, `${priceLabel} ${per(interval)}`),
]
: [])
),
el('span', {}, el('b', {}, plan.name), planPrice),
// A purchase already made is not a choice any more.
...(bought ? [] : [change])
);
const error = notice('');
const checkoutDock = el(
'div',
{ className: 'dock' },
submit,
el('p', { className: 'fine' }, opts.freeTrial ? trialCancellation() : t('native.claim.renews'))
);
const form = el(
'form',
{ className: 'pad form', noValidate: true },
@@ -1405,15 +1363,7 @@ function showClaim(
{
back: () => showPlans({ back: true }),
overlay: [card.node],
content: [
form,
el(
'div',
{ className: 'dock' },
submit,
el('p', { className: 'fine' }, opts.freeTrial ? trialCancellation() : t('native.claim.renews'))
),
],
content: [form, checkoutDock],
},
opts
);
@@ -1527,6 +1477,8 @@ function showClaim(
const outcome = await iap.purchase(productIdFor(plan.id, interval), trialRenewalPrice);
if (outcome.kind === 'offer-changed') {
restore();
planPrice?.remove();
checkoutDock.hidden = true;
setNotice(error, t('native.trial.changed'));
return;
}