// Which tables someone serves (plan step 6.11): every zone, or some of them. Their phone and the // table map only show those tables; someone with no zone sees none. import { useState } from 'react' import { useMutation } from '@tanstack/react-query' import toast from 'react-hot-toast' import { errorMessage } from '@xenia/api' import { useTranslation } from '@xenia/i18n' import { Button, Dialog, Switch, cx } from '@xenia/ui' import client from '../../api/client' import { displayName, zonesBody, zonesOf } from './staffLogic' export default function ZonesDialog({ member, groups, onClose, onSaved }) { const { t } = useTranslation('manager') const [zones, setZones] = useState(() => zonesOf(member)) const save = useMutation({ mutationFn: () => client.put(`/api/waiters/${member.id}/zones`, zonesBody(zones)), onSuccess: () => { toast.success(t('staff.zonesSaved', { name: displayName(member) })); onSaved() }, onError: e => toast.error(errorMessage(e, t)), }) const toggle = id => setZones(z => ({ ...z, ids: z.ids.includes(id) ? z.ids.filter(x => x !== id) : [...z.ids, id] })) return ( }>
{!zones.all && ( groups.length === 0 ?

{t('staff.noGroups')}

: (
{groups.map(g => { const on = zones.ids.includes(g.id) return ( ) })}
) )} {!zones.all && !zones.ids.length &&

{t('staff.noZonesWarn')}

}
) }