// The waiters on shift now (plan step 6.2): since when, what they took in, a break in progress; // message one of them, look at their shift, or end it. "Start" puts a waiter without a shift // on one (with the cash they start with) while the day is open. import { useState } from 'react' import toast from 'react-hot-toast' import { BarChart3, Coffee, MessageSquare, Plus } from 'lucide-react' import { errorMessage } from '@xenia/api' import { parseNumber, useFormat, useTranslation } from '@xenia/i18n' import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, cx } from '@xenia/ui' import { Avatar, Card, Money, Pill } from './parts' import { useDuration } from './hooks' export default function ShiftsCard({ shifts, idle, dayOpen, hidden, onStart, onEnd, onStats, onMessage, canMessage }) { const { t } = useTranslation('manager') const { formatTime } = useFormat() const since = useDuration() const [starting, setStarting] = useState(false) return ( 0 && }>
{shifts.length === 0 ? : shifts.map(s => { const onBreak = Array.isArray(s.breaks) ? s.breaks.find(b => !b.ended_at) : null return (
{s.waiter_name} {onBreak && }
{t('overview.shifts.since', { time: formatTime(s.started_at), length: since(s.started_at) })} {s.total_collected > 0 && <> ยท
{canMessage && onMessage(s)}>} onStats(s)} data-testid="shift-stats">
) })}
{starting && setStarting(false)} onStart={onStart} />}
) } function StartShiftDialog({ waiters, onClose, onStart }) { const { t } = useTranslation('manager') const [waiterId, setWaiterId] = useState('') const [cash, setCash] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState(null) async function submit() { if (!waiterId) { setError(t('overview.shifts.pickWaiter')); return } const amount = cash.trim() === '' ? null : parseNumber(cash) if (amount != null && !Number.isFinite(amount)) { setError(t('overview.shifts.badAmount')); return } setBusy(true) try { await onStart(Number(waiterId), amount) onClose() } catch (err) { toast.error(errorMessage(err, t)) } finally { setBusy(false) } } return ( }>
{ setCash(e.target.value); setError(null) }} placeholder="0" />
) }