Files
Convivo/apps/convivo/src/screens/Connections.tsx
T
0b6d1f2b6f Post-event reporting + talk networking incentives
- Talk networking: per-event talk_networking_bonus awarded when two people
  who shared a checked-in talk accept a connection (accept_connection
  re-created, shared_talk flag, get_talk_cohort RPC, points_log category
  check widened); Convivo Networking sub-tab inside the Connect screen
  (Home quick action deep-links in; Connect button reflects existing
  connection state and is disabled for sent/connected/declined); admin
  Events view bonus input (0-10).
- Reports: sidecar POST /export (CSV / multi-sheet XLSX / PDF report via
  new pdfkit dep); APPE Admin Reports view (any event: on-screen summary,
  session feedback summary, top-5, CSV/Excel/PDF downloads); Activity
  session-feedback per-session aggregate header.
- Also carried: @appe.at admin trigger + default password, bulk contact
  delete, session level/area + event-level feedback, agenda level/area
  filters, admin password self-service, schedule level/area fields.
- 18/18 RPC tests; both apps build; exports verified end-to-end.

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-09-21 22:34:25 +02:00

190 lines
8.2 KiB
TypeScript
Raw 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 { useCallback, useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { acceptConnection, getLeaderboard, getMyConnections, getPublicContacts, rejectConnection } from '../lib/api';
import { usePolling } from '../lib/usePolling';
import { capWords } from '../lib/time';
import type { Connection, PublicContact } from '../lib/types';
import { Avatar, Empty, Sheet, Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
import { NetworkingPanel } from './Networking';
export function Connections({
initialTab = 'mine',
}: {
initialTab?: 'mine' | 'req' | 'networking';
}) {
const { contact } = useAuth();
const [tab, setTab] = useState<'mine' | 'req' | 'networking'>(initialTab);
// A deep-link (e.g. the Home "Networking" quick action) re-targets the tab.
useEffect(() => {
setTab(initialTab);
}, [initialTab]);
const [conns, setConns] = useState<Connection[]>([]);
const [people, setPeople] = useState<Map<string, PublicContact>>(new Map());
const [points, setPoints] = useState<Map<string, number>>(new Map());
const [detail, setDetail] = useState<{ email: string; status: Connection['status'] } | null>(null);
const [loading, setLoading] = useState(true);
const { toast } = useToast();
const load = useCallback(async () => {
try {
const [c, p, lb] = await Promise.all([getMyConnections(), getPublicContacts(), getLeaderboard()]);
setConns(c);
setPeople(new Map(p.map((x) => [x.email, x])));
setPoints(new Map(lb.map((x) => [x.contact_email, x.points])));
} catch {
/* non-fatal */
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
void load();
}, [load]);
// Live-ish updates: poll every 5s while the tab is visible.
usePolling(() => void load(), 5000, !loading);
if (!contact) return null;
const me = contact.email;
const nameOf = (email: string) => people.get(email)?.full_name ?? '…';
const typeOf = (email: string) => people.get(email)?.registration_type ?? null;
const pointsOf = (email: string) => points.get(email) ?? 0;
const accepted = conns.filter((c) => c.status === 'accepted');
const incoming = conns.filter((c) => c.status === 'pending' && c.to_email === me);
const outgoing = conns.filter((c) => c.status === 'pending' && c.from_email === me);
async function resolve(id: string, accept: boolean) {
try {
if (accept) await acceptConnection(id);
else await rejectConnection(id);
toast(accept ? 'Connected! +5 pts 🤝' : 'Request declined', accept ? 'ok' : '');
window.dispatchEvent(new Event('connections-changed'));
await load();
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not update request', 'err');
}
}
if (loading) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
return (
<section className="screen">
<div className="h1">{tab === 'networking' ? 'Networking' : 'Connections'}</div>
<div className="seg">
<button className={tab === 'mine' ? 'active' : ''} data-testid="connections-tab-mine" onClick={() => setTab('mine')}>My connections</button>
<button className={tab === 'req' ? 'active' : ''} data-testid="connections-tab-req" onClick={() => setTab('req')}>
Requests {incoming.length + outgoing.length > 0 && <span className="pill violet" style={{ marginLeft: 4 }}>{incoming.length + outgoing.length}</span>}
</button>
<button className={tab === 'networking' ? 'active' : ''} data-testid="connections-tab-networking" onClick={() => setTab('networking')}>🗣 Networking</button>
</div>
{tab === 'mine' &&
(accepted.length === 0 ? (
<Empty icon="🤝" text="No connections yet. Scan a peer’s lanyard to start one." />
) : (
accepted.map((c) => {
const otherEmail = c.from_email === me ? c.to_email : c.from_email;
return (
<div className="conn clickable" key={c.id} onClick={() => setDetail({ email: otherEmail, status: c.status })}>
<Avatar name={nameOf(otherEmail)} id={otherEmail} size={44} />
<div className="grow">
<div className="name">{nameOf(otherEmail)}</div>
{typeOf(otherEmail) && (
<div className="meta">{capWords(typeOf(otherEmail)!)}</div>
)}
</div>
<span className="pill green">Connected</span>
</div>
);
})
))}
{tab === 'req' && (
<div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
{incoming.length === 0 && outgoing.length === 0 && (
<Empty icon="📭" text="No pending requests." />
)}
{incoming.length > 0 && (
<div>
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Incoming</div>
{incoming.map((c) => (
<div className="conn" key={c.id}>
<div className="clickable" style={{ display: 'flex', alignItems: 'center', gap: 10, flex: 1 }}
onClick={() => setDetail({ email: c.from_email, status: c.status })}>
<Avatar name={nameOf(c.from_email)} id={c.from_email} size={44} />
<div className="grow">
<div className="name">{nameOf(c.from_email)}</div>
{typeOf(c.from_email) && (
<div className="meta">{capWords(typeOf(c.from_email)!)}</div>
)}
</div>
</div>
<button className="btn primary small" data-testid="connection-accept" onClick={() => resolve(c.id, true)}>Accept</button>
<button className="btn small" data-testid="connection-decline" onClick={() => resolve(c.id, false)}>Decline</button>
</div>
))}
</div>
)}
{outgoing.length > 0 && (
<div>
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Sent</div>
{outgoing.map((c) => (
<div className="conn clickable" key={c.id} onClick={() => setDetail({ email: c.to_email, status: c.status })}>
<Avatar name={nameOf(c.to_email)} id={c.to_email} size={44} />
<div className="grow">
<div className="name">{nameOf(c.to_email)}</div>
{typeOf(c.to_email) && (
<div className="meta">{capWords(typeOf(c.to_email)!)}</div>
)}
</div>
<span className="pill amber">Pending</span>
</div>
))}
</div>
)}
</div>
)}
{tab === 'networking' && <NetworkingPanel />}
{detail && (() => {
const p = people.get(detail.email);
const t = p?.registration_type ?? null;
return (
<Sheet open onClose={() => setDetail(null)}>
<div className="center" style={{ flexDirection: 'column', gap: 10, padding: '8px 0 20px' }}>
<Avatar name={p?.full_name ?? '…'} id={detail.email} size={72} />
<div className="h2" style={{ textAlign: 'center' }}>{p?.full_name ?? '…'}</div>
<div className="row" style={{ justifyContent: 'center', gap: 8 }}>
{t && <span className={`pill reg-${t}`}>{capWords(t)}</span>}
<span className="pill violet">⚡ {pointsOf(detail.email)} pts</span>
</div>
{p?.linkedin_url && (
<a className="link" href={p.linkedin_url} target="_blank" rel="noreferrer">
{p.linkedin_url.replace(/^https?:\/\//, '')}
</a>
)}
{p?.show_email && <div className="muted small">{detail.email}</div>}
<div className="muted small">
{detail.status === 'accepted' ? 'Connected' : detail.status === 'pending' ? 'Request pending' : 'Request declined'}
</div>
</div>
</Sheet>
);
})()}
</section>
);
}