Files
3ee91b5ad6 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]>
2026-10-20 22:15:29 +02:00

118 lines
3.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { supabase } from '../lib/supabase';
import { getLeaderboard } from '../lib/api';
import type { LeaderboardRow } from '../lib/types';
import { Avatar, Spinner } from '../components/ui';
/**
* Leaderboard display name: first name + the initial of the last name
* ("Max Muster" → "Max M.") — surnames stay private on a public screen.
*/
function maskedName(fullName: string): string {
const parts = fullName.trim().split(/\s+/).filter(Boolean);
if (parts.length < 2) return parts[0] ?? fullName;
return `${parts[0]} ${parts[parts.length - 1].charAt(0).toUpperCase()}.`;
}
export function Leaderboard() {
const { contact } = useAuth();
const [rows, setRows] = useState<LeaderboardRow[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
let active = true;
(async () => {
try {
const data = await getLeaderboard();
if (active) setRows(data);
} catch {
/* non-fatal */
} finally {
if (active) setLoading(false);
}
})();
// Live updates: re-fetch on any leaderboard change (points are synced
// transactionally by the RPCs, so the table is always consistent).
const channel = supabase
.channel('leaderboard-live')
.on('postgres_changes', { event: '*', schema: 'public', table: 'leaderboard' }, () => {
getLeaderboard().then((d) => active && setRows(d)).catch(() => {});
})
.subscribe();
return () => {
active = false;
supabase.removeChannel(channel);
};
}, []);
if (loading) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
const me = contact?.email;
const top3 = rows.slice(0, 3);
const rest = rows.slice(3);
const myRank = rows.findIndex((r) => r.contact_email === me) + 1;
return (
<section className="screen">
<div className="row between">
<div>
<div className="h1">Leaderboard</div>
<div className="muted small">All attendees · by points</div>
</div>
<span className="pill green">● Live</span>
</div>
{top3.length > 0 && (
<div className="podium">
{[1, 0, 2].map((idx) => {
const r = top3[idx];
if (!r) return <div key={idx} style={{ width: 96 }} />;
const cls = idx === 0 ? 'b1' : idx === 1 ? 'b2' : 'b3';
return (
<div className="pod" key={r.contact_email}>
<div className={`bar ${cls}`}>{r.points}</div>
<div className="pname">{maskedName(r.full_name)}</div>
<div className="ppoints">#{idx + 1}</div>
</div>
);
})}
</div>
)}
<div style={{ display: 'flex', flexDirection: 'column' }}>
{rest.map((r, i) => {
const rank = i + 4;
const isMe = r.contact_email === me;
return (
<div className={`lb-row ${isMe ? 'me' : ''}`} key={r.contact_email}>
<span className="rank">{rank}</span>
<Avatar name={maskedName(r.full_name)} id={r.contact_email} size={38} fs={13} />
<div className="grow">
<div style={{ fontWeight: 700, fontSize: 14 }}>{maskedName(r.full_name)} {isMe && <span className="muted small">(you)</span>}</div>
</div>
<span className="pts">{r.points}</span>
</div>
);
})}
</div>
{myRank > 0 && (
<div className="muted small" style={{ textAlign: 'center', marginTop: 6 }}>
You’re ranked <b>#{myRank}</b> of {rows.length}
</div>
)}
</section>
);
}