// Staff (plan step 6.11; replaces the v1 Management → Staff table): everyone who works here, // with their role, whether they can sign in (blocked or not; PIN, password), what they may do // (permission keys, "custom" when they differ from the role) and their zones. New person, edit // (and photo), a new PIN, a password (KI-014: the password sign-in mode works for everyone now), // zones, permissions, block / unblock, delete (only someone without history). import { useState } from 'react' import { useMutation, useQueryClient } from '@tanstack/react-query' import toast from 'react-hot-toast' import { Ban, CheckCircle2, KeyRound, LockKeyhole, MapPin, Pencil, Plus, Search, ShieldCheck, Trash2, Users } from 'lucide-react' import { useAccess } from '@xenia/access' import { errorMessage } from '@xenia/api' import { useTranslation } from '@xenia/i18n' import { Button, Dialog, EmptyState, IconButton, Input, Select, Spinner, cx } from '@xenia/ui' import client from '../../api/client' import { useLiveQuery } from '../../live/useLiveQuery' import { Avatar, Pill } from '../overview/parts' import PermissionEditor from './PermissionEditor' import SecretDialog from './SecretDialog' import StaffDialog from './StaffDialog' import ZonesDialog from './ZonesDialog' import { GROUPS, ROLES, customKeys, displayName, filterStaff, groupCounts, zonesSummary } from './staffLogic' export default function StaffPage() { const { t } = useTranslation('manager') const qc = useQueryClient() const { user: me } = useAccess() const [filter, setFilter] = useState({ role: '', status: '', q: '' }) const [dialog, setDialog] = useState(null) // { kind: 'new' | 'edit' | 'pin' | 'password' | 'zones' | 'perms' | 'delete', member } const { data: staff, isPending } = useLiveQuery({ queryKey: ['staff'], queryFn: () => client.get('/api/waiters/').then(r => r.data) }) const { data: catalog } = useLiveQuery({ queryKey: ['permission-catalog'], queryFn: () => client.get('/api/waiters/permission-catalog').then(r => r.data), staleTime: 300_000 }) const { data: groups = [] } = useLiveQuery({ queryKey: ['table-groups'], queryFn: () => client.get('/api/tables/groups').then(r => r.data), staleTime: 60_000 }) const changed = () => qc.invalidateQueries({ queryKey: ['staff'] }) const onError = err => toast.error(errorMessage(err, t)) const block = useMutation({ mutationFn: m => client.put(`/api/waiters/${m.id}/block`).then(r => r.data), onSuccess: (r, m) => { toast.success(t(r.is_active ? 'staff.unblocked' : 'staff.blocked', { name: displayName(m) })); changed() }, onError, }) const remove = useMutation({ mutationFn: m => client.delete(`/api/waiters/${m.id}`), onSuccess: (_r, m) => { toast.success(t('staff.deleted', { name: displayName(m) })); setDialog(null); changed() }, onError, }) const set = (k, v) => setFilter(f => ({ ...f, [k]: v })) const shown = filterStaff(staff ?? [], filter) const counts = groupCounts(staff ?? []) const open = (kind, member = null) => setDialog({ kind, member }) return (

{t('staff.title')}

{GROUPS.filter(g => counts[g]).map(g => t(`staff.groups.${g}`, { count: counts[g] })).join(' · ')}

set('status', e.target.value)} aria-label={t('staff.status')} options={[{ value: '', label: t('staff.anyStatus') }, { value: 'active', label: t('staff.active') }, { value: 'blocked', label: t('staff.blockedState') }]} />
{isPending ?
: !shown.length ? } title={t('staff.none')} /> : (
    {shown.map(m => { const support = m.role === 'superadmin' const zones = zonesSummary(m, groups) return (
  • {!m.is_active && {t('staff.blockedState')}} {m.has_password ? t('staff.pinAndPassword') : t('staff.pinOnly')} {!support && ( )} {support && {t('permissions.all')}} {(m.zone_assignments?.length > 0 || m.permissions?.includes('waiter_app.access')) && ( )} {!support && ( open('edit', m)}> open('pin', m)} data-testid="staff-pin"> open('password', m)} data-testid="staff-password"> open('zones', m)}> {m.id !== me?.id && (<> block.mutate(m)} data-testid="staff-block">{m.is_active ? : } open('delete', m)}> )} )}
  • ) })}
)}
{(dialog?.kind === 'new' || dialog?.kind === 'edit') && ( setDialog(null)} onSaved={() => { setDialog(null); changed() }} /> )} {(dialog?.kind === 'pin' || dialog?.kind === 'password') && ( setDialog(null)} onSaved={() => { setDialog(null); changed() }} /> )} {dialog?.kind === 'zones' && setDialog(null)} onSaved={() => { setDialog(null); changed() }} />} {dialog?.kind === 'perms' && { setDialog(null); changed() }} />} {dialog?.kind === 'delete' && ( setDialog(null)} title={t('staff.deleteTitle', { name: displayName(dialog.member) })} description={t('staff.deleteBody')} footer={<> {dialog.member.is_active && } } /> )}
) }