feat(manager): the venue's identity (Settings -> Identity): name, slogan, named colours, logos, guest Wi-Fi, contact details

Set once (GET/PUT /api/identity, venue.name + venue.identity); every colour field
offers the venue's colours first (VenueColoursProvider in @xenia/ui); signage screens
get the identity and the venue's time zone with their venue and are told on a change;
logos are protected in the media library; wifiQr() for the join-the-network code.
Plan 6R.14, F-111.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 13:10:58 +02:00
co-authored by Claude Opus 5.5
parent 1c8d45e00c
commit 2a38602d45
25 changed files with 663 additions and 8 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ import { lazy, Suspense } from 'react'
import { useQuery } from '@tanstack/react-query'
import { BrowserRouter, Routes, Route, Navigate, Outlet } from 'react-router-dom'
import { AccessProvider } from '@xenia/access'
import { VenueIdentity } from './shell/VenueIdentity'
import { createI18n } from '@xenia/i18n'
import { Spinner } from '@xenia/ui'
import useAuthStore from './store/authStore'
@@ -110,7 +111,7 @@ function ManagerRoot() {
return (
<AccessProvider client={client} token={token} i18n={i18n} loading={<Loading />}>
<AuthRehydrator>
<Outlet />
<VenueIdentity><Outlet /></VenueIdentity>
</AuthRehydrator>
</AccessProvider>
)
@@ -16,10 +16,12 @@ import SecuritySettings from './sections/SecuritySettings'
import SystemSettings from './sections/SystemSettings'
import TableColours from './sections/TableColours'
import VenueSettings from './sections/VenueSettings'
import IdentitySettings from './sections/IdentitySettings'
const TABS = {
'app-info': () => <SystemSettings />,
venue: () => <VenueSettings />,
identity: () => <IdentitySettings />,
'customer-display': () => <CustomerDisplaySettings />,
'menu-tablets': () => <MenuTabletSettings />,
security: () => <SecuritySettings />,
@@ -0,0 +1,146 @@
// Settings → Identity (6R.14, owner 2026-11-22): the venue's name and slogan, its colours (named),
// logos, guest Wi-Fi and contact details, edited together and saved at once (PUT /api/identity).
// Signage offers the colours first in every colour field and its widgets read the rest; the other
// apps follow it (6R.20) unless they have their own look.
import { useMemo, useState } from 'react'
import toast from 'react-hot-toast'
import { useQueryClient } from '@tanstack/react-query'
import { QRCodeSVG } from 'qrcode.react'
import { Plus, Trash2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useCan } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import { Button, ColourField, Dropdown, Field, IconButton, Input, Spinner, Switch } from '@xenia/ui'
import { wifiQr } from '@xenia/signage/logic'
import client from '../../../api/client'
import MediaField from '../../media/MediaField'
import { IDENTITY_KEY, useIdentity } from '../../../shell/useIdentity'
import { CONTACT, CONTACT_MAX, identityBody, LOGOS, MAX_COLOURS, newColour } from './identityLogic'
import { SettingsCard } from './SettingsCard'
export default function IdentitySettings() {
const { data } = useIdentity()
if (!data) return <div className="py-8 flex justify-center"><Spinner /></div>
return <IdentityForm saved={data} key={JSON.stringify(identityBody(data))} />
}
function IdentityForm({ saved }) {
const { t } = useTranslation('manager')
const qc = useQueryClient()
const canEdit = useCan('core.settings.manage')
const [d, setD] = useState(() => structuredClone(saved))
const [busy, setBusy] = useState(false)
const dirty = useMemo(() => JSON.stringify(identityBody(d)) !== JSON.stringify(identityBody(saved)), [d, saved])
const set = patch => setD(x => ({ ...x, ...patch }))
const setIn = (part, patch) => setD(x => ({ ...x, [part]: { ...(x[part] || {}), ...patch } }))
const colours = d.colours || []
const setColour = (i, patch) => set({ colours: colours.map((c, j) => (j === i ? { ...c, ...patch } : c)) })
const bad = colours.some(c => !(c.name || '').trim())
const save = async () => {
setBusy(true)
try {
const { data: out } = await client.put('/api/identity', identityBody(d))
qc.setQueryData(IDENTITY_KEY, out)
qc.invalidateQueries({ queryKey: ['pos-settings'] })
toast.success(t('identity.saved'))
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
const wifi = d.wifi || {}
const qr = wifiQr(wifi)
return (
<div className="grid gap-5" data-testid="settings-identity">
<div className="flex flex-wrap items-center gap-3">
<p className="text-label text-ink-2 flex-1 min-w-[16rem]">{t('identity.intro')}</p>
{dirty && <span className="text-label text-ink-3">{t('identity.unsaved')}</span>}
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setD(structuredClone(saved))}>{t('identity.undo')}</Button>
<Button loading={busy} disabled={!canEdit || !dirty || bad} onClick={save} data-testid="identity-save">{t('identity.save')}</Button>
</div>
<SettingsCard title={t('identity.name.title')} testId="identity-name">
<div className="p-5 grid gap-4 sm:grid-cols-2">
<Field label={t('identity.name.name')} hint={t('identity.name.nameHint')}>
<Input value={d.name || ''} maxLength={80} onChange={e => set({ name: e.target.value })} data-testid="identity-name-input" />
</Field>
<Field label={t('identity.name.slogan')} hint={t('identity.name.sloganHint')}>
<Input value={d.slogan || ''} maxLength={120} onChange={e => set({ slogan: e.target.value })} data-testid="identity-slogan" />
</Field>
</div>
</SettingsCard>
<SettingsCard title={t('identity.colours.title')} description={t('identity.colours.hint')} testId="identity-colours">
<div className="p-5 grid gap-3">
{colours.length === 0 && <p className="text-label text-ink-3">{t('identity.colours.none')}</p>}
{colours.map((c, i) => (
<div key={i} className="grid gap-3 grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] items-end" data-testid="identity-colour">
<Field label={t('identity.colours.name')} error={!(c.name || '').trim() ? ' ' : undefined}>
<Input value={c.name || ''} maxLength={40} onChange={e => setColour(i, { name: e.target.value })} data-testid="identity-colour-name" />
</Field>
<ColourField label={t('identity.colours.colour')} value={c.colour} onChange={v => setColour(i, { colour: v })} testId={`identity-colour-${i}`} />
<IconButton tone="danger" label={t('identity.colours.remove', { name: c.name || i + 1 })} onClick={() => set({ colours: colours.filter((_, j) => j !== i) })}>
<Trash2 size={16} />
</IconButton>
</div>
))}
<div className="flex items-center gap-3">
<Button variant="secondary" icon={<Plus size={16} />} disabled={colours.length >= MAX_COLOURS} data-testid="identity-colour-add"
onClick={() => set({ colours: [...colours, newColour(colours.length, t('identity.colours.newName', { n: colours.length + 1 }))] })}>
{t('identity.colours.add')}
</Button>
{colours.length >= MAX_COLOURS && <span className="text-caption text-ink-3">{t('identity.colours.max')}</span>}
</div>
</div>
</SettingsCard>
<SettingsCard title={t('identity.logos.title')} description={t('identity.logos.hint')} testId="identity-logos">
<div className="p-5 grid gap-5 sm:grid-cols-2">
{LOGOS.map(k => (
<MediaField key={k} label={t(`identity.logos.${k}`)} value={d.logos?.[k] || null} nameAfter={d.name}
onChange={img => setIn('logos', { [k]: img })} testid={`identity-logo-${k}`} />
))}
</div>
</SettingsCard>
<SettingsCard title={t('identity.wifi.title')} description={t('identity.wifi.hint')} testId="identity-wifi">
<div className="p-5 grid gap-5 md:grid-cols-[minmax(0,1fr)_auto]">
<div className="grid gap-4 sm:grid-cols-2 content-start">
<Field label={t('identity.wifi.ssid')}>
<Input value={wifi.ssid || ''} maxLength={32} onChange={e => setIn('wifi', { ssid: e.target.value })} data-testid="identity-wifi-ssid" />
</Field>
<Field label={t('identity.wifi.password')}>
<Input value={wifi.password || ''} maxLength={63} disabled={wifi.security === 'nopass'} onChange={e => setIn('wifi', { password: e.target.value })} data-testid="identity-wifi-password" />
</Field>
<Field label={t('identity.wifi.security')}>
<Dropdown value={wifi.security || 'WPA'} onChange={v => setIn('wifi', { security: v })} data-testid="identity-wifi-security"
options={['WPA', 'WEP', 'nopass'].map(v => ({ value: v, label: t(`identity.wifi.securities.${v}`) }))} />
</Field>
<Field label={t('identity.wifi.note')} hint={t('identity.wifi.noteHint')}>
<Input value={wifi.note || ''} maxLength={120} onChange={e => setIn('wifi', { note: e.target.value })} />
</Field>
<div className="sm:col-span-2">
<Switch checked={!!wifi.hidden} onChange={v => setIn('wifi', { hidden: v })} label={t('identity.wifi.hidden')} description={t('identity.wifi.hiddenHint')} />
</div>
</div>
{qr && (
<figure className="grid justify-items-center gap-2 content-start" data-testid="identity-wifi-qr" data-qr={qr}>
<div className="rounded-control bg-surface p-2 border border-line"><QRCodeSVG value={qr} size={136} /></div>
<figcaption className="text-caption text-ink-2">{t('identity.wifi.preview')}</figcaption>
</figure>
)}
</div>
</SettingsCard>
<SettingsCard title={t('identity.contact.title')} description={t('identity.contact.hint')} testId="identity-contact">
<div className="p-5 grid gap-4 sm:grid-cols-2">
{CONTACT.map(k => (
<Field key={k} label={t(`identity.contact.${k}`)} className={k === 'address' ? 'sm:col-span-2' : undefined}>
<Input value={d.contact?.[k] || ''} maxLength={CONTACT_MAX[k] || 200}
onChange={e => setIn('contact', { [k]: e.target.value })} data-testid={`identity-contact-${k}`} />
</Field>
))}
</div>
</SettingsCard>
</div>
)
}
@@ -0,0 +1,20 @@
// The identity form's pure helpers (6R.14), unit-tested in tests/identity.test.mjs. The new
// colours' defaults are data (the venue's own colours), so this file is in the colour guard's DATA.
export const LOGOS = ['main', 'light', 'dark', 'icon']
export const CONTACT = ['phone', 'phone2', 'email', 'address', 'website', 'google', 'facebook', 'instagram', 'tiktok', 'tripadvisor', 'whatsapp', 'viber']
export const CONTACT_MAX = { phone: 40, phone2: 40, whatsapp: 40, viber: 40, email: 120, google: 300 } // else 200 (routers/identity.py)
export const MAX_COLOURS = 12
/** A new colour: the first a deep blue, the next ones white (the owner changes them). */
export const newColour = (n, name) => ({ name, colour: n === 0 ? '#1e3a8a' : '#ffffff' })
/** The identity as PUT /api/identity takes it (logos as media ids, empty texts as null). */
export function identityBody(d) {
return {
name: (d.name || '').trim(), slogan: (d.slogan || '').trim() || null,
colours: (d.colours || []).map(c => ({ name: (c.name || '').trim(), colour: c.colour })),
logos: Object.fromEntries(LOGOS.map(k => [k, d.logos?.[k]?.id ?? null])),
wifi: { ssid: d.wifi?.ssid || null, password: d.wifi?.password || null, security: d.wifi?.security || 'WPA', hidden: !!d.wifi?.hidden, note: d.wifi?.note || null },
contact: Object.fromEntries(CONTACT.map(k => [k, (d.contact?.[k] || '').trim() || null])),
}
}
@@ -0,0 +1,9 @@
// The venue's identity in the manager (6R.14): its colours offered first in every colour field
// (VenueColoursProvider of @xenia/ui).
import { VenueColoursProvider } from '@xenia/ui'
import { useIdentity } from './useIdentity'
export function VenueIdentity({ children }) {
const { data } = useIdentity()
return <VenueColoursProvider colours={data?.colours}>{children}</VenueColoursProvider>
}
@@ -0,0 +1,17 @@
// One shared read of the venue's identity (6R.14): GET /api/identity.
import { useQuery } from '@tanstack/react-query'
import { useCan } from '@xenia/access'
import client from '../api/client'
export const IDENTITY_KEY = ['identity']
/** The venue's identity ({ name, slogan, colours, logos, wifi, contact }); data undefined while it loads. */
export function useIdentity() {
const can = useCan('core.dashboard.access')
return useQuery({
queryKey: IDENTITY_KEY,
queryFn: () => client.get('/api/identity').then(r => r.data),
enabled: !!can,
staleTime: 60_000,
})
}