import { useEffect, useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { getMyPointsLog, updateMyProfile } from '../lib/api'; import { capWords } from '../lib/time'; import type { PointsLogRow } from '../lib/types'; import { Avatar, QrImage, Spinner, Toggle } from '../components/ui'; import { useToast } from '../context/ToastContext'; const CATEGORY_LABEL: Record = { checkin: 'Session check-ins', connection: 'Connections', feedback: 'Feedback', talk_networking: 'Talk networking', admin: 'Other', }; const MANFRED_POSES = ['confident', 'coffee', 'celebrating', 'waving']; export function Profile() { const { contact, registration, signOut, refresh } = useAuth(); const { toast } = useToast(); const [manfredPose] = useState(() => MANFRED_POSES[Math.floor(Math.random() * MANFRED_POSES.length)]); const [log, setLog] = useState([]); const [loading, setLoading] = useState(true); // Profile self-service (LinkedIn + visibility). const [linkedin, setLinkedin] = useState(contact?.linkedin_url ?? ''); const [showEmail, setShowEmail] = useState(contact?.show_email ?? false); const [showLinkedin, setShowLinkedin] = useState(contact?.show_linkedin ?? false); const [saving, setSaving] = useState(false); const email = contact?.email ?? ''; useEffect(() => { let active = true; (async () => { try { const data = await getMyPointsLog(email); if (active) setLog(data); } catch { /* non-fatal */ } finally { if (active) setLoading(false); } })(); return () => { active = false; }; }, [email]); if (!contact) return null; const points = registration?.points ?? 0; const totals: Record = {}; for (const l of log) totals[l.category] = (totals[l.category] ?? 0) + l.delta; async function saveProfile() { setSaving(true); try { await updateMyProfile({ linkedin_url: linkedin.trim() || null, show_email: showEmail, show_linkedin: showLinkedin, }); await refresh(); toast('Profile updated', 'ok'); } catch (e) { toast(e instanceof Error ? e.message : 'Could not save profile', 'err'); } finally { setSaving(false); } } return (
Profile
Manfred
{contact.full_name}
{contact.email}
{registration && {capWords(registration.type)}} {contact.is_admin && registration?.type !== 'staff' && staff} ⚡ {points} pts
My QR code
{registration?.qr_token ? ( ) : (
No QR token assigned.
)}
Show this to staff for session check-in
and to peers to make a connection.
Profile settings
Choose what other attendees can see on your profile.
LinkedIn
setLinkedin(e.target.value)} />
Points breakdown
{loading ? (
) : ( <> {Object.entries(totals).map(([cat, val]) => (
{CATEGORY_LABEL[cat as PointsLogRow['category']] ?? cat} +{val}
))}
Total {points}
)}
); }