Files
Convivo/apps/admin/src/views/Sponsors.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

317 lines
9.8 KiB
TypeScript

import { useEffect, useState } from 'react';
import { deleteSponsor, getAllContacts, getActiveEvent, getSponsors, upsertSponsor } from '../lib/api';
import type { Contact, Event, Sponsor, SponsorType } from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Empty, Modal, Spinner, Toggle, TypeBadge } from '../components/ui';
const SPONSOR_TYPES: SponsorType[] = [
'headline',
'platinum',
'gold',
'silver',
'community',
'swag',
'catering',
'diversity',
];
export function Sponsors() {
const { push } = useToast();
const [event, setEvent] = useState<Event | null>(null);
const [loaded, setLoaded] = useState(false);
const [contacts, setContacts] = useState<Contact[]>([]);
const [sponsors, setSponsors] = useState<Sponsor[]>([]);
const [error, setError] = useState<string | null>(null);
const [editing, setEditing] = useState<Sponsor | null>(null);
const [creating, setCreating] = useState(false);
const [busy, setBusy] = useState(false);
async function load() {
try {
const ev = await getActiveEvent();
setEvent(ev);
if (ev) {
const [c, s] = await Promise.all([getAllContacts(), getSponsors(ev.id)]);
setContacts(c);
setSponsors(s);
}
setLoaded(true);
} catch (e) {
setError(e instanceof Error ? e.message : 'Failed to load');
}
}
useEffect(() => {
load();
}, []);
async function doDelete(s: Sponsor) {
if (!confirm(`Delete sponsor "${s.name}"?`)) return;
setBusy(true);
try {
await deleteSponsor(s.id);
await load();
push('success', `Deleted ${s.name}`);
} catch (e) {
push('error', e instanceof Error ? e.message : 'Delete failed');
} finally {
setBusy(false);
}
}
if (error) return <Empty icon="⚠️" text={error} />;
if (!loaded)
return (
<div className="loading-screen">
<Spinner />
</div>
);
if (!event) {
return (
<div>
<div className="page-head">
<div>
<h1>Sponsors</h1>
<div className="sub">Sponsors for the active event.</div>
</div>
</div>
<div className="card">
<Empty icon="📅" text="No active event. Set an event active in the Events view first." />
</div>
</div>
);
}
const paid = sponsors.filter((s) => s.paid).length;
return (
<div>
<div className="page-head">
<div>
<h1>Sponsors</h1>
<div className="sub">
{event.name} · {sponsors.length} sponsors · {paid} paid. Unpaid sponsors are hidden from attendees.
</div>
</div>
<button className="btn primary" onClick={() => setCreating(true)}>
+ New sponsor
</button>
</div>
<div className="table-wrap">
<table className="data">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Contact</th>
<th>Paid</th>
<th style={{ textAlign: 'right' }}>Amount</th>
<th style={{ textAlign: 'right' }}>Actions</th>
</tr>
</thead>
<tbody>
{sponsors.map((s) => (
<tr key={s.id}>
<td>
<div className="n">{s.name}</div>
{s.email && <div className="e">{s.email}</div>}
</td>
<td>
<TypeBadge type={s.type} />
</td>
<td className="muted small">{s.contact_email ?? '—'}</td>
<td>
<span className={`pill ${s.paid ? 'green' : 'amber'}`}>{s.paid ? 'paid' : 'unpaid'}</span>
</td>
<td style={{ textAlign: 'right' }} className="mono small">
{s.amount_eur != null ? `€${s.amount_eur.toLocaleString()}` : '—'}
</td>
<td>
<div className="row-actions">
<button className="btn small" onClick={() => setEditing(s)}>
Edit
</button>
<button className="btn small danger" disabled={busy} onClick={() => doDelete(s)}>
Delete
</button>
</div>
</td>
</tr>
))}
</tbody>
</table>
{sponsors.length === 0 && <div style={{ padding: 16 }}><Empty icon="🤝" text="No sponsors yet" /></div>}
</div>
{(editing || creating) && (
<SponsorModal
sponsor={editing}
eventId={event.id}
contacts={contacts}
onClose={() => {
setEditing(null);
setCreating(false);
}}
onSaved={async (msg) => {
setEditing(null);
setCreating(false);
await load();
push('success', msg);
}}
/>
)}
</div>
);
}
function SponsorModal({
sponsor,
eventId,
contacts,
onClose,
onSaved,
}: {
sponsor: Sponsor | null;
eventId: string;
contacts: Contact[];
onClose: () => void;
onSaved: (msg: string) => void;
}) {
const [type, setType] = useState<SponsorType>(sponsor?.type ?? 'gold');
const [name, setName] = useState(sponsor?.name ?? '');
const [email, setEmail] = useState(sponsor?.email ?? '');
const [phone, setPhone] = useState(sponsor?.phone ?? '');
const [paid, setPaid] = useState(sponsor?.paid ?? false);
const [amount, setAmount] = useState(sponsor?.amount_eur != null ? String(sponsor.amount_eur) : '');
const [contactEmail, setContactEmail] = useState(sponsor?.contact_email ?? '');
const [contactQuery, setContactQuery] = useState('');
const [busy, setBusy] = useState(false);
const contactMatches = (() => {
const q = contactQuery.trim().toLowerCase();
const list = q
? contacts.filter(
(c) => c.full_name.toLowerCase().includes(q) || c.email.toLowerCase().includes(q),
)
: contacts;
return list.slice(0, 6);
})();
async function save() {
if (!name.trim()) return;
setBusy(true);
try {
await upsertSponsor(sponsor?.id ?? null, {
event_id: eventId,
type,
name: name.trim(),
email: email.trim() || null,
phone: phone.trim() || null,
paid,
amount_eur: amount ? parseFloat(amount) : null,
contact_email: contactEmail || null,
});
onSaved(sponsor ? 'Sponsor updated' : 'Sponsor created');
} catch (e) {
onSaved(e instanceof Error ? e.message : 'Save failed');
} finally {
setBusy(false);
}
}
return (
<Modal
open
title={sponsor ? `Edit — ${sponsor.name}` : 'New sponsor'}
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="grid-2">
<div className="field">
<label>Type</label>
<select className="input" value={type} onChange={(e) => setType(e.target.value as SponsorType)}>
{SPONSOR_TYPES.map((t) => (
<option key={t} value={t}>
{t}
</option>
))}
</select>
</div>
<div className="field">
<label>Name</label>
<input className="input" value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Nubank" />
</div>
</div>
<div className="grid-2">
<div className="field">
<label>Email</label>
<input className="input" type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="—" />
</div>
<div className="field">
<label>Phone</label>
<input className="input" value={phone} onChange={(e) => setPhone(e.target.value)} placeholder="—" />
</div>
</div>
<div className="grid-2">
<div className="field">
<label>Amount (EUR)</label>
<input className="input mono" type="number" value={amount} onChange={(e) => setAmount(e.target.value)} placeholder="—" />
</div>
<div className="field">
<label>Contact (lookup)</label>
{contactEmail ? (
<div className="row" style={{ gap: 8 }}>
<span className="input" style={{ flex: 1, display: 'flex', alignItems: 'center' }}>
{contacts.find((c) => c.email === contactEmail)?.full_name ?? contactEmail}
</span>
<button className="btn small" onClick={() => { setContactEmail(''); setContactQuery(''); }}>
Clear
</button>
</div>
) : (
<>
<input
className="input"
placeholder="Search name or email…"
value={contactQuery}
onChange={(e) => setContactQuery(e.target.value)}
/>
{contactMatches.length > 0 && (
<div className="contact-pick">
{contactMatches.map((c) => (
<button
key={c.email}
className="contact-pick-item"
onClick={() => {
setContactEmail(c.email);
setContactQuery('');
}}
>
<span className="n">{c.full_name}</span>
<span className="e">{c.email}</span>
</button>
))}
</div>
)}
</>
)}
</div>
</div>
<div className="row">
<Toggle checked={paid} onChange={setPaid} label="Paid (visible to attendees)" />
</div>
</Modal>
);
}