// 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 (
)
}
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) => (
))}
} className="justify-self-start" data-testid="course-add"
onClick={() => save(addCourse(saved, COURSE_COLOURS, id => t('settings.ops.courseN', { n: id })))}>{t('settings.ops.addCourse')}
)
}
/** 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 (