Files
Convivo/apps/admin/src/views/Contacts.tsx
T
2f3952dc71 Fixes & Refinements: QR token on registration, role caps, connection detail + red dot, admin schedule/sponsors
Datamodel:
- Move qr_token from contacts to registrations (per event); new migration
  20260826000000. lanyard_lookup / create_connection_request / checkin_attendee
  resolve via registrations + active event.
- reset_qr_token -> reset_registration_qr_token (fixes ambiguous 'email' col).
- upsert_contact drops the token arg; create_registration generates + syncs it.
- Pretix sync writes the token to the registration (keeps it on re-sync).

Registration types:
- Distinct pill colors; red reserved for Staff (both apps).
- Roles capitalized everywhere (Attendee/Speaker/Sponsor/Staff); 'Attendee'
  hidden only at the Home footer.
- Reset-token button moved from Contacts to Registrations (per registration).

Sessions (APPE Admin):
- Slot types capitalized; material submitted/not-submitted state.
- Speaker selection = multi-select search dropdown.
- Fix 'a session must have a speaker' on edit (diff-based setSessionSpeakers)
  and the file-upload bug (speaker save no longer aborts first).

APPE Admin:
- Sponsors contact lookup = search field (filter + pick).

Convivo App:
- Other people's QR codes hidden; connection detail sheet shows public info +
  points.
- Connect red dot recalculates immediately on accept/decline/send.
- 'My picks today' = 2 rows (current + next); 'tap to change' links to Agenda.

Docs updated across backend + frontend.

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-08-23 10:39:21 +02:00

369 lines
11 KiB
TypeScript

import { useEffect, useMemo, useState } from 'react';
import { adjustPoints, getAllContacts, updateContact, upsertContact } from '../lib/api';
import type { Contact } from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Avatar, Empty, Modal, 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 [pointsFor, setPointsFor] = useState<Contact | null>(null);
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),
);
}, [contacts, query]);
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 and points.</div>
</div>
<div className="row" style={{ gap: 10 }}>
<input
className="input"
style={{ maxWidth: 260 }}
placeholder="Search name, email…"
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 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>
<div className="row-actions">
<button className="btn small" onClick={() => setEditing(c)}>
Edit
</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);
}}
/>
)}
{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 when the contact is registered for an event — it 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>
);
}