// Settings → Operation (plan step 6.14a; was the v1 OperationTab): what each role may do, what the // waiters do by themselves (start / end their shift, see their takings), card payments, how tables // and orders behave (closing, the kitchen screens' serve step, courses, quick notes for lines), // table flags, quick messages to the staff, and sending the digital menu to the cloud now. // Each part shows only with its app on. Dropped from v1: "automatic store schedule" (its switches // were kept in the browser only and nothing ever read them). import { useState } from 'react' import { useMutation } from '@tanstack/react-query' import toast from 'react-hot-toast' import { ArrowDown, ArrowUp, Plus, RefreshCw, Trash2 } from 'lucide-react' import { useModule } from '@xenia/access' import { errorMessage } from '@xenia/api' import { useTranslation } from '@xenia/i18n' import { Button, IconButton, Input, Spinner, Switch } from '@xenia/ui' import client from '../../../api/client' import QuickMessages from './QuickMessages' import RolePermissions from './RolePermissions' import { SettingRow, SettingsCard } from './SettingsCard' import TableFlags from './TableFlags' import { addCourse, cleanNotes, move, nextColour, readJson } from './settingsLogic' import { useSettings } from './useSettings' import { COURSE_COLOURS } from './venueColours' export default function OperationSettings() { const ordering = useModule('ordering') const chat = useModule('chat') const qrMenu = useModule('connect_menu') return (
{ordering && } {ordering && } {chat && } {qrMenu && }
) } function Toggle({ s, k, fallback = 'false', label, hint }) { return ( s.save(k, v)} aria-label={label} data-testid={`setting-${k}`} /> ) } function OrderingSettings() { const { t } = useTranslation('manager') const s = useSettings() if (s.loading) return
const o = k => t(`settings.ops.${k}`) return (<> {s.get('orders.courses_enabled') === 'true' && } ) } /** orders.courses: [{ id, name, color }] in the order they are served. */ function Courses({ s }) { const { t } = useTranslation('manager') const saved = readJson(s.get('orders.courses', '[]'), []) const [names, setNames] = useState({}) // typed names not saved yet, by id const save = next => s.save('orders.courses', JSON.stringify(next)) return (
{saved.map((c, i) => (
))}
) } /** orders.quick_notes: the notes a waiter can add to a line with one tap. */ function QuickNotes({ s }) { const { t } = useTranslation('manager') const notes = readJson(s.get('orders.quick_notes', '[]'), []) const [typed, setTyped] = useState('') const [edits, setEdits] = useState({}) const save = next => s.save('orders.quick_notes', JSON.stringify(cleanNotes(next))) const add = () => { if (typed.trim()) { save([...notes, typed]); setTyped('') } } return (
{t('settings.ops.quickNotes')} {t('settings.ops.quickNotesHint')} {notes.map((n, i) => (
setEdits(x => ({ ...x, [i]: e.target.value }))} onBlur={() => { if (edits[i] != null && edits[i] !== n) save(notes.map((x, j) => (j === i ? edits[i] : x))); setEdits({}) }} /> save(notes.filter((_, j) => j !== i))}>
))}
setTyped(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') add() }} data-testid="quick-note-new" />
) } function MenuSync() { const { t } = useTranslation('manager') const sync = useMutation({ mutationFn: () => client.post('/api/system/sync-menu'), onSuccess: () => toast.success(t('settings.ops.synced')), onError: err => toast.error(errorMessage(err, t)), }) return ( ) }