feat(manager): staff permission editor, signed-in sessions, approvals log (platform-v2 2.6e)
- Staff: the 13 perm_* tick columns become one Permissions column (count, "changed from role") opening an editor grouped by module, from /api/waiters/permission-catalog: switches labelled per key, keys you don't hold are disabled with the reason, reset to role defaults (names what it can't give), save the whole set; access.cannot_grant explained by label. - "Signed in now" (/management/sessions): who, where (app or device), since, last active, your own session marked; end session; show ended + reason. - "Manager approvals" (/management/approvals): the override audit with action label, asked by, approved by, device, used/not used, order link. - Backend: sessions list adds device_name/device_app/current/expires_at; overrides list adds device_name/expires_at. - Permission labels for every key in modules.json (en/el), guarded by test_module_texts; manager unit tests for the editor logic; e2e 66 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
// "Manager approvals" (plan step 2.6e, APPS_PLATFORM D-10): the record of every time a
|
||||
// manager typed their PIN to allow one action for someone who lacks the permission (cancel
|
||||
// a sent item, change a price, a discount over the limit…). Backend: GET /api/access/overrides
|
||||
// (core.staff.manage), newest first, the latest 200. Rows are never deleted.
|
||||
// An approval is valid for 60 s, once: "Not used" = it expired before the action happened.
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ShieldCheck } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation, useFormat } from '@xenia/i18n'
|
||||
import { Button, EmptyState, Spinner } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { approvalState, approvalTarget, permLabelKey } from './permissionsLogic'
|
||||
|
||||
const STATE_TONE = {
|
||||
used: 'bg-success-soft text-success-ink',
|
||||
expired: 'bg-surface-2 text-ink-3',
|
||||
waiting: 'bg-info-soft text-info-ink',
|
||||
}
|
||||
|
||||
export default function ApprovalsPage() {
|
||||
const { t } = useTranslation('manager')
|
||||
const f = useFormat()
|
||||
const [rows, setRows] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const r = await client.get('/api/access/overrides')
|
||||
setRows(r.data)
|
||||
setError(null)
|
||||
} catch (err) {
|
||||
setError(errorMessage(err, t))
|
||||
}
|
||||
}, [t])
|
||||
|
||||
useEffect(() => { load() }, [load])
|
||||
|
||||
if (error) return <div className="p-8"><EmptyState title={error} action={<Button variant="secondary" onClick={load}>{t('common:actions.retry')}</Button>} /></div>
|
||||
if (!rows) return <div className="p-8 flex justify-center"><Spinner /></div>
|
||||
|
||||
return (
|
||||
<div className="p-6 lg:p-8 max-w-6xl grid gap-6">
|
||||
<p className="text-body text-ink-2 max-w-2xl">{t('approvals.intro')}</p>
|
||||
{rows.length === 0
|
||||
? <EmptyState icon={<ShieldCheck />} title={t('approvals.empty')} description={t('approvals.emptyBody')} />
|
||||
: (
|
||||
<div className="bg-surface border border-line rounded-card shadow-raised overflow-x-auto">
|
||||
<table className="w-full text-body" data-testid="approvals-table">
|
||||
<thead>
|
||||
<tr className="text-left text-label text-ink-3 border-b border-line">
|
||||
{['when', 'action', 'askedBy', 'approvedBy', 'where', 'result'].map(c => (
|
||||
<th key={c} className="px-4 py-2.5 font-medium">{t(`approvals.columns.${c}`)}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map(r => {
|
||||
const state = approvalState(r)
|
||||
const target = approvalTarget(r.target)
|
||||
return (
|
||||
<tr key={r.id} className="border-b border-line last:border-0" data-testid={`approval-${r.id}`} data-state={state}>
|
||||
<td className="px-4 py-3 text-ink-2 whitespace-nowrap">{f.formatDateTime(r.created_at, 'datetimeShort')}</td>
|
||||
<td className="px-4 py-3 text-ink">{t(permLabelKey(r.key), { defaultValue: r.key })}</td>
|
||||
<td className="px-4 py-3 text-ink-2">{r.requested_by_name || '—'}</td>
|
||||
<td className="px-4 py-3 text-ink-2">{r.approved_by_name || '—'}</td>
|
||||
<td className="px-4 py-3 text-ink-2">{r.device_name || '—'}</td>
|
||||
<td className="px-4 py-3">
|
||||
<span className={`rounded-full px-2.5 py-0.5 text-caption font-medium ${STATE_TONE[state]}`}>{t(`approvals.state.${state}`)}</span>
|
||||
{state === 'used' && target?.order && (
|
||||
<Link to={`/orders/${target.order}`} className="ml-2 text-label text-accent-ink hover:underline">{t('approvals.order', { id: target.order })}</Link>
|
||||
)}
|
||||
{state === 'used' && target?.text && <span className="ml-2 text-caption text-ink-3">{target.text}</span>}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user