- 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 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]>
278 lines
8.4 KiB
TypeScript
278 lines
8.4 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 [busy, setBusy] = useState(false);
|
|
|
|
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>
|
|
<select className="input" value={contactEmail} onChange={(e) => setContactEmail(e.target.value)}>
|
|
<option value="">— none —</option>
|
|
{contacts.map((c) => (
|
|
<option key={c.email} value={c.email}>
|
|
{c.full_name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<Toggle checked={paid} onChange={setPaid} label="Paid (visible to attendees)" />
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|