diff --git a/frontend/src/admin.css b/frontend/src/admin.css new file mode 100644 index 0000000..a4b96bd --- /dev/null +++ b/frontend/src/admin.css @@ -0,0 +1,32 @@ +/* Admin dashboard — operator-facing, English-only. Sits on top of the app's tokens; nothing + here is used outside views/Admin.jsx. The page is looked at maybe twice a year, so every + card says what it is for in a sentence and every state is a word, not a colour to decode. */ + +.adm-intro{color:var(--label-2);font-size:14px;line-height:1.45;margin:-6px 0 16px} + +/* one sentence under a card heading that says what the card is for */ +.adm-lead{color:var(--label-2);font-size:13px;line-height:1.45;margin:2px 0 12px} + +/* status pill: a word and a colour, never a paragraph */ +.adm-pill{ + display:inline-flex;align-items:center;gap:6px;padding:3px 10px;border-radius:999px; + font-size:12.5px;font-weight:600;letter-spacing:-.004em;line-height:1.5;white-space:nowrap; + background:var(--surface-2);color:var(--label-2) +} +.adm-pill::before{content:'';width:7px;height:7px;border-radius:50%;background:currentColor;flex:none} +.adm-pill.bad{background:color-mix(in srgb,var(--red) 16%,transparent);color:var(--red)} +.adm-pill.acc{background:var(--acc-soft);color:var(--acc)} + +/* a dim explainer that reads like a sentence, not a footnote */ +.adm-hint{font-size:13px;color:var(--label-2);line-height:1.45;margin:6px 0 10px} + +/* a small heading over a group of rows ("Unused · tap to copy") */ +.adm-group-t{font-size:11.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--label-3);margin:0 0 7px} + +/* an invite code, sized to be tapped and read out loud */ +.adm-code{ + font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-weight:600;letter-spacing:.08em; + background:var(--surface-2);padding:4px 9px;border-radius:8px;font-size:14px +} +.adm-iconbtn{width:44px;height:44px;border-radius:12px;font-size:17px} +.adm-empty{color:var(--label-3);font-size:13.5px;padding:10px 2px} diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx index b7447fc..ae00dcf 100644 --- a/frontend/src/views/Admin.jsx +++ b/frontend/src/views/Admin.jsx @@ -9,20 +9,25 @@ import { workoutVolume, setsDone } from '../lib/history.js' import { confirmSheet } from '../sheets.jsx' import Icon from '../components/Icon.jsx' import { Button } from '../components/ui.jsx' +import '../admin.css' // Admin-only operator dashboard (owner passkey + admin flag; guarded again server-side). // Deliberately English-only — it isn't part of the translated end-user surface, so it stays // out of the per-language string packs. +// +// One page of cards, each opening with a sentence that says what it is for. An operator who +// looks at this twice a year should not have to remember what "synced 3d ago" or an invite +// code means. const rel = ts => { if (!ts) return 'never' const s = Math.max(0, (Date.now() - ts) / 1000) if (s < 60) return 'just now' - if (s < 3600) return Math.floor(s / 60) + 'm ago' - if (s < 86400) return Math.floor(s / 3600) + 'h ago' - return Math.floor(s / 86400) + 'd ago' + if (s < 3600) return Math.floor(s / 60) + ' min ago' + if (s < 86400) return Math.floor(s / 3600) + ' h ago' + return Math.floor(s / 86400) + ' d ago' } -const dur = ms => { const m = Math.max(0, Math.floor(ms / 60000)); return m < 60 ? m + 'm' : Math.floor(m / 60) + 'h' + (m % 60) + 'm' } +const dur = ms => { const m = Math.max(0, Math.floor(ms / 60000)); return m < 60 ? m + ' min' : Math.floor(m / 60) + ' h ' + (m % 60) + ' min' } function UserDetail({ id, onChanged, close }) { const [d, setD] = useState(null) @@ -38,10 +43,10 @@ function UserDetail({ id, onChanged, close }) { return <>

{u.name}

- {u.admin && admin} - {u.disabled && disabled} - {u.invitedBy && invite {u.invitedBy}} - joined {u.created ? fmtDate(u.created.slice(0, 10)) : '—'} + {u.admin && admin} + {u.disabled && disabled} + {u.invitedBy && invite {u.invitedBy}} + joined {u.created ? fmtDate(u.created.slice(0, 10)) : '—'}
Workouts
{d.workouts.length}
@@ -49,10 +54,13 @@ function UserDetail({ id, onChanged, close }) {
Routines
{d.routines.length}
Last sync
{rel(d.lastSync)}
- {!u.admin && } + {!u.admin && <> + +
{u.disabled ? 'Enabling lets them sign in and sync again.' : 'Disabling signs them out everywhere and blocks sign-in. Nothing is deleted.'}
+ }

Workout history

{d.workouts.length ?
{d.workouts.slice(0, 60).map(w =>
@@ -60,32 +68,49 @@ function UserDetail({ id, onChanged, close }) {
{fmtDate(w.d, true)} · {fmtDur((w.end || w.start) - w.start)} · {setsDone(w)} sets{w.prs?.length ? ' · ' + w.prs.length + ' PR' : ''}
{fmtVol(w.vol ?? workoutVolume(w), d.unit)}
)} - :
No workouts logged.
} + :
No workouts logged.
} } -function InvitesCard({ invites, reload }) { +function InvitesCard({ invites, reload, inviteOnly }) { const toast = useUI(s => s.toast) const gen = () => api('/api/admin/invites/new', { method: 'POST', body: '{}' }) .then(({ invite }) => { navigator.clipboard?.writeText(invite.code).catch(() => {}); toast('Code ' + invite.code + ' created & copied'); reload() }) .catch(e => toast(e.message)) - const revoke = code => api('/api/admin/invites/revoke', { method: 'POST', body: JSON.stringify({ code }) }) - .then(() => { toast('Code revoked'); reload() }).catch(e => toast(e.message)) + const revoke = code => confirmSheet({ + title: 'Revoke code ' + code + '?', message: 'Anyone who has it can no longer use it. People who already signed up with it are not affected.', + confirmText: 'Revoke', danger: true, + onConfirm: () => api('/api/admin/invites/revoke', { method: 'POST', body: JSON.stringify({ code }) }) + .then(() => { toast('Code revoked'); reload() }).catch(e => toast(e.message)) + }) + const copy = code => { navigator.clipboard?.writeText(code).catch(() => {}); toast('Copied ' + code) } const open = (invites || []).filter(i => !i.usedBy) const used = (invites || []).filter(i => i.usedBy) return

Invite codes

-
-
{open.length} unused · {used.length} redeemed
- {open.map(i =>
- { navigator.clipboard?.writeText(i.code).catch(() => {}); toast('Copied ' + i.code) }}>{i.code} - -
)} - {used.map(i =>
- {i.code}→ {i.usedByName || 'used'} -
)} - {!open.length && !used.length &&
No codes yet — generate one to invite someone.
} +
+
+ {inviteOnly + ? 'Sign-up is invite-only: someone needs one of these codes to create a profile. Each code works once.' + : 'Sign-up is open, so codes are optional here — they only record who invited whom.'} +
+ {open.length ? <> +
Unused · tap to copy
+ {open.map(i =>
+ +
+ + +
+
)} + : null} + {used.length ? <> +
Already used
+ {used.map(i =>
+ {i.code}→ {i.usedByName || 'used'} +
)} + : null} + {!open.length && !used.length &&
No codes yet. "New code" makes one and copies it to your clipboard.
} } @@ -118,30 +143,31 @@ function AuditCard({ tick }) { return

Activity log

-
-
- {meta ? fmtNum(meta.total) + ' events' - + (meta.retention.days ? ' · last ' + meta.retention.days + ' days' : '') - + (meta.ip_mode === 'off' ? ' · no IP addresses' : '') : 'Loading…'}
+
+
+ Who signed in, what failed, and what an admin changed. + {meta ? ' ' + fmtNum(meta.total) + ' events' + + (meta.retention.days ? ', kept for ' + meta.retention.days + ' days' : '') + + (meta.ip_mode === 'off' ? ', without IP addresses' : '') + '.' : ''} +
{[['', 'All'], ['auth', 'Sign-ins'], ['admin', 'Admin'], ['fail', 'Failed']].map(([v, l]) => )}
{rows.map(e => { const line = auditLine(e) - return
+ return
{line.title} {/* a red pill, not a red row: twenty fumbled Face IDs in a row shouldn't read as an incident */} - {!e.ok && failed} - {auditCat(e.ev) === 'admin' && admin}
+ {!e.ok && failed} + {auditCat(e.ev) === 'admin' && admin}
{line.sub &&
{line.sub}
}
{fmtWhen(e.ts, meta?.now)}
})} - {meta && !rows.length &&
Nothing logged yet.
} + {meta && !rows.length &&
Nothing logged yet.
} {meta?.nextBefore &&
} @@ -175,33 +201,40 @@ export default function Admin() {
{users ? users.length + ' users · ' + activeCount + ' active this week' : 'Loading…'}
+
+ Everything about running this instance: who uses it, how they get in, and what has happened on it. Nothing here shows anyone's training data beyond counts. +
Users
{users ? users.length : '—'}
Training now
{users ? liveUsers.length : '—'}
-
Active 7d
{users ? activeCount : '—'}
+
Active 7 days
{users ? activeCount : '—'}
Disabled
{users ? disabledCount : '—'}
{liveUsers.length > 0 &&
-

Training now

- {liveUsers.map(u =>
openUser(u.id)}> +

Training now

+
Sessions running at this moment. Tap a name for details.
+ {liveUsers.map(u =>
openUser(u.id)}>
{u.name}
-
{u.live.name} · ex {u.live.exIdx}/{u.live.exTotal} · {u.live.setsDone}/{u.live.setsTotal} sets
- {dur(Date.now() - u.live.startedAt)} +
{u.live.name} · exercise {u.live.exIdx} of {u.live.exTotal} · {u.live.setsDone}/{u.live.setsTotal} sets
+ {dur(Date.now() - u.live.startedAt)}
)}
} - + -

Users

-
- {(users || []).map(u =>
openUser(u.id)} style={u.disabled ? { opacity: .55 } : null}> -
{u.live && }{u.name} {u.admin && admin}{u.disabled && off}
-
{u.live ? 'training now · ' + u.live.name : u.workouts + ' workouts' + (u.lastWorkout ? ' · last ' + fmtDate(u.lastWorkout) : '') + ' · synced ' + rel(u.lastSync)}
- {u.hasPush && } -
)} - {users && !users.length &&
No users yet.
} +
+

Users

+
Everyone with a profile on this instance. Tap one to see their activity or to disable the account — their data is never deleted from here.
+
+ {(users || []).map(u =>
openUser(u.id)} style={u.disabled ? { opacity: .55 } : null}> +
{u.live && }{u.name} {u.admin && admin}{u.disabled && disabled}
+
{u.live ? 'training now · ' + u.live.name : u.workouts + ' workouts' + (u.lastWorkout ? ' · last ' + fmtDate(u.lastWorkout) : '') + ' · last sync ' + rel(u.lastSync)}
+ {u.hasPush && } +
)} + {users && !users.length &&
No users yet.
} +