feat: staff and the schedule on v2; managers give staff passwords (platform-v2 step 6.11, KI-014)
- staff: PUT /api/waiters/{id}/password (set, change, or take away; 6+ chars)
so the password sign-in mode works for everyone; PUT /{id}/pin with the PIN in
the body (was in the address: reset-pin?pin= removed); PINs 4-6 digits when
adding; a password can be given when adding; has_password on staff; editing
clears emptied fields and keeps usernames unique; delete only without history
(orders, items, shifts) and never yourself
- schedule: times checked (schedule.bad_time), one person's overlapping shifts
refused (schedule.overlap, past midnight understood), everyone active can be
scheduled (the kitchen too), changes need core.staff.manage
- manager: src/pages/staff (list with search and filters, person dialog with
photo, PIN / password dialog, zones) and src/pages/schedule (by person, by
hour with opening hours, shift dialog with clash check, view settings kept in
the browser); the never-used "automatic start/close" switches dropped; v1
StaffTab and SchedulePage removed; ApprovalsPage loads with useLiveQuery
- tests: test_staff_v2.py (done-when on a paired screen), staff.test.mjs, e2e
manager.mjs (add, password, sign-in on a paired till, a shift and a clash)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
// The staff page as plain data (plan step 6.11), tested in tests/staff.test.mjs.
|
||||
|
||||
/** The roles in the order the page lists them (backend roles.py); names are i18n `roles.*`. */
|
||||
export const ROLES = ['owner', 'store_manager', 'staff_manager', 'chef', 'assistant_chef', 'barista', 'barman', 'waiter', 'assistant_waiter', 'custom']
|
||||
const GROUP = {
|
||||
superadmin: 'management', owner: 'management', store_manager: 'management', staff_manager: 'management',
|
||||
chef: 'kitchen', assistant_chef: 'kitchen', barista: 'kitchen', barman: 'kitchen',
|
||||
waiter: 'service', assistant_waiter: 'service',
|
||||
}
|
||||
export const GROUPS = ['management', 'kitchen', 'service', 'other']
|
||||
export const groupOf = role => GROUP[role] ?? 'other'
|
||||
|
||||
export const displayName = m => (m ? m.full_name || m.nickname || m.username : '')
|
||||
|
||||
/** How many people in each group (the page's header). */
|
||||
export function groupCounts(staff = []) {
|
||||
const out = Object.fromEntries(GROUPS.map(g => [g, 0]))
|
||||
for (const m of staff) out[groupOf(m.role)] += 1
|
||||
return out
|
||||
}
|
||||
|
||||
const fold = s => String(s ?? '').normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase()
|
||||
|
||||
/** Staff shown for a role ('' = all), a status ('' | 'active' | 'blocked') and a search
|
||||
* (name, nickname, username, phone; accents ignored); active first, then by name. */
|
||||
export function filterStaff(staff = [], { role = '', status = '', q = '' } = {}) {
|
||||
const words = fold(q).split(/\s+/).filter(Boolean)
|
||||
return staff
|
||||
.filter(m => (!role || m.role === role) && (!status || (status === 'active') === !!m.is_active))
|
||||
.filter(m => {
|
||||
if (!words.length) return true
|
||||
const text = fold([m.full_name, m.nickname, m.username, m.mobile_phone].join(' '))
|
||||
return words.every(w => text.includes(w))
|
||||
})
|
||||
.sort((a, b) => Number(!!b.is_active) - Number(!!a.is_active) || displayName(a).localeCompare(displayName(b)))
|
||||
}
|
||||
|
||||
// ── the person's form ───────────────────────────────────────────────────────
|
||||
|
||||
export const EMPTY_STAFF = {
|
||||
full_name: '', nickname: '', username: '', role: 'waiter', mobile_phone: '', email: '', note: '',
|
||||
hourly_rate: '', language: '', pin: '', password: '',
|
||||
}
|
||||
|
||||
export function staffForm(m) {
|
||||
if (!m) return { ...EMPTY_STAFF }
|
||||
const out = { ...EMPTY_STAFF }
|
||||
for (const k of Object.keys(EMPTY_STAFF)) if (m[k] != null && k !== 'pin' && k !== 'password') out[k] = String(m[k])
|
||||
return out
|
||||
}
|
||||
|
||||
export const validPin = pin => /^\d{4,6}$/.test(pin ?? '')
|
||||
export const validPassword = pw => (pw ?? '').length >= 6
|
||||
|
||||
/** The fields that are wrong (empty = fine). A new person needs a PIN; a password is optional. */
|
||||
export function staffProblems(form, isNew) {
|
||||
const out = []
|
||||
if (!form.full_name.trim()) out.push('full_name')
|
||||
if (!form.nickname.trim()) out.push('nickname')
|
||||
if (!/^[^\s]{2,}$/.test(form.username.trim())) out.push('username')
|
||||
const rate = String(form.hourly_rate).trim().replace(',', '.')
|
||||
if (rate && !(Number(rate) >= 0)) out.push('hourly_rate')
|
||||
if (isNew && !validPin(form.pin)) out.push('pin')
|
||||
if (isNew && form.password && !validPassword(form.password)) out.push('password')
|
||||
return out
|
||||
}
|
||||
|
||||
/** POST /api/waiters/ (new) or PUT /api/waiters/{id} (edit). */
|
||||
export function staffBody(form, isNew) {
|
||||
const text = v => (v ?? '').trim() || null
|
||||
const rate = String(form.hourly_rate).trim().replace(',', '.')
|
||||
const body = {
|
||||
full_name: form.full_name.trim(), nickname: form.nickname.trim(), username: form.username.trim(), role: form.role,
|
||||
mobile_phone: text(form.mobile_phone), email: text(form.email), note: text(form.note),
|
||||
hourly_rate: rate ? Number(rate) : null, language: form.language || '',
|
||||
}
|
||||
if (isNew) {
|
||||
body.pin = form.pin
|
||||
body.is_active = true
|
||||
body.language = form.language || null
|
||||
if (form.password) body.password = form.password
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
// ── zones ───────────────────────────────────────────────────────────────────
|
||||
|
||||
/** A person's zones: { all, ids } (all = every zone). */
|
||||
export function zonesOf(member) {
|
||||
const rows = member?.zone_assignments ?? []
|
||||
return { all: rows.some(z => z.group_id == null), ids: rows.map(z => z.group_id).filter(id => id != null) }
|
||||
}
|
||||
|
||||
/** 'all' | 'none' | the zones' names. */
|
||||
export function zonesSummary(member, groups = []) {
|
||||
const { all, ids } = zonesOf(member)
|
||||
if (all) return 'all'
|
||||
if (!ids.length) return 'none'
|
||||
return ids.map(id => groups.find(g => g.id === id)?.name ?? `#${id}`).join(', ')
|
||||
}
|
||||
|
||||
export const zonesBody = ({ all, ids }) => ({ all_zones: all, group_ids: all ? [] : ids })
|
||||
|
||||
/** Does the role's set of keys differ from the person's? (the "custom" mark) */
|
||||
export function customKeys(member, templates) {
|
||||
const role = templates?.[member.role]
|
||||
if (!role || member.role === 'superadmin') return false
|
||||
const a = new Set(member.permissions ?? [])
|
||||
return a.size !== role.length || role.some(k => !a.has(k))
|
||||
}
|
||||
Reference in New Issue
Block a user