SHA256
68 lines
2.9 KiB
JavaScript
68 lines
2.9 KiB
JavaScript
import { openSheet } from './sheet.js';
|
|
|
|
// Пошаговое подтверждение перед публичной записью. Ни один шаг не выполняет сетевых запросов.
|
|
// Текст задаёт вызывающий экран; запись начинается только после прохождения всех шагов.
|
|
export function confirmConsentSteps({ title = 'Подтверждение', steps = [] } = {}) {
|
|
if (!steps.length) return Promise.resolve(false);
|
|
return new Promise((resolve) => {
|
|
let completed = false;
|
|
let stepIndex = 0;
|
|
const content = document.createElement('div');
|
|
content.className = 'stack profile-consent-flow';
|
|
const progress = document.createElement('div');
|
|
progress.className = 'meta-muted profile-consent-progress';
|
|
const heading = document.createElement('h3');
|
|
heading.className = 'profile-consent-heading';
|
|
const paragraph = document.createElement('p');
|
|
paragraph.className = 'profile-consent-description';
|
|
const checkboxLabel = document.createElement('label');
|
|
checkboxLabel.className = 'profile-consent-accept';
|
|
const checkbox = document.createElement('input');
|
|
checkbox.type = 'checkbox';
|
|
const checkboxText = document.createElement('span');
|
|
checkboxLabel.append(checkbox, checkboxText);
|
|
const actions = document.createElement('div');
|
|
actions.className = 'form-actions-grid';
|
|
const cancelBtn = document.createElement('button');
|
|
cancelBtn.type = 'button';
|
|
cancelBtn.className = 'secondary-btn';
|
|
cancelBtn.textContent = 'Отмена';
|
|
const nextBtn = document.createElement('button');
|
|
nextBtn.type = 'button';
|
|
nextBtn.className = 'primary-btn';
|
|
actions.append(cancelBtn, nextBtn);
|
|
content.append(progress, heading, paragraph, checkboxLabel, actions);
|
|
|
|
const sheet = openSheet({
|
|
title,
|
|
className: 'profile-consent-sheet',
|
|
content,
|
|
onClose: () => resolve(completed),
|
|
});
|
|
function renderStep() {
|
|
const step = steps[stepIndex];
|
|
progress.textContent = `${stepIndex + 1} / ${steps.length}`;
|
|
heading.textContent = step.title;
|
|
paragraph.textContent = step.text;
|
|
checkbox.checked = false;
|
|
checkboxLabel.hidden = !step.accept;
|
|
checkboxText.textContent = step.accept || '';
|
|
nextBtn.disabled = Boolean(step.accept);
|
|
nextBtn.textContent = step.button || (stepIndex === steps.length - 1 ? 'Подтверждаю и продолжаю' : 'Понятно, дальше');
|
|
}
|
|
checkbox.addEventListener('change', () => { nextBtn.disabled = !checkbox.checked; });
|
|
cancelBtn.addEventListener('click', () => sheet.close());
|
|
nextBtn.addEventListener('click', () => {
|
|
if (steps[stepIndex].accept && !checkbox.checked) return;
|
|
if (stepIndex === steps.length - 1) {
|
|
completed = true;
|
|
sheet.close();
|
|
} else {
|
|
stepIndex += 1;
|
|
renderStep();
|
|
}
|
|
});
|
|
renderStep();
|
|
});
|
|
}
|