RezinaLMS-CustomerEnd/packages/features/src/ui.tsx
kirukib 1fccdc07c9 feat(demo): real payment logos, Vimeo placeholder video, new footer, sample assessments
- Telebirr and CBE Birr logos from ethiopianlogos.com; Visa, Mastercard, PayPal and Zelle
  added as checkout methods with their logos (all simulated in ETB)
- Lessons without an upload play a Vimeo placeholder; progress tracked over the player API
- Footer redesigned: wordmark, short story, instructors, makeup-palette art, link columns
- Multiple-choice assessments: seed quizzes for three courses, quiz page with grading and
  review, results on My progress and in admin (student detail, curriculum tab)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 14:04:37 +03:00

207 lines
11 KiB
TypeScript

'use client';
import { useEffect, useRef, useState, type ReactNode } from 'react';
import type { Course, Locale } from '@lms/data';
import { useApp } from './store';
import { tr } from './domain';
const PATHS: Record<string, string> = {
home: 'M3 11l9-7 9 7v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z',
grid: 'M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z',
book: 'M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2zM4 21V5M8 7h7',
help: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6V14M12 17.5v.01',
user: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0',
bell: 'M6 8a6 6 0 1 1 12 0c0 7 3 8 3 8H3s3-1 3-8M10 20a2 2 0 0 0 4 0',
search: 'M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4',
play: 'M7 4v16l13-8z',
pause: 'M7 4h4v16H7zM13 4h4v16h-4z',
lock: 'M6 11h12v10H6zM8 11V7a4 4 0 0 1 8 0v4',
check: 'M5 12l5 5 9-10',
quiz: 'M9 3h6v3H9zM7 4.5H5V21h14V4.5h-2M9 14l2 2 4-4',
chevron: 'M9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4 6h16M4 12h16M4 18h16',
upload: 'M12 16V4M7 9l5-5 5 5M4 20h16',
plus: 'M12 5v14M5 12h14',
up: 'M6 15l6-6 6 6',
down: 'M6 9l6 6 6-6',
download: 'M12 4v12M7 11l5 5 5-5M4 20h16',
phone: 'M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2',
chat: 'M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z',
rewind: 'M11 19l-9-7 9-7zM22 19l-9-7 9-7z',
forward: 'M13 19l9-7-9-7zM2 19l9-7-9-7z',
expand: 'M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5',
comment: 'M4 4h16v12H8l-4 4z',
globe: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18',
clock: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2',
calendar: 'M4 6h16v14H4zM4 10h16M8 3v4M16 3v4',
share: 'M4 12v7a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-7M16 6l-4-4-4 4M12 2v13',
video: 'M3 6h12v12H3zM15 10l6-3v10l-6-3',
logout: 'M15 4h4a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-4M10 17l5-5-5-5M15 12H3',
sparkle: 'M12 3l2 6 6 2-6 2-2 6-2-6-6-2 6-2z',
brush: 'M14 4l6 6-8 8-6-6zM6 12l-3 7 7-3',
};
export function Icon({ name, size = 20, label }: { name: keyof typeof PATHS | string; size?: number; label?: string }) {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden={label ? undefined : true} role={label ? 'img' : undefined} aria-label={label}>
<path d={PATHS[name] ?? ''} />
</svg>
);
}
// Placeholder brand mark until the real logo arrives: navy tile, frosted-blue wave, punch-red dot.
export function Logo({ size = 34 }: { size?: number }) {
return (
<span className="logo" aria-hidden>
<svg width={size} height={size} viewBox="0 0 34 34">
<rect width="34" height="34" rx="10" fill="#1D3557" />
<path d="M7 22c3.5-6 7-6 10 0s6.5 6 10 0" fill="none" stroke="#A8DADC" strokeWidth="3" strokeLinecap="round" />
<circle cx="23.5" cy="11" r="3.5" fill="#E63946" />
</svg>
</span>
);
}
// Stand-in lesson video until real uploads exist: Blender's openly licensed "Big Buck Bunny" on Vimeo.
export const VIMEO_ORIGIN = 'https://player.vimeo.com';
export const VIMEO_PLACEHOLDER = `${VIMEO_ORIGIN}/video/1084537?dnt=1&title=0&byline=0&portrait=0`;
// Footer art: an eyeshadow palette. Twelve pans in brand and skin shades; a white brush and compact mirror sit
// under the case's grid lines so the shapes break across tiles (the reference's cut-paper look).
const PANS = ['#E63946', '#F5AFB5', '#A8DADC', '#E9B8A7', '#457B9D', '#F1FAEE', '#C98B6B', '#FAD7DA', '#315A93', '#8E4B45', '#70C3C6', '#CB1928'];
export function MakeupBox() {
const W = 92, H = 92, G = 6, P = 14; // tile size, gap, case padding
return (
<div className="foot-box" aria-hidden>
<svg viewBox={`0 0 ${P * 2 + W * 3 + G * 2} ${P * 2 + H * 4 + G * 3}`} role="presentation">
<defs>
<radialGradient id="pan-shine" cx="35%" cy="30%" r="70%"><stop offset="0" stopColor="#fff" stopOpacity=".55" /><stop offset=".45" stopColor="#fff" stopOpacity="0" /></radialGradient>
</defs>
<rect width="100%" height="100%" rx="22" fill="#1D3557" />
{PANS.map((c, i) => {
const x = P + (i % 3) * (W + G), y = P + Math.floor(i / 3) * (H + G);
return (
<g key={i}>
<rect x={x} y={y} width={W} height={H} rx="6" fill={c} />
<circle cx={x + W / 2} cy={y + H / 2} r={W * 0.34} fill={c} stroke="rgba(0,0,0,.12)" strokeWidth="2" />
<circle cx={x + W / 2} cy={y + H / 2} r={W * 0.34} fill="url(#pan-shine)" />
</g>
);
})}
<g fill="#fff">
<g transform="rotate(-40 160 220)">
<rect x="10" y="206" width="180" height="28" rx="14" />
<rect x="184" y="198" width="44" height="44" rx="6" />
<path d="M226 192 C 290 176, 340 200, 352 220 C 340 240, 290 264, 226 248 Z" />
</g>
<circle cx="262" cy="64" r="44" fill="none" stroke="#fff" strokeWidth="12" />
<path d="M40 404 a40 40 0 0 1 80 0 Z" />
</g>
<g fill="#1D3557">
{[1, 2].map((k) => <rect key={'v' + k} x={P + k * W + (k - 1) * G} y={0} width={G} height="100%" />)}
{[1, 2, 3].map((k) => <rect key={'h' + k} x={0} y={P + k * H + (k - 1) * G} width="100%" height={G} />)}
</g>
</svg>
</div>
);
}
const TONES = ['rose', 'clay', 'plum', 'sand', 'sage', 'ink'];
export function Cover({ course, locale, badge }: { course: Course; locale: Locale; badge?: ReactNode }) {
const { ds } = useApp();
// No image → the title itself, set in Ge'ez serif, is the cover (§11.2: the script is the visual identity).
// Shows the title in the other script from the page's language, so the cover adds a second language instead of repeating the card title.
const other = locale === 'am' || locale === 'ti' ? 'en' : 'am';
const title = course.translations[other]?.title ?? tr(course.translations, locale)?.title ?? '';
const tone = course.coverTone && TONES.includes(course.coverTone) ? course.coverTone : 'ink';
return (
<div className={`cover tone-${tone} ${course.coverAssetId ? 'has-img' : ''}`}>
{course.coverAssetId && <img src={ds.assetUrl(course.coverAssetId)} alt="" />}
{badge}
<span className="ttl" lang={other} aria-hidden>{title}</span>
</div>
);
}
export function Empty({ children, action }: { children: ReactNode; action?: ReactNode }) {
return <div className="empty"><p>{children}</p>{action}</div>;
}
export function Skeleton({ h = 120, n = 1 }: { h?: number; n?: number }) {
return <div className="stack" aria-busy="true" aria-live="polite">{Array.from({ length: n }, (_, i) => <div key={i} className="skel" style={{ height: h }} />)}</div>;
}
export function Modal({ title, onClose, children }: { title: string; onClose(): void; children: ReactNode }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const k = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
addEventListener('keydown', k);
ref.current?.querySelector<HTMLElement>('input,select,textarea,button')?.focus();
return () => removeEventListener('keydown', k);
}, [onClose]);
return (
<div className="modal-back" onClick={(e) => e.target === e.currentTarget && onClose()}>
<div className="modal" role="dialog" aria-modal="true" aria-label={title} ref={ref}>
<div className="row-between"><h2 style={{ fontSize: 'var(--fs-lg)' }}>{title}</h2><button className="icon-btn" onClick={onClose} aria-label="Close"><Icon name="x" /></button></div>
{children}
</div>
</div>
);
}
export function Ring({ pct, size = 56 }: { pct: number; size?: number }) {
const r = 24, c = 2 * Math.PI * r;
return (
<svg className="ring" width={size} height={size} viewBox="0 0 56 56" role="img" aria-label={`${pct}%`}>
<circle className="bg" cx="28" cy="28" r={r} />
<circle className="fg" cx="28" cy="28" r={r} strokeDasharray={c} strokeDashoffset={c * (1 - pct / 100)} />
<text x="28" y="32" textAnchor="middle" fontSize="13" fontWeight="700" fill="currentColor">{pct}%</text>
</svg>
);
}
const PILL_KIND: Record<string, string> = {
PAID: 'ok', ACTIVE: 'ok', PUBLISHED: 'ok', RESOLVED: 'ok', READY: 'ok', SENT: 'ok',
PENDING: 'warn', OPEN: 'warn', IN_PROGRESS: 'info', DRAFT: 'info', PROCESSING: 'info', UPLOADING: 'info', SCHEDULED: 'info',
FAILED: 'bad', EXPIRED: 'bad', DEACTIVATED: 'bad', CANCELLED: '', REFUNDED: 'info', ARCHIVED: '', CLOSED: '', NONE: '',
};
export function StatusPill({ status, label }: { status: string; label?: string }) {
const k = PILL_KIND[status];
return <span className={`pill ${k ? 'pill-' + k : ''}`}>{label ?? status.replace(/_/g, ' ').toLowerCase().replace(/^./, (c) => c.toUpperCase())}</span>;
}
/** "Leave feedback" — opens a Claude comment pinned to the current screen (§18.6). Hidden when comments are unavailable. */
export function FeedbackButton({ label, target }: { label: string; target: () => Element | null }) {
const { ds } = useApp();
const [ok, setOk] = useState(false);
useEffect(() => { ds.feedbackAvailable().then(setOk); }, [ds]);
if (!ok) return null;
return <button className="btn btn-ghost btn-sm feedback-btn" aria-label={label} title={label} onClick={() => { const el = target(); if (el) ds.feedback(el); }}><Icon name="comment" size={16} /><span className="lbl">{label}</span></button>;
}
export function CopyText({ text, copyLabel, copiedLabel }: { text: string; copyLabel: string; copiedLabel: string }) {
const [done, setDone] = useState(false);
return (
<button className="btn btn-ghost btn-sm" onClick={() => {
navigator.clipboard?.writeText(text).then(() => setDone(true), () => setDone(false));
}}>{done ? copiedLabel : copyLabel}</button>
);
}
// Gregorian, en-GB digits in every locale for the demo; Ethiopian calendar is P2 (§12).
export const fmtDate = (iso?: string | null) =>
iso ? new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' }) : '—';
export const fmtDateTime = (iso?: string | null) =>
iso ? new Date(iso).toLocaleString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }) : '—';