- The waiter's --bg/--text/--accent… are made of @xenia/ui tokens: light / dark (user menu) and the venue's accent reach every screen; the 751 colour literals in waiter_pwa/src became tokens (by hue family and lightness), hex-alpha suffixes became fade() (color-mix), fixing 'var(--accent)18' tints that never showed. - @xenia/ui: new `special` (violet: offers, discounts, deals; contrast-tested) and `on-colour` tokens. - Setting venue.theme (teal | amber | blue | violet | rose, default amber), bootstrap venue.theme, manager Settings → Venue → Colour; the waiter sets data-venue-theme and the theme before the first render. - Guard tests/no-colours.test.mjs; tests/e2e/waiter_look.mjs (every page light + dark, side-by-side compare page); waiter e2e +3; backend test_venue_theme.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.8 KiB
JavaScript
42 lines
1.8 KiB
JavaScript
// Venue settings for the v2 settings sections (plan step 2.6f): GET /api/settings/ (all
|
|
// declared keys with their values) and PUT /api/settings/{key} {value} (core.settings.manage;
|
|
// the backend checks types, enums, time zones and languages). Shares the react-query key
|
|
// with the older settings tabs, so both stay in sync.
|
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
import { errorMessage } from '@xenia/api'
|
|
import { useAccess } from '@xenia/access'
|
|
import { useTranslation } from '@xenia/i18n'
|
|
import client from '../../../api/client'
|
|
|
|
/** Keys that change what bootstrap says (language, time zone, sign-in mode): reload it. */
|
|
const BOOTSTRAP_KEYS = new Set(['venue.language', 'venue.timezone', 'venue.theme', 'auth.manager_login_mode', 'security.autofill_username'])
|
|
|
|
export function useSettings() {
|
|
const { t } = useTranslation('manager')
|
|
const qc = useQueryClient()
|
|
const access = useAccess()
|
|
const query = useQuery({
|
|
queryKey: ['pos-settings'],
|
|
queryFn: () => client.get('/api/settings/').then(r => r.data),
|
|
staleTime: 30_000,
|
|
})
|
|
const mutation = useMutation({
|
|
mutationFn: ({ key, value }) => client.put(`/api/settings/${key}`, { value }),
|
|
onSuccess: (_r, { key }) => {
|
|
toast.success(t('settings.saved'))
|
|
qc.invalidateQueries({ queryKey: ['pos-settings'] })
|
|
if (BOOTSTRAP_KEYS.has(key)) access.refresh()
|
|
},
|
|
onError: err => toast.error(errorMessage(err, t)),
|
|
})
|
|
return {
|
|
loading: query.isLoading,
|
|
error: query.error ? errorMessage(query.error, t) : null,
|
|
/** The stored value (strings, as the backend keeps them), or `fallback`. */
|
|
get: (key, fallback = '') => query.data?.[key]?.value ?? fallback,
|
|
save: (key, value) => mutation.mutate({ key, value: String(value) }),
|
|
saving: mutation.isPending,
|
|
}
|
|
}
|