Redesign Phases 3-6: multi-event model, APPE Admin, Convivo App behaviors, APPE branding
- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite - Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views - Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material) - Phase 6: APPE favicon + PWA icons for both apps - Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated
This commit is contained in:
1 parent
5adb5785aa
commit
22f5f1d317
64 files changed
+4593
-1371
No files matched your search
@@ -0,0 +1,430 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { adjustPoints, getAllContacts, resetQrToken, updateContact, upsertContact } from '../lib/api';
|
||||
import type { Contact } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle } from '../components/ui';
|
||||
|
||||
export function Contacts() {
|
||||
const { push } = useToast();
|
||||
const [contacts, setContacts] = useState<Contact[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState('');
|
||||
|
||||
const [editing, setEditing] = useState<Contact | null>(null);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [qrFor, setQrFor] = useState<Contact | null>(null);
|
||||
const [newToken, setNewToken] = useState<string | null>(null);
|
||||
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
setContacts(await getAllContacts());
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!contacts) return [];
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return contacts;
|
||||
return contacts.filter(
|
||||
(c) =>
|
||||
c.full_name.toLowerCase().includes(q) ||
|
||||
c.email.toLowerCase().includes(q) ||
|
||||
(c.linkedin_url ?? '').toLowerCase().includes(q) ||
|
||||
(c.qr_token ?? '').toLowerCase().includes(q),
|
||||
);
|
||||
}, [contacts, query]);
|
||||
|
||||
async function doResetQr(c: Contact) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await resetQrToken(c.email);
|
||||
setNewToken(res.qr_token);
|
||||
setQrFor(c);
|
||||
await load();
|
||||
push('success', `New QR token issued for ${c.full_name}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Reset failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!contacts)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Contacts</h1>
|
||||
<div className="sub">{contacts.length} people · manage contacts, QR tokens, and points.</div>
|
||||
</div>
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<input
|
||||
className="input"
|
||||
style={{ maxWidth: 260 }}
|
||||
placeholder="Search name, email, token…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
<button className="btn primary" onClick={() => setCreating(true)}>
|
||||
+ New contact
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>LinkedIn</th>
|
||||
<th>Visibility</th>
|
||||
<th>Admin</th>
|
||||
<th>QR token</th>
|
||||
<th style={{ textAlign: 'right' }}>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered.map((c) => (
|
||||
<tr key={c.email}>
|
||||
<td>
|
||||
<div className="cell-person">
|
||||
<Avatar name={c.full_name} id={c.email} size={38} fs={13} />
|
||||
<div>
|
||||
<div className="n">{c.full_name}</div>
|
||||
<div className="e">{c.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{c.linkedin_url ? (
|
||||
<a className="muted small" href={c.linkedin_url} target="_blank" rel="noreferrer">
|
||||
linkedin
|
||||
</a>
|
||||
) : (
|
||||
<span className="muted small">—</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<span className="muted small" title="Show email">
|
||||
{c.show_email ? '📧' : '🙈'}
|
||||
</span>
|
||||
<span className="muted small" title="Show LinkedIn">
|
||||
{c.show_linkedin ? '💼' : '🙈'}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{c.is_admin ? <span className="pill admin">admin</span> : <span className="muted small">—</span>}
|
||||
</td>
|
||||
<td>
|
||||
<span className="mono small">{c.qr_token ?? '—'}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div className="row-actions">
|
||||
<button className="btn small" onClick={() => setEditing(c)}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small" onClick={() => { setNewToken(null); setQrFor(c); }}>
|
||||
QR
|
||||
</button>
|
||||
<button className="btn small" onClick={() => setPointsFor(c)}>
|
||||
Points
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{filtered.length === 0 && <div style={{ padding: 16 }}><Empty icon="🔍" text="No matches" /></div>}
|
||||
</div>
|
||||
|
||||
{editing && (
|
||||
<EditContactModal
|
||||
contact={editing}
|
||||
onClose={() => setEditing(null)}
|
||||
onSaved={async (msg) => {
|
||||
setEditing(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{creating && (
|
||||
<CreateContactModal
|
||||
onClose={() => setCreating(false)}
|
||||
onSaved={async (msg) => {
|
||||
setCreating(false);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{qrFor && (
|
||||
<Modal
|
||||
open
|
||||
title={`QR — ${qrFor.full_name}`}
|
||||
onClose={() => setQrFor(null)}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn danger" disabled={busy} onClick={() => doResetQr(qrFor)}>
|
||||
{busy ? 'Resetting…' : 'Reset token'}
|
||||
</button>
|
||||
<button className="btn primary" onClick={() => setQrFor(null)}>
|
||||
Done
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="qr-wrap">
|
||||
{newToken ? (
|
||||
<>
|
||||
<QrImage value={newToken} size={190} />
|
||||
<div className="token-big">{newToken}</div>
|
||||
<p className="muted small">
|
||||
New token issued. The old token no longer works — the person must re-scan.
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<QrImage value={qrFor.qr_token ?? ''} size={190} />
|
||||
<div className="token-big">{qrFor.qr_token ?? '—'}</div>
|
||||
<p className="muted small">Current token. Reset to issue a new one.</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{pointsFor && (
|
||||
<AdjustPointsModal
|
||||
contact={pointsFor}
|
||||
onClose={() => setPointsFor(null)}
|
||||
onSaved={async (msg) => {
|
||||
setPointsFor(null);
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EditContactModal({
|
||||
contact,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
contact: Contact;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(contact.full_name);
|
||||
const [linkedin, setLinkedin] = useState(contact.linkedin_url ?? '');
|
||||
const [showEmail, setShowEmail] = useState(contact.show_email);
|
||||
const [showLinkedin, setShowLinkedin] = useState(contact.show_linkedin);
|
||||
const [isAdmin, setIsAdmin] = useState(contact.is_admin);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await updateContact(contact.email, {
|
||||
full_name: name.trim(),
|
||||
linkedin_url: linkedin.trim() || null,
|
||||
show_email: showEmail,
|
||||
show_linkedin: showLinkedin,
|
||||
is_admin: isAdmin,
|
||||
});
|
||||
onSaved(`Updated ${name.trim()}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Update failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Edit — ${contact.full_name}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !name.trim()} onClick={save}>
|
||||
{busy ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Full name</label>
|
||||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Email</label>
|
||||
<input className="input" value={contact.email} disabled />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>LinkedIn URL</label>
|
||||
<input className="input" value={linkedin} onChange={(e) => setLinkedin(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="row" style={{ gap: 20, flexWrap: 'wrap' }}>
|
||||
<Toggle checked={showEmail} onChange={setShowEmail} label="Show email" />
|
||||
<Toggle checked={showLinkedin} onChange={setShowLinkedin} label="Show LinkedIn" />
|
||||
<Toggle checked={isAdmin} onChange={setIsAdmin} label="Admin / staff" />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateContactModal({
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [email, setEmail] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
const [linkedin, setLinkedin] = useState('');
|
||||
const [isAdmin, setIsAdmin] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
if (!email.trim() || !name.trim()) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await upsertContact({
|
||||
email: email.trim(),
|
||||
full_name: name.trim(),
|
||||
linkedin_url: linkedin.trim() || null,
|
||||
is_admin: isAdmin,
|
||||
});
|
||||
onSaved(`Created ${name.trim()}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Create failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title="New contact"
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !email.trim() || !name.trim()} onClick={save}>
|
||||
{busy ? 'Creating…' : 'Create'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Full name</label>
|
||||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Ana Silva" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Email</label>
|
||||
<input className="input" type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="[email protected]" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>LinkedIn URL</label>
|
||||
<input className="input" value={linkedin} onChange={(e) => setLinkedin(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="row">
|
||||
<Toggle checked={isAdmin} onChange={setIsAdmin} label="Admin / staff" />
|
||||
</div>
|
||||
<p className="muted small">A QR token is generated automatically and becomes the login password.</p>
|
||||
</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);
|
||||
|
||||
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} onClick={save}>
|
||||
{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)} />
|
||||
</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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user