From the owner's page-by-page review (2026-11-20): - every page root is <Page> (scrolls, fills 1080p, 16:9 centred on ultrawides); not yet: products, management/tables, stock (next pass) - /dashboard: more padding in cards (p-card), quieter secondary text, 11px uppercase labels everywhere (text-overline) - day stats: xl dialog, "● Day running · Opened …" as text, the six figures in equal boxes, "On tabs" in the payments bar, shared Tabs - /tables: Segmented List / Map / QR codes (?view=; /online/qr redirects), filter chips + zones multi-select at one height, the card itself opens the table (button removed), cards ~20% wider - /online-orders: shared Tabs with Settings (= the old /online/fees page, which redirects to ?tab=settings); orders fill the width - contacts, customers, expenses: PageHeader + Toolbar + SearchInput + multi-select Dropdowns (kinds; statuses, categories); table cells vertically centred; the Spent tip opens on hover - filterCards / filterContacts / filterExpenses take several values (unit tests added) - docs/DESIGN.md: the design language (CS-20 in the pack README) - tests/e2e/manager_layout.mjs: the page rule at 1920x1080 and 3440x1440; manager.mjs and manager_look.mjs follow the moved pages Verified: manager build + lint (0 errors), unit tests (manager 99, ui 24, i18n 31, api 25, access 8), i18n guard, manager_layout.mjs all passed, manager.mjs 228 checks all passed. Not checked: the waiter app and the terminal by eye (they only get the muted ink-2 token). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
141 lines
6.2 KiB
React
141 lines
6.2 KiB
React
import { useState, useEffect, useRef } from 'react'
|
|
import { ChevronDown, User, LogOut, Languages, Check, Monitor, Moon, Palette, Sun } from 'lucide-react'
|
|
import toast from 'react-hot-toast'
|
|
import { useAccess } from '@xenia/access'
|
|
import { PALETTES, STYLES, THEMES, applyLook, getStoredLook } from '@xenia/ui'
|
|
import { LANGUAGE_NAMES, setUserLanguage, useLanguage, useTranslation } from '@xenia/i18n'
|
|
import client from '../api/client'
|
|
|
|
/**
|
|
* The profile menu (plan step 2.6a): edit profile, language, the look (6.15: light / dark /
|
|
* system, the palette, the style; saved on this device, applied at once), sign out.
|
|
* The language changes the screen at once, is saved to the user's profile
|
|
* (PATCH /api/auth/me) and then the platform bootstrap is reloaded, so it also
|
|
* applies on the next login and in the other apps (D-12).
|
|
*/
|
|
export default function UserMenuButton({ displayName, onEditProfile, onSignOut }) {
|
|
const { t, i18n } = useTranslation('manager')
|
|
const { language, languages } = useLanguage()
|
|
const { refresh } = useAccess()
|
|
const [open, setOpen] = useState(false)
|
|
const [look, setLook] = useState(getStoredLook)
|
|
const pickLook = change => setLook(applyLook({ ...look, ...change }, { save: true }))
|
|
const ref = useRef(null)
|
|
|
|
useEffect(() => {
|
|
function handleOutside(e) {
|
|
if (ref.current && !ref.current.contains(e.target)) setOpen(false)
|
|
}
|
|
function handleEscape(e) {
|
|
if (e.key === 'Escape') setOpen(false)
|
|
}
|
|
if (open) {
|
|
document.addEventListener('mousedown', handleOutside)
|
|
document.addEventListener('keydown', handleEscape)
|
|
}
|
|
return () => {
|
|
document.removeEventListener('mousedown', handleOutside)
|
|
document.removeEventListener('keydown', handleEscape)
|
|
}
|
|
}, [open])
|
|
|
|
async function chooseLanguage(lng) {
|
|
setOpen(false)
|
|
if (lng === language) return
|
|
try {
|
|
await setUserLanguage(i18n, lng, { save: l => client.patch('/api/auth/me', { language: l }) })
|
|
await refresh()
|
|
} catch {
|
|
toast.error(t('common:language.notSaved'))
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="relative" ref={ref}>
|
|
<button
|
|
onClick={() => setOpen(o => !o)}
|
|
className="flex items-center gap-1 text-[13px] text-ink-2 font-medium hover:text-ink transition-colors"
|
|
aria-haspopup="menu"
|
|
aria-expanded={open}
|
|
data-testid="user-menu"
|
|
>
|
|
{displayName}
|
|
<ChevronDown className={`h-3.5 w-3.5 text-ink-3 transition-transform ${open ? 'rotate-180' : ''}`} />
|
|
</button>
|
|
|
|
{open && (
|
|
<div className="absolute right-0 top-full mt-1.5 w-72 rounded-xl border border-line bg-surface shadow-lg py-1 z-50" role="menu">
|
|
<button
|
|
role="menuitem"
|
|
onClick={() => { setOpen(false); onEditProfile() }}
|
|
className="flex w-full items-center gap-2.5 px-3.5 py-2 text-[13px] text-ink hover:bg-surface-2 transition-colors"
|
|
>
|
|
<User className="h-3.5 w-3.5 text-ink-3" />
|
|
{t('profile.edit')}
|
|
</button>
|
|
|
|
<div className="my-1 border-t border-line" />
|
|
<div className="flex items-center gap-2.5 px-3.5 pt-1.5 pb-1 text-overline font-semibold uppercase tracking-wide text-ink-3">
|
|
<Languages className="h-3.5 w-3.5" />
|
|
{t('profile.language')}
|
|
</div>
|
|
{languages.map(lng => (
|
|
<button
|
|
key={lng}
|
|
role="menuitemradio"
|
|
aria-checked={lng === language}
|
|
lang={lng}
|
|
onClick={() => chooseLanguage(lng)}
|
|
className="flex w-full items-center gap-2.5 px-3.5 py-2 pl-9 text-[13px] text-ink hover:bg-surface-2 transition-colors"
|
|
>
|
|
<span className="flex-1 text-left">{LANGUAGE_NAMES[lng]}</span>
|
|
{lng === language && <Check className="h-3.5 w-3.5 text-accent-ink" />}
|
|
</button>
|
|
))}
|
|
|
|
<div className="my-1 border-t border-line" />
|
|
<div className="flex items-center gap-2.5 px-3.5 pt-1.5 pb-1 text-overline font-semibold uppercase tracking-wide text-ink-3">
|
|
<Palette className="h-3.5 w-3.5" />
|
|
{t('profile.look')}
|
|
</div>
|
|
<LookRow label={t('profile.mode')} options={THEMES} value={look.mode} onPick={mode => pickLook({ mode })}
|
|
name={m => t(`profile.modes.${m}`)} icon={m => ({ light: Sun, dark: Moon, system: Monitor })[m]} testId="look-mode" />
|
|
<LookRow label={t('profile.palette')} options={PALETTES} value={look.palette} onPick={palette => pickLook({ palette })} name={p => t(`profile.palettes.${p}`)} testId="look-palette" />
|
|
<LookRow label={t('profile.style')} options={STYLES} value={look.style} onPick={style => pickLook({ style })} name={x => t(`profile.styles.${x}`)} testId="look-style" />
|
|
|
|
<div className="my-1 border-t border-line" />
|
|
<button
|
|
role="menuitem"
|
|
onClick={() => { setOpen(false); onSignOut() }}
|
|
className="flex w-full items-center gap-2.5 px-3.5 py-2 text-[13px] text-danger-ink hover:bg-danger-soft transition-colors"
|
|
>
|
|
<LogOut className="h-3.5 w-3.5" />
|
|
{t('profile.signOut')}
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/** One choice of the look: a small segmented row (the menu stays open, the page changes at once). */
|
|
function LookRow({ label, options, value, onPick, name, icon, testId }) {
|
|
return (
|
|
<div className="px-3.5 py-1 grid gap-1" role="group" aria-label={label} data-testid={testId}>
|
|
<span className="text-caption text-ink-3">{label}</span>
|
|
<span className="flex gap-1">
|
|
{options.map(o => {
|
|
const Icon = icon?.(o)
|
|
const on = o === value
|
|
return (
|
|
<button key={o} type="button" role="menuitemradio" aria-checked={on} onClick={() => onPick(o)} data-value={o}
|
|
className={`flex-1 flex items-center justify-center gap-1 rounded-control border px-1.5 py-1 text-caption font-medium transition-colors ${on ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line text-ink-2 hover:bg-surface-2'}`}>
|
|
{Icon && <Icon className="h-3.5 w-3.5" aria-hidden="true" />}{name(o)}
|
|
</button>
|
|
)
|
|
})}
|
|
</span>
|
|
</div>
|
|
)
|
|
}
|