- 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).
122 lines
3.7 KiB
TypeScript
122 lines
3.7 KiB
TypeScript
import { useEffect, useState } from 'react';
|
||
import { useAuth } from '../context/AuthContext';
|
||
import { useEvent } from '../lib/useEvent';
|
||
import { getMyEventFeedback, submitEventFeedback } from '../lib/api';
|
||
import { Spinner } from '../components/ui';
|
||
import { useToast } from '../context/ToastContext';
|
||
|
||
/**
|
||
* Event-level feedback (distinct from the per-session Feedback screen).
|
||
* Any registered participant can rate the event overall (1–5) + leave a
|
||
* comment. Idempotent: one row per (event, contact) — re-submitting updates
|
||
* the existing row.
|
||
*/
|
||
export function EventFeedback({ onDone }: { onDone: () => void }) {
|
||
const { contact } = useAuth();
|
||
const { event, loading } = useEvent();
|
||
const [rating, setRating] = useState(0);
|
||
const [comment, setComment] = useState('');
|
||
const [busy, setBusy] = useState(false);
|
||
const [submitted, setSubmitted] = useState(false);
|
||
const { toast } = useToast();
|
||
|
||
// Pre-fill with the user's existing event feedback (if any).
|
||
useEffect(() => {
|
||
let active = true;
|
||
(async () => {
|
||
try {
|
||
const existing = await getMyEventFeedback();
|
||
if (!active || !existing) return;
|
||
setRating(existing.rating);
|
||
setComment(existing.comment ?? '');
|
||
setSubmitted(true);
|
||
} catch {
|
||
/* non-fatal */
|
||
}
|
||
})();
|
||
return () => {
|
||
active = false;
|
||
};
|
||
}, []);
|
||
|
||
if (loading || !event) {
|
||
return (
|
||
<section className="screen no-tab">
|
||
<div className="center" style={{ flex: 1 }}>
|
||
<Spinner />
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
async function submit() {
|
||
if (rating === 0) return;
|
||
setBusy(true);
|
||
try {
|
||
const res = await submitEventFeedback(rating, comment.trim());
|
||
toast(res.earned > 0 ? `Thanks! +${res.earned} pts ⭐` : 'Thanks for your feedback! ⭐', 'ok');
|
||
setSubmitted(true);
|
||
onDone();
|
||
} catch (e) {
|
||
toast(e instanceof Error ? e.message : 'Could not submit feedback', 'err');
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}
|
||
|
||
return (
|
||
<section className="screen no-tab">
|
||
<div className="row" style={{ marginBottom: 14 }}>
|
||
<button className="btn ghost small" onClick={onDone}>← Back</button>
|
||
<div className="grow" style={{ textAlign: 'center' }}>
|
||
<div className="h2">Rate this event</div>
|
||
</div>
|
||
<span style={{ width: 60 }} />
|
||
</div>
|
||
|
||
<div className="card" style={{ textAlign: 'center' }}>
|
||
<div className="h2">{event.name}</div>
|
||
<div className="muted small" style={{ marginTop: 4 }}>
|
||
{event.location ? `${event.location} · ` : ''}
|
||
{event.start_date}
|
||
</div>
|
||
</div>
|
||
|
||
<div className="stars" style={{ justifyContent: 'center', margin: '20px 0' }}>
|
||
{[1, 2, 3, 4, 5].map((n) => (
|
||
<button
|
||
key={n}
|
||
data-testid={`event-feedback-star-${n}`}
|
||
className={`star ${n <= rating ? 'on' : ''}`}
|
||
onClick={() => setRating(n)}
|
||
aria-label={`${n} star${n > 1 ? 's' : ''}`}
|
||
>
|
||
★
|
||
</button>
|
||
))}
|
||
</div>
|
||
|
||
<textarea
|
||
className="input"
|
||
data-testid="event-feedback-comment"
|
||
placeholder="Share your thoughts about the event (optional)"
|
||
value={comment}
|
||
onChange={(e) => setComment(e.target.value)}
|
||
rows={4}
|
||
/>
|
||
|
||
<button
|
||
className="btn primary"
|
||
data-testid="event-feedback-submit"
|
||
disabled={busy || rating === 0}
|
||
onClick={submit}
|
||
>
|
||
{busy ? 'Submitting…' : submitted ? 'Update feedback' : 'Submit feedback'}
|
||
</button>
|
||
<div className="muted small" style={{ textAlign: 'center', marginTop: 8 }}>
|
||
{contact ? `Signing in as ${contact.full_name}` : ''}
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|