feat(manager): the setup wizard and the shell on v2; all of src on the v2 rules (platform-v2 step 6.14b)
- setup wizard (src/pages/setup): welcome (pick the language: the wizard switches at once), the owner's account, the venue (kind, name, staff language, time zone), an optional lock-screen PIN, finish -> sign in; English and Greek - shell (src/shell): AppLayout (license banner in both languages, header, lock button, idle lock / sign-out), Sidebar on a new 'nav' token set in @xenia/ui (light + dark), ProfileDialog (name, username, password, 4-6 digit PIN), licenseContext; App.jsx loads the session and the setup state with react-query (no setState in effects); the header's dead search box gone - Management -> Tables -> List (src/pages/tables, was TablesConfigTab): zones as tabs (drag to reorder), zone name / prefix / colour, add many numbered on, a table's name (6 chars) / zone / seats, twice-used names flagged, off / on / delete, pick several to move, rename in a series or delete (says how many failed) - the old src/ui kit, layouts/, components/Sidebar + EditProfileModal, the 'primary' palette and the .btn/.card/.input classes deleted; NotificationBell / UserMenuButton on tokens; @xenia/ui: nav tokens, 'scrim' in the Tailwind preset - v2.json paths = src (the guards cover all of it); npm run lint = eslint src; argsIgnorePattern for components in JSX - tests: shell.test.mjs (3), e2e setup.mjs (new: a fresh install through the wizard in Greek to the overview, in run-all), manager.mjs 'tables list' (zone, 3 tables, rename series, profile PIN, rail tokens) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,166 +0,0 @@
|
||||
import { useState } from 'react'
|
||||
import Modal from '../ui/Modal'
|
||||
import Button from '../ui/Button'
|
||||
import { LabelledInput } from '../ui/Input'
|
||||
import client from '../api/client'
|
||||
import useAuthStore from '../store/authStore'
|
||||
|
||||
export default function EditProfileModal({ onClose }) {
|
||||
const { user, updateUser } = useAuthStore()
|
||||
|
||||
const [fullName, setFullName] = useState(user?.full_name || '')
|
||||
const [username, setUsername] = useState(user?.username || '')
|
||||
|
||||
const [currentPassword, setCurrentPassword] = useState('')
|
||||
const [newPassword, setNewPassword] = useState('')
|
||||
const [confirmPassword, setConfirmPassword] = useState('')
|
||||
|
||||
const [newPin, setNewPin] = useState('')
|
||||
const [confirmPin, setConfirmPin] = useState('')
|
||||
|
||||
const [error, setError] = useState('')
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
const passwordTouched = currentPassword || newPassword || confirmPassword
|
||||
const pinTouched = newPin || confirmPin
|
||||
|
||||
function validate() {
|
||||
if (passwordTouched) {
|
||||
if (!currentPassword) return 'Enter your current password.'
|
||||
if (!newPassword) return 'Enter a new password.'
|
||||
if (newPassword.length < 6) return 'New password must be at least 6 characters.'
|
||||
if (newPassword !== confirmPassword) return 'New passwords do not match.'
|
||||
}
|
||||
if (pinTouched) {
|
||||
if (newPin.length < 4) return 'PIN must be 4 digits.'
|
||||
if (newPin !== confirmPin) return 'PINs do not match.'
|
||||
}
|
||||
if (!username.trim()) return 'Username cannot be empty.'
|
||||
return null
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
const validationError = validate()
|
||||
if (validationError) { setError(validationError); return }
|
||||
|
||||
const body = {}
|
||||
if (fullName !== (user?.full_name || '')) body.full_name = fullName
|
||||
if (username !== user?.username) body.username = username
|
||||
if (passwordTouched) {
|
||||
body.current_password = currentPassword
|
||||
body.new_password = newPassword
|
||||
}
|
||||
if (pinTouched) {
|
||||
body.new_pin = newPin
|
||||
}
|
||||
|
||||
if (Object.keys(body).length === 0) { onClose(); return }
|
||||
|
||||
setError('')
|
||||
setSaving(true)
|
||||
try {
|
||||
const { data } = await client.patch('/api/auth/me', body)
|
||||
updateUser(data)
|
||||
onClose()
|
||||
} catch (err) {
|
||||
const detail = err.response?.data?.detail
|
||||
setError(typeof detail === 'string' ? detail : 'Failed to save changes.')
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
function onlyDigits(val, max) {
|
||||
return val.replace(/\D/g, '').slice(0, max)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal title="Edit Profile" onClose={onClose} maxWidth="max-w-lg">
|
||||
<div className="space-y-4">
|
||||
|
||||
<div className="space-y-2">
|
||||
<LabelledInput
|
||||
label="Display Name"
|
||||
value={fullName}
|
||||
onChange={e => setFullName(e.target.value)}
|
||||
placeholder="e.g. Maria Papadopoulou"
|
||||
/>
|
||||
<LabelledInput
|
||||
label="Username"
|
||||
value={username}
|
||||
onChange={e => setUsername(e.target.value)}
|
||||
autoComplete="off"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-slate-100" />
|
||||
|
||||
<div className="space-y-2">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-wider text-slate-400">
|
||||
Change Password <span className="normal-case font-normal">(leave blank to keep current)</span>
|
||||
</p>
|
||||
<LabelledInput
|
||||
label="Current Password"
|
||||
type="password"
|
||||
value={currentPassword}
|
||||
onChange={e => setCurrentPassword(e.target.value)}
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
<LabelledInput
|
||||
label="New Password"
|
||||
type="password"
|
||||
value={newPassword}
|
||||
onChange={e => setNewPassword(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
<LabelledInput
|
||||
label="Confirm New Password"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={e => setConfirmPassword(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-slate-100" />
|
||||
|
||||
<div className="space-y-2">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-wider text-slate-400">
|
||||
Change PIN <span className="normal-case font-normal">(leave blank to keep current)</span>
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<LabelledInput
|
||||
label="New PIN"
|
||||
type="password"
|
||||
inputMode="numeric"
|
||||
value={newPin}
|
||||
onChange={e => setNewPin(onlyDigits(e.target.value, 4))}
|
||||
placeholder="••••"
|
||||
className="flex-1"
|
||||
/>
|
||||
<LabelledInput
|
||||
label="Confirm PIN"
|
||||
type="password"
|
||||
inputMode="numeric"
|
||||
value={confirmPin}
|
||||
onChange={e => setConfirmPin(onlyDigits(e.target.value, 4))}
|
||||
placeholder="••••"
|
||||
className="flex-1"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="text-[12px] text-rose-500">{error}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Modal.Footer>
|
||||
<Button variant="secondary" onClick={onClose} disabled={saving}>Cancel</Button>
|
||||
<Button variant="primary" onClick={handleSave} disabled={saving}>
|
||||
{saving ? 'Saving…' : 'Save Changes'}
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export default function NotificationBell() {
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
onClick={() => { setOpen(o => !o); if (!open) load() }}
|
||||
className="relative flex h-8 w-8 items-center justify-center rounded-lg border border-slate-200 bg-white text-slate-500 transition hover:bg-slate-50 hover:text-slate-700"
|
||||
className="relative flex h-8 w-8 items-center justify-center rounded-lg border border-line bg-surface text-ink-3 transition hover:bg-surface-2 hover:text-ink"
|
||||
aria-label={data.unread ? t('notifications.bellUnread', { count: data.unread }) : t('notifications.bell')}
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={open}
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
import { NavLink, useLocation } from 'react-router-dom'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { ChevronDown } from 'lucide-react'
|
||||
import { useAccess } from '@xenia/access'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { getIncomingOrders } from '../api/client'
|
||||
import { NAV, NAV_BOTTOM, canSee } from '../shell/nav'
|
||||
|
||||
// The sidebar is drawn from shell/nav.js: an item shows when its module is on and the user
|
||||
// holds its key (platform bootstrap, @xenia/access). Plan step 2.6a; this replaces the
|
||||
// browser-only feature toggles (F-033).
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function isChildActive(children, pathname) {
|
||||
return children.some(c => pathname === c.to || pathname.startsWith(c.to + '/'))
|
||||
}
|
||||
|
||||
// ─── Child link ───────────────────────────────────────────────────────────────
|
||||
|
||||
function ChildLink({ to, icon: Icon, label, placeholder }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (placeholder) {
|
||||
return (
|
||||
<div className="flex items-center gap-2.5 px-3 py-2 mx-2 rounded-md text-[13px] text-primary-400 cursor-default select-none">
|
||||
<Icon size={14} className="shrink-0 opacity-50" />
|
||||
<span>{t(label)}</span>
|
||||
<span className="ml-auto text-[10px] font-semibold bg-primary-700 text-primary-300 px-1.5 py-0.5 rounded">{t('nav.soon')}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
to={to}
|
||||
end
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-2.5 px-3 py-2 mx-2 rounded-md text-[13px] font-medium transition-colors ` +
|
||||
(isActive
|
||||
? 'bg-primary-600 text-white'
|
||||
: 'text-primary-200 hover:bg-primary-700 hover:text-white')
|
||||
}
|
||||
>
|
||||
{({ isActive }) => (
|
||||
<>
|
||||
<Icon size={14} className="shrink-0" />
|
||||
<span>{t(label)}</span>
|
||||
{isActive && <span className="ml-auto w-1 h-1 rounded-full bg-sky-400 shrink-0" />}
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Group item (collapsible parent) ─────────────────────────────────────────
|
||||
|
||||
function GroupItem({ group, icon: Icon, label, children, openGroup, onToggle }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const location = useLocation()
|
||||
const hasActive = isChildActive(children, location.pathname)
|
||||
const isOpen = openGroup === group
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
onClick={() => onToggle(group)}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors ` +
|
||||
(hasActive
|
||||
? 'text-white bg-primary-700'
|
||||
: 'text-primary-100 hover:bg-primary-700 hover:text-white')}
|
||||
>
|
||||
<Icon size={18} className="shrink-0" />
|
||||
<span className="flex-1 text-left">{t(label)}</span>
|
||||
<ChevronDown
|
||||
size={14}
|
||||
className={`shrink-0 transition-transform duration-200 ${isOpen ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{isOpen && (
|
||||
<div className="mt-0.5 mb-1 space-y-0.5 py-1 border-l border-primary-600 ml-5">
|
||||
{children.map(child => (
|
||||
<ChildLink key={child.to} {...child} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Solo item (direct link) ──────────────────────────────────────────────────
|
||||
|
||||
function SoloItem({ to, icon: Icon, label, badge, onNavigate }) {
|
||||
const { t } = useTranslation('manager')
|
||||
return (
|
||||
<NavLink
|
||||
to={to}
|
||||
end
|
||||
onClick={onNavigate}
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors ` +
|
||||
(isActive ? 'bg-primary-600 text-white' : 'text-primary-100 hover:bg-primary-700 hover:text-white')
|
||||
}
|
||||
>
|
||||
<div className="relative shrink-0">
|
||||
<Icon size={18} />
|
||||
{badge > 0 && (
|
||||
<span className="absolute -top-1.5 -right-1.5 bg-red-500 text-white text-[10px] font-bold w-4 h-4 rounded-full flex items-center justify-center leading-none">
|
||||
{badge > 9 ? '9+' : badge}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span>{t(label)}</span>
|
||||
</NavLink>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Sidebar ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/** The sections with only what this user may see (empty groups and sections dropped). */
|
||||
function visibleNav(access) {
|
||||
return NAV
|
||||
.map(section => ({
|
||||
...section,
|
||||
items: section.items
|
||||
.map(item => (item.children
|
||||
? { ...item, children: item.children.filter(c => canSee(c, access)) }
|
||||
: item))
|
||||
.filter(item => (item.children ? item.children.length > 0 : canSee(item, access))),
|
||||
}))
|
||||
.filter(section => section.items.length > 0)
|
||||
}
|
||||
|
||||
export default function Sidebar() {
|
||||
const { t } = useTranslation('manager')
|
||||
const access = useAccess()
|
||||
const [pendingCount, setPendingCount] = useState(0)
|
||||
const [openGroup, setOpenGroup] = useState(null)
|
||||
const location = useLocation()
|
||||
const nav = visibleNav(access)
|
||||
const onlineOrdersShown = nav.some(s => s.items.some(i => i.badge === 'onlineOrders'))
|
||||
|
||||
// Online orders badge (only while that page is available)
|
||||
useEffect(() => {
|
||||
if (!onlineOrdersShown) return undefined
|
||||
async function fetchPending() {
|
||||
try {
|
||||
const { data } = await getIncomingOrders()
|
||||
setPendingCount(data.length)
|
||||
} catch { /* non-critical */ }
|
||||
}
|
||||
fetchPending()
|
||||
const timer = setInterval(fetchPending, 20_000)
|
||||
return () => clearInterval(timer)
|
||||
}, [onlineOrdersShown])
|
||||
|
||||
// Auto-open the group that contains the active route on location change
|
||||
useEffect(() => {
|
||||
for (const section of NAV) {
|
||||
for (const item of section.items) {
|
||||
if (item.children && isChildActive(item.children, location.pathname)) {
|
||||
setOpenGroup(item.group)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [location.pathname])
|
||||
|
||||
function handleGroupToggle(id) {
|
||||
setOpenGroup(prev => (prev === id ? null : id))
|
||||
}
|
||||
|
||||
function handleSoloClick() {
|
||||
setOpenGroup(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<aside className="flex flex-col bg-primary-800 text-white shrink-0 w-56 h-full sidebar-scroll" data-testid="sidebar">
|
||||
{/* Brand */}
|
||||
<div className="flex items-center px-4 py-4 border-b border-primary-700 shrink-0">
|
||||
<span className="font-bold text-lg tracking-wide">XeniaPOS</span>
|
||||
</div>
|
||||
|
||||
{/* Main nav */}
|
||||
<nav className="flex-1 py-3 px-2 space-y-4">
|
||||
{nav.map(({ section, items }) => (
|
||||
<div key={section}>
|
||||
<div className="flex items-center gap-2 px-3 mb-1.5 select-none" style={{ opacity: 0.45 }}>
|
||||
<span className="text-[9.5px] font-bold uppercase tracking-widest text-primary-100 whitespace-nowrap">
|
||||
{t(section)}
|
||||
</span>
|
||||
<div className="flex-1" style={{ height: 1, background: 'rgba(255,255,255,0.2)' }} />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
{items.map(item =>
|
||||
item.children ? (
|
||||
<GroupItem key={item.group} {...item} openGroup={openGroup} onToggle={handleGroupToggle} />
|
||||
) : (
|
||||
<SoloItem
|
||||
key={item.to}
|
||||
{...item}
|
||||
badge={item.badge === 'onlineOrders' ? pendingCount : undefined}
|
||||
onNavigate={handleSoloClick}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* Divider + bottom items */}
|
||||
<div className="shrink-0 px-2 pb-3 border-t border-primary-700 pt-3 space-y-0.5">
|
||||
{NAV_BOTTOM.filter(item => canSee(item, access)).map(item => (
|
||||
<SoloItem key={item.to} {...item} onNavigate={handleSoloClick} />
|
||||
))}
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
@@ -50,28 +50,28 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
onClick={() => setOpen(o => !o)}
|
||||
className="flex items-center gap-1 text-[13px] text-slate-600 font-medium hover:text-slate-900 transition-colors"
|
||||
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-slate-400 transition-transform ${open ? 'rotate-180' : ''}`} />
|
||||
<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-52 rounded-xl border border-slate-200 bg-white shadow-lg py-1 z-50" role="menu">
|
||||
<div className="absolute right-0 top-full mt-1.5 w-52 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-slate-700 hover:bg-slate-50 transition-colors"
|
||||
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-slate-400" />
|
||||
<User className="h-3.5 w-3.5 text-ink-3" />
|
||||
{t('profile.edit')}
|
||||
</button>
|
||||
|
||||
<div className="my-1 border-t border-slate-100" />
|
||||
<div className="flex items-center gap-2.5 px-3.5 pt-1.5 pb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">
|
||||
<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-[11px] font-semibold uppercase tracking-wide text-ink-3">
|
||||
<Languages className="h-3.5 w-3.5" />
|
||||
{t('profile.language')}
|
||||
</div>
|
||||
@@ -82,18 +82,18 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
|
||||
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-slate-700 hover:bg-slate-50 transition-colors"
|
||||
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-primary-700" />}
|
||||
{lng === language && <Check className="h-3.5 w-3.5 text-accent-ink" />}
|
||||
</button>
|
||||
))}
|
||||
|
||||
<div className="my-1 border-t border-slate-100" />
|
||||
<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-rose-500 hover:bg-rose-50 transition-colors"
|
||||
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')}
|
||||
|
||||
Reference in New Issue
Block a user