feat(points): staff auto-connect never scores; event feedback pays +5
- Migration 20261020120000: staff (type staff / Admin / @appe.at) are auto-connected to every participant of the event via connections.auto rows inserted directly as accepted - never through accept_connection, so zero points by construction; backfill + idempotent helper + trigger. - Migration 20261020130000: submit_event_feedback awards +5 on the first submission per participant x event (edits earn 0), gated by _points_eligible; response gains earned column; ACL restored. - Admin: points move from Contacts to Registrations (active-event rows only, in-place save); Dashboard Top points drops emails; Dashboard and Activity hide auto connections. - Attendee: leaderboard masks surnames (Max M.); EventFeedback toast shows +5 pts on paid submissions. - Tests: staff_auto_connections_tests.sql (14 assertions), rpc_tests section 11 (4 assertions). Docs + release record 2026-10-20. - README: document the git-ignored .env provisioning step (missing key = white screen). Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
e243b83a56
commit
3ee91b5ad6
22 files changed
+809
-166
No files matched your search
@@ -52,7 +52,9 @@ export function Activity() {
|
||||
const ss = await getSessions(ev.id);
|
||||
setSessions(ss);
|
||||
setCheckins(ck.filter((x) => x.event_id === ev.id));
|
||||
setConnections(cn.filter((x) => x.event_id === ev.id));
|
||||
// Staff auto-pairings (connections.auto) are bookkeeping, not real
|
||||
// networking — the console only shows hand-made connections.
|
||||
setConnections(cn.filter((x) => x.event_id === ev.id && !x.auto));
|
||||
setFeedback(fb.filter((x) => x.event_id === ev.id));
|
||||
setEventFeedback(efb.filter((x) => x.event_id === ev.id));
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { adjustPoints, deleteContact, getAllContacts, updateContact, upsertContact } from '../lib/api';
|
||||
import { deleteContact, getAllContacts, updateContact, upsertContact } from '../lib/api';
|
||||
import type { Contact } from '../lib/types';
|
||||
import { useSilentRefresh } from '../lib/useSilentRefresh';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
@@ -24,7 +24,6 @@ export function Contacts() {
|
||||
|
||||
const [editing, setEditing] = useState<Contact | null>(null);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
||||
const [deleting, setDeleting] = useState<string | null>(null);
|
||||
|
||||
async function load(silent = false) {
|
||||
@@ -59,7 +58,7 @@ export function Contacts() {
|
||||
// Background pull, paused while a modal is open so nothing re-renders under a
|
||||
// form. Writes here already `await load()`, so no refreshSoon is needed.
|
||||
useSilentRefresh(() => load(true), {
|
||||
enabled: contacts !== null && !editing && !creating && !pointsFor && !deleting,
|
||||
enabled: contacts !== null && !editing && !creating && !deleting,
|
||||
});
|
||||
|
||||
// General search: first name, last name or email address.
|
||||
@@ -106,7 +105,7 @@ export function Contacts() {
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Contacts</h1>
|
||||
<div className="sub">{contacts.length} people · manage contacts and points.</div>
|
||||
<div className="sub">{contacts.length} people · manage contacts.</div>
|
||||
</div>
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<input
|
||||
@@ -172,9 +171,6 @@ export function Contacts() {
|
||||
<button className="btn small" onClick={() => setEditing(c)}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small" onClick={() => setPointsFor(c)}>
|
||||
Points
|
||||
</button>
|
||||
<button
|
||||
className="btn small danger"
|
||||
disabled={deleting === c.email}
|
||||
@@ -214,16 +210,6 @@ export function Contacts() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{pointsFor && (
|
||||
<AdjustPointsModal
|
||||
contact={pointsFor}
|
||||
onClose={() => setPointsFor(null)}
|
||||
onSaved={async (msg) => {
|
||||
setPointsFor(null);
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -365,85 +351,3 @@ function CreateContactModal({
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function AdjustPointsModal({
|
||||
contact,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
contact: Contact;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [delta, setDelta] = useState('10');
|
||||
const [reason, setReason] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
// Mirrors the contact-side half of the SQL predicate `_points_eligible`
|
||||
// (which additionally requires a non-staff registration in the active event).
|
||||
const canEarn = !contact.is_admin && !/@appe\.at$/i.test(contact.email);
|
||||
|
||||
async function save() {
|
||||
const d = parseInt(delta, 10);
|
||||
if (Number.isNaN(d) || d === 0) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await adjustPoints(contact.email, d, reason.trim() || 'manual adjustment');
|
||||
onSaved(`${d > 0 ? '+' : ''}${d} points for ${contact.full_name}`);
|
||||
onClose();
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Adjustment failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Points — ${contact.full_name}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !canEarn} onClick={save} data-testid="adjust-points-apply"
|
||||
title={canEarn ? undefined : 'This contact is excluded from points, so there is nothing to apply'}>
|
||||
{busy ? 'Applying…' : 'Apply'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="row" style={{ justifyContent: 'center', gap: 16 }}>
|
||||
<Avatar name={contact.full_name} id={contact.email} size={52} fs={18} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 700 }}>{contact.full_name}</div>
|
||||
<div className="muted small">{contact.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Adjustment for the active event (use a negative number to subtract)</label>
|
||||
<input className="input mono" type="number" value={delta} onChange={(e) => setDelta(e.target.value)} />
|
||||
{/* _points_eligible needs a registration row in the ACTIVE event; without
|
||||
one the award is a no-op, so the target of the adjustment is worth
|
||||
stating explicitly. */}
|
||||
<span className="muted small">Goes to this person’s pass for the active event — with no pass there, nothing can be awarded.</span>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Reason (optional)</label>
|
||||
<input className="input" value={reason} onChange={(e) => setReason(e.target.value)} placeholder="e.g. prize, correction" />
|
||||
</div>
|
||||
{/* adjust_points routes through _award_points, which no-ops for staff,
|
||||
admin contacts and @appe.at addresses — and returns void, so the call
|
||||
would "succeed" having changed nothing. Say so up front instead of
|
||||
letting the admin believe the score moved. */}
|
||||
{!canEarn && (
|
||||
<p className="pts-exempt-note" data-testid="adjust-points-exempt">
|
||||
This person does not earn points (Admin/staff contact or an @appe.at address), so
|
||||
{delta.trim().startsWith('-') ? ' subtracting' : ' adding'} points changes nothing and they stay off
|
||||
the leaderboard. That is deliberate — change their type in Registrations if it is wrong.
|
||||
</p>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -43,7 +43,9 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
if (cancelledRef.current) return;
|
||||
setContacts(c);
|
||||
setCheckins(ck.filter((x) => x.event_id === ev.id));
|
||||
setConnections(conn.filter((x) => x.event_id === ev.id));
|
||||
// `auto` rows are the staff auto-pairings (migration 20261020120000):
|
||||
// background bookkeeping, not real activity — keep them out of the feed.
|
||||
setConnections(conn.filter((x) => x.event_id === ev.id && !x.auto));
|
||||
setFeedback(f.filter((x) => x.event_id === ev.id));
|
||||
setLb(l.filter((x) => x.event_id === ev.id));
|
||||
setLoaded(true);
|
||||
@@ -172,7 +174,6 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
<Avatar name={r.full_name} id={r.contact_email} size={36} fs={13} />
|
||||
<div className="grow">
|
||||
<div style={{ fontWeight: 700, fontSize: 14 }}>{r.full_name}</div>
|
||||
<div className="muted small">{r.contact_email}</div>
|
||||
</div>
|
||||
<span className="pts">{r.points}</span>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
adjustPoints,
|
||||
createRegistration,
|
||||
deleteContacts,
|
||||
enqueueBadgePrint,
|
||||
@@ -45,6 +46,9 @@ export function Registrations() {
|
||||
const [deletingAll, setDeletingAll] = useState(false);
|
||||
const [mergeFor, setMergeFor] = useState<Registration | null>(null);
|
||||
const [badgeFor, setBadgeFor] = useState<Registration | null>(null);
|
||||
// Points adjustment. It lives here, not in Contacts, because the value sits
|
||||
// on the pass (registrations.points) that this table manages row by row.
|
||||
const [pointsFor, setPointsFor] = useState<Registration | null>(null);
|
||||
const [badgeLayouts, setBadgeLayouts] = useState<BadgeLayout[]>([]);
|
||||
const [printingIds, setPrintingIds] = useState<Set<string>>(new Set());
|
||||
// Rows with a write in flight (check-in toggle or pass-type change). Per-row
|
||||
@@ -472,7 +476,20 @@ export function Registrations() {
|
||||
than showing a bare 0, which reads like a broken
|
||||
check-in. Mirrors the SQL predicate exactly. */}
|
||||
{canEarnPoints(r) ? (
|
||||
<span className="pts">{r.points}</span>
|
||||
<div className="row" style={{ gap: 8, justifyContent: 'flex-end' }}>
|
||||
<span className="pts">{r.points}</span>
|
||||
{event.is_active ? (
|
||||
<button className="btn small" data-testid={`points-adjust-${r.id}`} onClick={() => setPointsFor(r)}>
|
||||
Points
|
||||
</button>
|
||||
) : (
|
||||
<Tooltip title="Only the active event" content="adjust_points always lands on the active event’s pass. Adjusting a different event’s row would silently change the wrong person’s other pass, so points can only be adjusted while the active event is selected.">
|
||||
<button className="btn small" disabled>
|
||||
Points
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<Tooltip title="Does not earn points" content="Staff and organiser accounts (type staff, Admin contacts, or an @appe.at address) are excluded from points and the leaderboard on purpose.">
|
||||
<span className="pts pts-exempt" data-testid={`points-exempt-${r.id}`}>
|
||||
@@ -539,6 +556,28 @@ export function Registrations() {
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{pointsFor && (
|
||||
<AdjustPointsModal
|
||||
registration={pointsFor}
|
||||
contact={byEmail.get(pointsFor.contact_email)}
|
||||
onClose={() => setPointsFor(null)}
|
||||
onSaved={(msg, appliedDelta, ok) => {
|
||||
setPointsFor(null);
|
||||
if (ok && appliedDelta !== null) {
|
||||
// Patch in place — the list is sorted by points, a reload would
|
||||
// slide this row somewhere else mid-edit (same rule as the
|
||||
// check-in toggle). refreshSoon() settles the truth afterwards.
|
||||
const rowId = pointsFor.id;
|
||||
setRegistrations((rows) => rows.map((row) => (row.id === rowId
|
||||
? { ...row, points: Math.max(0, row.points + appliedDelta) }
|
||||
: row)));
|
||||
refreshSoon();
|
||||
}
|
||||
push(ok ? 'success' : 'error', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{badgeFor && (
|
||||
<BadgePreviewModal
|
||||
registration={badgeFor}
|
||||
@@ -786,6 +825,83 @@ function AddRegistrationModal({
|
||||
* 'sponsor' but no sponsor exists for that contact yet. Lets them create the
|
||||
* sponsor (with a contact search) and then retry the type change.
|
||||
*/
|
||||
/**
|
||||
* Adjust one attendee's points, from the row that owns the pass. Mirrors the
|
||||
* old Contacts modal, minus the exemption note: rows that cannot earn points
|
||||
* (_points_eligible mirror) never show the button, and the RPC re-checks the
|
||||
* same predicate server-side. Only offered for the active event —
|
||||
* adjust_points always targets the active event's pass.
|
||||
*/
|
||||
function AdjustPointsModal({
|
||||
registration,
|
||||
contact,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
registration: Registration;
|
||||
contact?: Contact;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string, appliedDelta: number | null, ok: boolean) => void;
|
||||
}) {
|
||||
const [delta, setDelta] = useState('10');
|
||||
const [reason, setReason] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const name = contact?.full_name ?? registration.contact_email;
|
||||
|
||||
async function save() {
|
||||
const d = parseInt(delta, 10);
|
||||
if (Number.isNaN(d) || d === 0) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await adjustPoints(registration.contact_email, d, reason.trim() || 'manual adjustment');
|
||||
onSaved(`${d > 0 ? '+' : ''}${d} points for ${name}`, d, true);
|
||||
onClose();
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Adjustment failed', null, false);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Points — ${name}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy} onClick={save} data-testid="adjust-points-apply">
|
||||
{busy ? 'Applying…' : 'Apply'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="row" style={{ justifyContent: 'center', gap: 16 }}>
|
||||
<Avatar name={name} id={registration.contact_email} size={52} fs={18} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 700 }}>{name}</div>
|
||||
<div className="muted small">{registration.contact_email}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Adjustment (use a negative number to subtract)</label>
|
||||
<input className="input mono" type="number" value={delta} onChange={(e) => setDelta(e.target.value)} />
|
||||
<span className="muted small">
|
||||
Goes to this person’s pass in {registration.qr_token ? `ticket ${registration.qr_token}` : 'this registration'} —
|
||||
the row you opened this from.
|
||||
</span>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Reason (optional)</label>
|
||||
<input className="input" value={reason} onChange={(e) => setReason(e.target.value)} placeholder="e.g. prize, correction" />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function SponsorLookupModal({
|
||||
registration,
|
||||
contact,
|
||||
|
||||
Reference in new issue
Block a user