Files
SHiNE-server/shine-UI/js/pages/registration-choice-view.js
T

84 lines
3.6 KiB
JavaScript

import { t } from '../i18n/index.js';
import { createTopBar } from '../components/topbar.js';
import { state } from '../state.js';
export const pageMeta = { id: 'registration-choice-view', get title() { return t('screens.registration_choice_view.text_001'); }, showAppChrome: false };
export function render({ navigate }) {
const screen = document.createElement('section');
screen.className = 'stack registration-screen signup-choice';
const title = document.createElement('h1');
title.className = 'signup-title';
title.textContent = t('screens.registration_choice_view.text_002');
const intro = document.createElement('p');
intro.className = 'signup-lead';
intro.textContent = t('screens.registration_choice_view.text_003');
function card({ type, icon, heading, price, lead, perks, button }) {
const box = document.createElement('article');
box.className = `signup-plan signup-plan--${type}`;
const top = document.createElement('div');
top.className = 'signup-plan__top';
const symbol = document.createElement('span');
symbol.className = 'signup-plan__symbol';
symbol.textContent = icon;
const header = document.createElement('div');
const name = document.createElement('h2');
name.textContent = heading;
const cost = document.createElement('p');
cost.className = 'signup-plan__price';
cost.textContent = price;
header.append(name, cost);
top.append(symbol, header);
const description = document.createElement('p');
description.className = 'signup-plan__lead';
description.textContent = lead;
const list = document.createElement('ul');
for (const perk of perks) {
const li = document.createElement('li');
li.textContent = perk;
list.append(li);
}
const action = document.createElement('button');
action.type = 'button';
action.className = type === 'paid' ? 'primary-btn' : 'secondary-btn';
action.textContent = button;
action.addEventListener('click', () => {
const draft = state.registrationDraft;
if (draft.flowType !== type) {
// При смене namespace старые ключи/коды больше не соответствуют выбранному аккаунту.
draft.login = '';
draft.password = '';
draft.preGeneratedKeyBundle = null;
draft.challengeId = '';
draft.challengeExpiresAtMs = 0;
draft.email = '';
}
draft.flowType = type;
draft.uiStep = 1;
navigate('register-view');
});
box.append(top, description, list, action);
return box;
}
screen.append(
createTopBar({ title: t('screens.registration_choice_view.text_004'), back: { label: '←', onClick: () => navigate('registration-intro-view') } }),
title, intro,
card({
type: 'paid', icon: '◇', heading: t('screens.registration_choice_view.text_005'),
price: t('screens.registration_choice_view.text_007'),
lead: t('screens.registration_choice_view.text_008'),
perks: [t('screens.registration_choice_view.text_009'), t('screens.registration_choice_view.text_010'), t('screens.registration_choice_view.text_011')],
button: t('screens.registration_choice_view.text_012'),
}),
card({
type: 'free', icon: '♧', heading: t('screens.registration_choice_view.text_006'),
price: t('screens.registration_choice_view.text_013'),
lead: t('screens.registration_choice_view.text_014'),
perks: [t('screens.registration_choice_view.text_015'), t('screens.registration_choice_view.text_016'), t('screens.registration_choice_view.text_017')],
button: t('screens.registration_choice_view.text_018'),
}),
);
return screen;
}