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 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]>
This commit is contained in:
1 parent
2f53d47578
commit
7605c9bbf4
64 files changed
+4593
-1371
No files matched your search
+21
-12
@@ -3,22 +3,28 @@ import { AuthProvider, useAuth } from './context/AuthContext';
|
||||
import { ToastProvider } from './context/ToastContext';
|
||||
import { Login } from './screens/Login';
|
||||
import { Dashboard } from './views/Dashboard';
|
||||
import { Attendees } from './views/Attendees';
|
||||
import { Contacts } from './views/Contacts';
|
||||
import { Registrations } from './views/Registrations';
|
||||
import { Sponsors } from './views/Sponsors';
|
||||
import { Schedule } from './views/Schedule';
|
||||
import { Activity } from './views/Activity';
|
||||
import { Events } from './views/Events';
|
||||
import { Spinner } from './components/ui';
|
||||
|
||||
type View = 'dashboard' | 'attendees' | 'schedule' | 'activity';
|
||||
export type View = 'dashboard' | 'contacts' | 'registrations' | 'sponsors' | 'schedule' | 'activity' | 'events';
|
||||
|
||||
const NAV: { id: View; label: string; ico: string }[] = [
|
||||
{ id: 'dashboard', label: 'Dashboard', ico: '📊' },
|
||||
{ id: 'attendees', label: 'Attendees', ico: '👥' },
|
||||
{ id: 'contacts', label: 'Contacts', ico: '👥' },
|
||||
{ id: 'registrations', label: 'Registrations', ico: '🎟️' },
|
||||
{ id: 'sponsors', label: 'Sponsors', ico: '🤝' },
|
||||
{ id: 'schedule', label: 'Schedule', ico: '🗓️' },
|
||||
{ id: 'activity', label: 'Activity', ico: '⚡' },
|
||||
{ id: 'events', label: 'Events', ico: '📅' },
|
||||
];
|
||||
|
||||
function Shell() {
|
||||
const { profile, loading, signOut } = useAuth();
|
||||
const { contact, loading, signOut } = useAuth();
|
||||
const [view, setView] = useState<View>('dashboard');
|
||||
|
||||
if (loading) {
|
||||
@@ -29,16 +35,16 @@ function Shell() {
|
||||
);
|
||||
}
|
||||
|
||||
if (!profile) return <Login />;
|
||||
if (!contact) return <Login />;
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<aside className="sidebar">
|
||||
<div className="brand">
|
||||
<div className="logo">C</div>
|
||||
<div className="logo">A</div>
|
||||
<div>
|
||||
<div className="name">Convivo</div>
|
||||
<div className="sub">Admin Console</div>
|
||||
<div className="name">APPE</div>
|
||||
<div className="sub">Admin</div>
|
||||
</div>
|
||||
</div>
|
||||
<nav className="nav">
|
||||
@@ -56,7 +62,7 @@ function Shell() {
|
||||
<div className="sidebar-foot">
|
||||
<div className="admin-card">
|
||||
<span className="avatar" style={{ width: 36, height: 36, fontSize: 13, background: '#d50000' }}>
|
||||
{profile.full_name
|
||||
{contact.full_name
|
||||
.split(' ')
|
||||
.map((w) => w[0])
|
||||
.slice(0, 2)
|
||||
@@ -64,8 +70,8 @@ function Shell() {
|
||||
.toUpperCase()}
|
||||
</span>
|
||||
<div className="who">
|
||||
<div className="n">{profile.full_name}</div>
|
||||
<div className="e">{profile.email}</div>
|
||||
<div className="n">{contact.full_name}</div>
|
||||
<div className="e">{contact.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button className="signout" onClick={signOut}>
|
||||
@@ -76,9 +82,12 @@ function Shell() {
|
||||
|
||||
<main className="content">
|
||||
{view === 'dashboard' && <Dashboard onNavigate={setView} />}
|
||||
{view === 'attendees' && <Attendees />}
|
||||
{view === 'contacts' && <Contacts />}
|
||||
{view === 'registrations' && <Registrations />}
|
||||
{view === 'sponsors' && <Sponsors />}
|
||||
{view === 'schedule' && <Schedule />}
|
||||
{view === 'activity' && <Activity />}
|
||||
{view === 'events' && <Events />}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -79,7 +79,28 @@ export function QrImage({ value, size = 180 }: { value: string; size?: number })
|
||||
);
|
||||
}
|
||||
|
||||
/** Small colored badge for a role. */
|
||||
export function RoleBadge({ role }: { role: string }) {
|
||||
return <span className={`pill pill-${role}`}>{role}</span>;
|
||||
/** Small colored badge for a registration / sponsor type. */
|
||||
export function TypeBadge({ type }: { type: string }) {
|
||||
return <span className={`pill pill-${type}`}>{type.replace('_', ' ')}</span>;
|
||||
}
|
||||
|
||||
/** A small on/off toggle switch. */
|
||||
export function Toggle({
|
||||
checked,
|
||||
onChange,
|
||||
label,
|
||||
}: {
|
||||
checked: boolean;
|
||||
onChange: (v: boolean) => void;
|
||||
label?: string;
|
||||
}) {
|
||||
return (
|
||||
<label className="toggle" title={label}>
|
||||
<input type="checkbox" checked={checked} onChange={(e) => onChange(e.target.checked)} />
|
||||
<span className="track">
|
||||
<span className="knob" />
|
||||
</span>
|
||||
{label && <span className="toggle-lbl">{label}</span>}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import type { Profile } from '../lib/types';
|
||||
import type { Contact } from '../lib/types';
|
||||
|
||||
interface AuthState {
|
||||
profile: Profile | null;
|
||||
contact: Contact | null;
|
||||
loading: boolean;
|
||||
signIn: (email: string, qrToken: string) => Promise<void>;
|
||||
signOut: () => Promise<void>;
|
||||
@@ -11,11 +11,23 @@ interface AuthState {
|
||||
|
||||
const AuthContext = createContext<AuthState | null>(null);
|
||||
|
||||
// Load the current user's contact row. Returns null if it doesn't exist or the
|
||||
// contact is not an admin (this is an admin-only app).
|
||||
async function loadAdminContact(email: string): Promise<Contact | null> {
|
||||
const { data } = await supabase
|
||||
.from('contacts')
|
||||
.select('*')
|
||||
.eq('email', email)
|
||||
.maybeSingle();
|
||||
const c = data as Contact | null;
|
||||
return c && c.is_admin ? c : null;
|
||||
}
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [profile, setProfile] = useState<Profile | null>(null);
|
||||
const [contact, setContact] = useState<Contact | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// On mount: restore any existing session and load the profile. If the
|
||||
// On mount: restore any existing session and load the contact. If the
|
||||
// session belongs to a non-admin, sign out immediately (admin-only app).
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
@@ -27,14 +39,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
if (!cancelled) setLoading(false);
|
||||
return;
|
||||
}
|
||||
const { data: prof } = await supabase
|
||||
.from('profiles')
|
||||
.select('*')
|
||||
.eq('id', session.user.id)
|
||||
.maybeSingle();
|
||||
const c = session.user.email ? await loadAdminContact(session.user.email) : null;
|
||||
if (cancelled) return;
|
||||
if (prof && prof.role === 'admin') {
|
||||
setProfile(prof as Profile);
|
||||
if (c) {
|
||||
setContact(c);
|
||||
} else {
|
||||
// Not an admin — clear the session.
|
||||
await supabase.auth.signOut();
|
||||
@@ -46,19 +54,15 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
const { data: sub } = supabase.auth.onAuthStateChange(async (_event, session) => {
|
||||
if (!session) {
|
||||
setProfile(null);
|
||||
setContact(null);
|
||||
return;
|
||||
}
|
||||
const { data: prof } = await supabase
|
||||
.from('profiles')
|
||||
.select('*')
|
||||
.eq('id', session.user.id)
|
||||
.maybeSingle();
|
||||
if (prof && prof.role === 'admin') {
|
||||
setProfile(prof as Profile);
|
||||
const c = session.user.email ? await loadAdminContact(session.user.email) : null;
|
||||
if (c) {
|
||||
setContact(c);
|
||||
} else {
|
||||
await supabase.auth.signOut();
|
||||
setProfile(null);
|
||||
setContact(null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,27 +79,22 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
if (error) throw new Error(error.message);
|
||||
|
||||
const { data: prof } = await supabase
|
||||
.from('profiles')
|
||||
.select('*')
|
||||
.eq('id', data.user.id)
|
||||
.maybeSingle();
|
||||
|
||||
if (!prof || prof.role !== 'admin') {
|
||||
const c = data.user.email ? await loadAdminContact(data.user.email) : null;
|
||||
if (!c) {
|
||||
// Signed in, but not an admin — reject and sign out.
|
||||
await supabase.auth.signOut();
|
||||
throw new Error('This account is not an admin.');
|
||||
}
|
||||
setProfile(prof as Profile);
|
||||
setContact(c);
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
await supabase.auth.signOut();
|
||||
setProfile(null);
|
||||
setContact(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ profile, loading, signIn, signOut }}>
|
||||
<AuthContext.Provider value={{ contact, loading, signIn, signOut }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
|
||||
+165
-18
@@ -2,13 +2,17 @@ import { supabase } from './supabase';
|
||||
import type {
|
||||
Checkin,
|
||||
Connection,
|
||||
Contact,
|
||||
Event,
|
||||
Feedback,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
Profile,
|
||||
Registration,
|
||||
ResetQrResult,
|
||||
Session,
|
||||
SessionSpeaker,
|
||||
Slot,
|
||||
Sponsor,
|
||||
} from './types';
|
||||
|
||||
export class ApiError extends Error {}
|
||||
@@ -29,33 +33,176 @@ async function all<T>(table: string, order?: { col: string; asc?: boolean }): Pr
|
||||
|
||||
// ---- Reads (admin can read all rows via RLS) --------------------------------
|
||||
|
||||
export const getAllProfiles = () => all<Profile>('profiles', { col: 'points', asc: false });
|
||||
export const getAllSlots = () => all<Slot>('slots', { col: 'id' });
|
||||
export const getAllSessions = () => all<Session>('sessions', { col: 'slot_id' });
|
||||
export const getAllContacts = () => all<Contact>('contacts', { col: 'full_name' });
|
||||
export const getAllEvents = () => all<Event>('events', { col: 'start_date', asc: false });
|
||||
export const getActiveEvent = async (): Promise<Event | null> => {
|
||||
const { data, error } = await supabase.from('events').select('*').eq('is_active', true).maybeSingle();
|
||||
if (error) throw new ApiError(error.message);
|
||||
return (data as Event) ?? null;
|
||||
};
|
||||
export const getRegistrations = (eventId: string) =>
|
||||
all<Registration>('registrations', { col: 'points', asc: false }).then((rows) =>
|
||||
rows.filter((r) => r.event_id === eventId),
|
||||
);
|
||||
export const getSponsors = (eventId: string) =>
|
||||
all<Sponsor>('sponsors', { col: 'name' }).then((rows) => rows.filter((s) => s.event_id === eventId));
|
||||
export const getSlots = (eventId: string) =>
|
||||
all<Slot>('slots', { col: 'id' }).then((rows) => rows.filter((s) => s.event_id === eventId));
|
||||
export const getSessions = (eventId: string) =>
|
||||
all<Session>('sessions', { col: 'slot_id' }).then((rows) => rows.filter((s) => s.event_id === eventId));
|
||||
// session_speakers has no event_id; callers filter by the event's session ids.
|
||||
export const getAllSessionSpeakers = () => all<SessionSpeaker>('session_speakers');
|
||||
export const getAllConnections = () => all<Connection>('connections', { col: 'created_at', asc: false });
|
||||
export const getAllCheckins = () => all<Checkin>('checkins', { col: 'created_at', asc: false });
|
||||
export const getAllFeedback = () => all<Feedback>('feedback', { col: 'created_at', asc: false });
|
||||
export const getAllPointsLog = () => all<PointsLogRow>('points_log', { col: 'created_at', asc: false });
|
||||
export const getLeaderboard = () => all<LeaderboardRow>('leaderboard', { col: 'points', asc: false });
|
||||
|
||||
// ---- Writes (admin only) ----------------------------------------------------
|
||||
// ---- Contacts ----------------------------------------------------------------
|
||||
|
||||
/** Update an attendee's editable fields (name, company, role). */
|
||||
export async function updateProfile(
|
||||
id: string,
|
||||
patch: { full_name?: string; company?: string | null; role?: Profile['role'] },
|
||||
export async function upsertContact(input: {
|
||||
email: string;
|
||||
full_name: string;
|
||||
linkedin_url?: string | null;
|
||||
is_admin?: boolean;
|
||||
qr_token?: string | null;
|
||||
}): Promise<Contact> {
|
||||
// upsert_contact returns a single composite row (a JSON object, not an array).
|
||||
return await rpc<Contact>('upsert_contact', {
|
||||
p_email: input.email,
|
||||
p_full_name: input.full_name,
|
||||
p_linkedin_url: input.linkedin_url ?? null,
|
||||
p_is_admin: input.is_admin ?? false,
|
||||
p_qr_token: input.qr_token ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateContact(
|
||||
email: string,
|
||||
patch: Partial<Pick<Contact, 'full_name' | 'linkedin_url' | 'show_email' | 'show_linkedin' | 'is_admin'>>,
|
||||
): Promise<void> {
|
||||
const { error } = await supabase.from('profiles').update(patch).eq('id', id);
|
||||
const { error } = await supabase.from('contacts').update(patch).eq('email', email);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
/** Admin manual points adjustment (audited as 'admin'). */
|
||||
export async function adjustPoints(profileId: string, delta: number, reason: string): Promise<void> {
|
||||
await rpc('adjust_points', { p_profile_id: profileId, p_delta: delta, p_reason: reason });
|
||||
}
|
||||
|
||||
/** Regenerate an attendee's QR token (syncs the auth password, forces re-login). */
|
||||
export async function resetQrToken(profileId: string): Promise<ResetQrResult> {
|
||||
const rows = await rpc<ResetQrResult[]>('reset_qr_token', { p_profile_id: profileId });
|
||||
/** Regenerate a contact's QR token (syncs the auth password, forces re-login). */
|
||||
export async function resetQrToken(email: string): Promise<ResetQrResult> {
|
||||
const rows = await rpc<ResetQrResult[]>('reset_qr_token', { p_contact_email: email });
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
// ---- Registrations -----------------------------------------------------------
|
||||
|
||||
export async function createRegistration(contactEmail: string, type: Registration['type']): Promise<void> {
|
||||
await rpc('create_registration', { p_contact_email: contactEmail, p_type: type });
|
||||
}
|
||||
|
||||
export async function setRegistrationType(contactEmail: string, type: Registration['type']): Promise<void> {
|
||||
await rpc('set_registration_type', { p_contact_email: contactEmail, p_type: type });
|
||||
}
|
||||
|
||||
export async function setCheckedIn(registrationId: string, checkedIn: boolean): Promise<void> {
|
||||
const { error } = await supabase.from('registrations').update({ checked_in: checkedIn }).eq('id', registrationId);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
// ---- Sponsors ----------------------------------------------------------------
|
||||
|
||||
export async function upsertSponsor(
|
||||
id: string | null,
|
||||
input: {
|
||||
event_id: string;
|
||||
type: Sponsor['type'];
|
||||
name: string;
|
||||
email?: string | null;
|
||||
phone?: string | null;
|
||||
paid?: boolean;
|
||||
amount_eur?: number | null;
|
||||
contact_email?: string | null;
|
||||
},
|
||||
): Promise<void> {
|
||||
if (id) {
|
||||
const { error } = await supabase.from('sponsors').update(input).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
} else {
|
||||
const { error } = await supabase.from('sponsors').insert(input);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteSponsor(id: string): Promise<void> {
|
||||
const { error } = await supabase.from('sponsors').delete().eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
// ---- Events ------------------------------------------------------------------
|
||||
|
||||
export async function upsertEvent(
|
||||
id: string | null,
|
||||
input: { name: string; start_date: string; end_date: string; location?: string | null },
|
||||
): Promise<void> {
|
||||
if (id) {
|
||||
const { error } = await supabase.from('events').update(input).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
} else {
|
||||
const { error } = await supabase.from('events').insert(input);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/** Set an event active (deactivates all others via trigger). */
|
||||
export async function activateEvent(id: string): Promise<void> {
|
||||
const { error } = await supabase.from('events').update({ is_active: true }).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
// ---- Points ------------------------------------------------------------------
|
||||
|
||||
/** Admin manual points adjustment for the active event (audited as 'admin'). */
|
||||
export async function adjustPoints(contactEmail: string, delta: number, reason: string): Promise<void> {
|
||||
await rpc('adjust_points', { p_contact_email: contactEmail, p_delta: delta, p_reason: reason });
|
||||
}
|
||||
|
||||
// ---- Sessions: speakers, material, AI feedback -------------------------------
|
||||
|
||||
export async function setSessionSpeakers(sessionId: string, emails: string[]): Promise<void> {
|
||||
// Replace the speaker set: delete all, then insert the new set.
|
||||
const { error: delErr } = await supabase.from('session_speakers').delete().eq('session_id', sessionId);
|
||||
if (delErr) throw new ApiError(delErr.message);
|
||||
if (emails.length > 0) {
|
||||
const rows = emails.map((contact_email) => ({ session_id: sessionId, contact_email }));
|
||||
const { error: insErr } = await supabase.from('session_speakers').insert(rows);
|
||||
if (insErr) throw new ApiError(insErr.message);
|
||||
}
|
||||
}
|
||||
|
||||
/** Upload a session material file to the `materials` bucket and store the path. */
|
||||
export async function uploadSessionMaterial(sessionId: string, file: File): Promise<string> {
|
||||
const path = `sessions/${sessionId}/${Date.now()}-${file.name}`;
|
||||
const { error } = await supabase.storage.from('materials').upload(path, file, { upsert: true });
|
||||
if (error) throw new ApiError(error.message);
|
||||
const { error: upErr } = await supabase.from('sessions').update({ material_path: path }).eq('id', sessionId);
|
||||
if (upErr) throw new ApiError(upErr.message);
|
||||
return path;
|
||||
}
|
||||
|
||||
export async function removeSessionMaterial(sessionId: string): Promise<void> {
|
||||
const { data } = await supabase.from('sessions').select('material_path').eq('id', sessionId).maybeSingle();
|
||||
const path = (data as Session | null)?.material_path;
|
||||
if (path) {
|
||||
await supabase.storage.from('materials').remove([path]);
|
||||
}
|
||||
const { error } = await supabase.from('sessions').update({ material_path: null }).eq('id', sessionId);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
export function sessionMaterialUrl(path: string): string {
|
||||
const { data } = supabase.storage.from('materials').getPublicUrl(path);
|
||||
return data.publicUrl;
|
||||
}
|
||||
|
||||
/** Trigger the (stub) AI feedback evaluation for a session. */
|
||||
export async function evaluateSessionFeedback(sessionId: string): Promise<Session> {
|
||||
// evaluate_session_feedback returns a single composite row (a JSON object, not an array).
|
||||
return await rpc<Session>('evaluate_session_feedback', { p_session_id: sessionId });
|
||||
}
|
||||
+80
-16
@@ -1,18 +1,70 @@
|
||||
export type Role = 'attendee' | 'staff' | 'admin';
|
||||
export type RegistrationType = 'attendee' | 'speaker' | 'staff' | 'sponsor';
|
||||
|
||||
export interface Profile {
|
||||
id: string;
|
||||
export type SponsorType =
|
||||
| 'headline'
|
||||
| 'platinum'
|
||||
| 'gold'
|
||||
| 'silver'
|
||||
| 'community'
|
||||
| 'swag'
|
||||
| 'catering'
|
||||
| 'diversity';
|
||||
|
||||
export type SlotType = 'session' | 'lunch_break' | 'coffee_break' | 'keynote' | 'close_up';
|
||||
|
||||
export interface Contact {
|
||||
email: string;
|
||||
full_name: string;
|
||||
company: string | null;
|
||||
role: Role;
|
||||
linkedin_url: string | null;
|
||||
show_email: boolean;
|
||||
show_linkedin: boolean;
|
||||
is_admin: boolean;
|
||||
qr_token: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Event {
|
||||
id: string;
|
||||
name: string;
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
location: string | null;
|
||||
is_active: boolean;
|
||||
avg_feedback: number | null;
|
||||
num_sessions: number;
|
||||
num_speakers: number;
|
||||
num_registrations: number;
|
||||
num_checked_in_registrations: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Registration {
|
||||
id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
type: RegistrationType;
|
||||
checked_in: boolean;
|
||||
points: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Sponsor {
|
||||
id: string;
|
||||
event_id: string;
|
||||
type: SponsorType;
|
||||
name: string;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
paid: boolean;
|
||||
amount_eur: number | null;
|
||||
contact_email: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Slot {
|
||||
id: number;
|
||||
event_id: string;
|
||||
type: SlotType;
|
||||
name: string;
|
||||
slot_date: string;
|
||||
start_time: string;
|
||||
@@ -21,21 +73,30 @@ export interface Slot {
|
||||
|
||||
export interface Session {
|
||||
id: string;
|
||||
event_id: string;
|
||||
slot_id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
slot_id: number;
|
||||
room: string | null;
|
||||
capacity: number | null;
|
||||
speakers: string | null;
|
||||
average_feedback: number | null;
|
||||
ai_generated_feedback: string | null;
|
||||
material_path: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface SessionSpeaker {
|
||||
session_id: string;
|
||||
contact_email: string;
|
||||
}
|
||||
|
||||
export type ConnectionStatus = 'pending' | 'accepted' | 'rejected';
|
||||
|
||||
export interface Connection {
|
||||
id: string;
|
||||
from_id: string;
|
||||
to_id: string;
|
||||
event_id: string;
|
||||
from_email: string;
|
||||
to_email: string;
|
||||
status: ConnectionStatus;
|
||||
created_at: string;
|
||||
resolved_at: string | null;
|
||||
@@ -43,15 +104,17 @@ export interface Connection {
|
||||
|
||||
export interface Checkin {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
session_id: string;
|
||||
staff_id: string;
|
||||
staff_email: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Feedback {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
session_id: string;
|
||||
rating: number;
|
||||
comment: string | null;
|
||||
@@ -59,22 +122,23 @@ export interface Feedback {
|
||||
}
|
||||
|
||||
export interface LeaderboardRow {
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
full_name: string;
|
||||
company: string | null;
|
||||
points: number;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface PointsLogRow {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
delta: number;
|
||||
category: 'checkin' | 'connection' | 'feedback' | 'admin';
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ResetQrResult {
|
||||
profile_id: string;
|
||||
email: string;
|
||||
qr_token: string;
|
||||
}
|
||||
@@ -31,9 +31,9 @@ export function Login() {
|
||||
<div className="login-wrap">
|
||||
<div className="login-card">
|
||||
<div className="login-brand">
|
||||
<div className="logo">C</div>
|
||||
<div className="logo">A</div>
|
||||
<div>
|
||||
<h1>Convivo Admin</h1>
|
||||
<h1>APPE Admin</h1>
|
||||
<p>Sign in with your admin QR token and email.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -94,6 +94,25 @@ body {
|
||||
.pill.green { background: rgba(5,150,105,.12); border-color: rgba(5,150,105,.35); color: var(--green); }
|
||||
.pill.violet { background: var(--accent-soft); border-color: rgba(213,0,0,.35); color: var(--accent); }
|
||||
.pill.cyan { background: rgba(32,178,170,.13); border-color: rgba(32,178,170,.4); color: #0f766e; }
|
||||
.pill.red { background: rgba(213,0,0,.1); border-color: rgba(213,0,0,.35); color: var(--red); }
|
||||
/* registration types */
|
||||
.pill.speaker { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
|
||||
.pill.sponsor { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
|
||||
/* slot types */
|
||||
.pill.session { background: rgba(14,165,233,.12); border-color: rgba(14,165,233,.4); color: #0369a1; }
|
||||
.pill.lunch_break { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.4); color: #b45309; }
|
||||
.pill.coffee_break { background: rgba(120,113,108,.14); border-color: rgba(120,113,108,.4); color: #57534e; }
|
||||
.pill.keynote { background: var(--accent-soft); border-color: rgba(213,0,0,.35); color: var(--accent); }
|
||||
.pill.close_up { background: rgba(5,150,105,.12); border-color: rgba(5,150,105,.35); color: var(--green); }
|
||||
/* sponsor tiers */
|
||||
.pill.headline { background: rgba(213,0,0,.1); border-color: rgba(213,0,0,.35); color: var(--red); }
|
||||
.pill.platinum { background: rgba(148,163,184,.16); border-color: rgba(148,163,184,.45); color: #475569; }
|
||||
.pill.gold { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.4); color: #b45309; }
|
||||
.pill.silver { background: rgba(148,163,184,.14); border-color: rgba(148,163,184,.4); color: #64748b; }
|
||||
.pill.community { background: rgba(5,150,105,.12); border-color: rgba(5,150,105,.35); color: var(--green); }
|
||||
.pill.swag { background: rgba(219,39,119,.12); border-color: rgba(219,39,119,.4); color: #be185d; }
|
||||
.pill.catering { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
|
||||
.pill.diversity { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
|
||||
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 800; color: #fff; flex-shrink: 0; }
|
||||
.input, select.input {
|
||||
width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
|
||||
@@ -194,6 +213,45 @@ table.data tr:hover td { background: rgba(244,245,249,.6); }
|
||||
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
|
||||
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
|
||||
|
||||
/* ---------- Toggle switch ---------- */
|
||||
.toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
|
||||
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
|
||||
.toggle .track {
|
||||
width: 40px; height: 23px; border-radius: 999px; background: #d5d8e2; position: relative;
|
||||
transition: background .15s; flex-shrink: 0;
|
||||
}
|
||||
.toggle .knob {
|
||||
position: absolute; top: 2.5px; left: 2.5px; width: 18px; height: 18px; border-radius: 50%;
|
||||
background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
|
||||
}
|
||||
.toggle input:checked + .track { background: var(--accent); }
|
||||
.toggle input:checked + .track .knob { transform: translateX(17px); }
|
||||
.toggle-lbl { font-size: 13px; font-weight: 600; color: var(--text); }
|
||||
|
||||
/* ---------- Event card (dashboard) ---------- */
|
||||
.event-card {
|
||||
background: linear-gradient(135deg, rgba(213,0,0,.1), rgba(32,178,170,.08));
|
||||
border: 1px solid rgba(213,0,0,.25); border-radius: 16px; padding: 20px; margin-bottom: 22px;
|
||||
}
|
||||
.event-name { font-size: 22px; font-weight: 900; letter-spacing: -.5px; }
|
||||
|
||||
/* ---------- Speaker picker (schedule) ---------- */
|
||||
.speaker-pick { display: flex; flex-wrap: wrap; gap: 8px; max-height: 220px; overflow-y: auto; padding: 4px; }
|
||||
.speaker-opt {
|
||||
display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px;
|
||||
border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; font-weight: 600;
|
||||
cursor: pointer; transition: all .12s;
|
||||
}
|
||||
.speaker-opt input { accent-color: var(--accent); }
|
||||
.speaker-opt.on { background: var(--accent-soft); border-color: rgba(213,0,0,.4); color: var(--accent); }
|
||||
|
||||
/* ---------- AI feedback box (schedule) ---------- */
|
||||
.ai-box {
|
||||
background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--accent-2);
|
||||
border-radius: 10px; padding: 12px 14px; font-size: 13.5px; line-height: 1.5; color: var(--text);
|
||||
}
|
||||
.ai-state { color: var(--accent-2); font-weight: 600; }
|
||||
|
||||
/* ---------- Toast ---------- */
|
||||
.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 10px; }
|
||||
.toast {
|
||||
|
||||
+175
-124
@@ -1,182 +1,233 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { getAllCheckins, getAllConnections, getAllFeedback, getAllProfiles, getAllSessions } from '../lib/api';
|
||||
import type { Checkin, Connection, Feedback, Profile, Session } from '../lib/types';
|
||||
import {
|
||||
getAllCheckins,
|
||||
getAllConnections,
|
||||
getAllContacts,
|
||||
getAllFeedback,
|
||||
getActiveEvent,
|
||||
getSessions,
|
||||
} from '../lib/api';
|
||||
import type { Checkin, Connection, Contact, Event, Feedback, Session } from '../lib/types';
|
||||
import { Avatar, Empty, Spinner } from '../components/ui';
|
||||
|
||||
type Tab = 'checkins' | 'connections' | 'feedback';
|
||||
|
||||
export function Activity() {
|
||||
const [profiles, setProfiles] = useState<Profile[] | null>(null);
|
||||
const [event, setEvent] = useState<Event | null>(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [tab, setTab] = useState<Tab>('checkins');
|
||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
const [checkins, setCheckins] = useState<Checkin[]>([]);
|
||||
const [connections, setConnections] = useState<Connection[]>([]);
|
||||
const [feedback, setFeedback] = useState<Feedback[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [tab, setTab] = useState<Tab>('checkins');
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const ev = await getActiveEvent();
|
||||
setEvent(ev);
|
||||
const [c, ck, cn, fb] = await Promise.all([
|
||||
getAllContacts(),
|
||||
getAllCheckins(),
|
||||
getAllConnections(),
|
||||
getAllFeedback(),
|
||||
]);
|
||||
setContacts(c);
|
||||
if (ev) {
|
||||
const ss = await getSessions(ev.id);
|
||||
setSessions(ss);
|
||||
setCheckins(ck.filter((x) => x.event_id === ev.id));
|
||||
setConnections(cn.filter((x) => x.event_id === ev.id));
|
||||
setFeedback(fb.filter((x) => x.event_id === ev.id));
|
||||
}
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const [p, s, c, conn, f] = await Promise.all([
|
||||
getAllProfiles(),
|
||||
getAllSessions(),
|
||||
getAllCheckins(),
|
||||
getAllConnections(),
|
||||
getAllFeedback(),
|
||||
]);
|
||||
if (cancelled) return;
|
||||
setProfiles(p);
|
||||
setSessions(s);
|
||||
setCheckins(c);
|
||||
setConnections(conn);
|
||||
setFeedback(f);
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const byId = useMemo(() => new Map((profiles ?? []).map((p) => [p.id, p])), [profiles]);
|
||||
const sessById = useMemo(() => new Map(sessions.map((s) => [s.id, s])), [sessions]);
|
||||
const nameOf = useMemo(() => {
|
||||
const m = new Map(contacts.map((c) => [c.email, c.full_name]));
|
||||
return (email: string) => m.get(email) ?? email;
|
||||
}, [contacts]);
|
||||
|
||||
const sessionTitle = useMemo(() => {
|
||||
const m = new Map(sessions.map((s) => [s.id, s.title]));
|
||||
return (id: string) => m.get(id) ?? id;
|
||||
}, [sessions]);
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!profiles)
|
||||
if (!loaded)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
if (!event) {
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Activity</h1>
|
||||
<div className="sub">Check-ins, connections, and feedback.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<Empty icon="📊" text="No active event. Set an event active in the Events view first." />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Activity</h1>
|
||||
<div className="sub">Check-ins, connections, and feedback.</div>
|
||||
<div className="sub">
|
||||
{event.name} · {checkins.length} check-ins · {connections.length} connections · {feedback.length} feedback.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="seg" style={{ maxWidth: 420, marginBottom: 18 }}>
|
||||
<div className="seg" style={{ marginBottom: 16 }}>
|
||||
<button className={tab === 'checkins' ? 'active' : ''} onClick={() => setTab('checkins')}>
|
||||
Check-ins ({checkins.length})
|
||||
Check-ins
|
||||
</button>
|
||||
<button className={tab === 'connections' ? 'active' : ''} onClick={() => setTab('connections')}>
|
||||
Connections ({connections.length})
|
||||
Connections
|
||||
</button>
|
||||
<button className={tab === 'feedback' ? 'active' : ''} onClick={() => setTab('feedback')}>
|
||||
Feedback ({feedback.length})
|
||||
Feedback
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{tab === 'checkins' && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attendee</th>
|
||||
<th>Session</th>
|
||||
<th>Checked in by</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{checkins.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<PersonCell p={byId.get(c.profile_id)} />
|
||||
</td>
|
||||
<td>{sessById.get(c.session_id)?.title ?? '—'}</td>
|
||||
<td className="muted small">{byId.get(c.staff_id)?.full_name ?? '—'}</td>
|
||||
<td className="muted small">{fmt(c.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{checkins.length === 0 && <div style={{ padding: 16 }}><Empty icon="✅" text="No check-ins yet" /></div>}
|
||||
<div className="card">
|
||||
{checkins.length === 0 ? (
|
||||
<Empty icon="📍" text="No check-ins yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attendee</th>
|
||||
<th>Session</th>
|
||||
<th>Checked in by</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{checkins.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<PersonCell name={nameOf(c.contact_email)} email={c.contact_email} />
|
||||
</td>
|
||||
<td>{sessionTitle(c.session_id)}</td>
|
||||
<td className="muted">{nameOf(c.staff_email)}</td>
|
||||
<td className="muted">{fmt(c.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'connections' && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>To</th>
|
||||
<th>Status</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{connections.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<PersonCell p={byId.get(c.from_id)} />
|
||||
</td>
|
||||
<td>
|
||||
<PersonCell p={byId.get(c.to_id)} />
|
||||
</td>
|
||||
<td>
|
||||
<span className={`pill ${c.status === 'accepted' ? 'green' : c.status === 'rejected' ? 'violet' : 'amber'}`}>
|
||||
{c.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="muted small">{fmt(c.resolved_at ?? c.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{connections.length === 0 && <div style={{ padding: 16 }}><Empty icon="🤝" text="No connections yet" /></div>}
|
||||
<div className="card">
|
||||
{connections.length === 0 ? (
|
||||
<Empty icon="🤝" text="No connections yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>To</th>
|
||||
<th>Status</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{connections.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<PersonCell name={nameOf(c.from_email)} email={c.from_email} />
|
||||
</td>
|
||||
<td>
|
||||
<PersonCell name={nameOf(c.to_email)} email={c.to_email} />
|
||||
</td>
|
||||
<td>
|
||||
<span className={`pill ${c.status === 'accepted' ? 'green' : c.status === 'rejected' ? 'red' : 'amber'}`}>
|
||||
{c.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="muted">{fmt(c.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'feedback' && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attendee</th>
|
||||
<th>Session</th>
|
||||
<th>Rating</th>
|
||||
<th>Comment</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{feedback.map((f) => (
|
||||
<tr key={f.id}>
|
||||
<td>
|
||||
<PersonCell p={byId.get(f.profile_id)} />
|
||||
</td>
|
||||
<td>{sessById.get(f.session_id)?.title ?? '—'}</td>
|
||||
<td>
|
||||
<span className="pill amber">{'★'.repeat(f.rating)}</span>
|
||||
</td>
|
||||
<td className="muted small" style={{ maxWidth: 260 }}>
|
||||
{f.comment ?? '—'}
|
||||
</td>
|
||||
<td className="muted small">{fmt(f.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{feedback.length === 0 && <div style={{ padding: 16 }}><Empty icon="⭐" text="No feedback yet" /></div>}
|
||||
<div className="card">
|
||||
{feedback.length === 0 ? (
|
||||
<Empty icon="⭐" text="No feedback yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Session</th>
|
||||
<th>Rating</th>
|
||||
<th>Comment</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{feedback.map((f) => (
|
||||
<tr key={f.id}>
|
||||
<td>
|
||||
<PersonCell name={nameOf(f.contact_email)} email={f.contact_email} />
|
||||
</td>
|
||||
<td>{sessionTitle(f.session_id)}</td>
|
||||
<td>
|
||||
<span className="pill amber">{'★'.repeat(f.rating)}</span>
|
||||
</td>
|
||||
<td className="muted">{f.comment || '—'}</td>
|
||||
<td className="muted">{fmt(f.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PersonCell({ p }: { p: Profile | undefined }) {
|
||||
if (!p) return <span className="muted small">—</span>;
|
||||
function PersonCell({ name, email }: { name: string; email: string }) {
|
||||
return (
|
||||
<div className="cell-person">
|
||||
<Avatar name={p.full_name} id={p.id} size={32} fs={12} />
|
||||
<div className="n">{p.full_name}</div>
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<Avatar name={name} id={email} size={38} fs={13} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 600, fontSize: 13 }}>{name}</div>
|
||||
<div className="muted small">{email}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,332 +0,0 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { adjustPoints, getAllProfiles, resetQrToken, updateProfile } from '../lib/api';
|
||||
import type { Profile, Role } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Avatar, Empty, Modal, QrImage, RoleBadge, Spinner } from '../components/ui';
|
||||
|
||||
export function Attendees() {
|
||||
const { push } = useToast();
|
||||
const [profiles, setProfiles] = useState<Profile[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState('');
|
||||
|
||||
// Modal state
|
||||
const [editing, setEditing] = useState<Profile | null>(null);
|
||||
const [qrFor, setQrFor] = useState<Profile | null>(null);
|
||||
const [newToken, setNewToken] = useState<string | null>(null);
|
||||
const [pointsFor, setPointsFor] = useState<Profile | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
setProfiles(await getAllProfiles());
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!profiles) return [];
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return profiles;
|
||||
return profiles.filter(
|
||||
(p) =>
|
||||
p.full_name.toLowerCase().includes(q) ||
|
||||
(p.company ?? '').toLowerCase().includes(q) ||
|
||||
p.email.toLowerCase().includes(q) ||
|
||||
(p.qr_token ?? '').toLowerCase().includes(q),
|
||||
);
|
||||
}, [profiles, query]);
|
||||
|
||||
async function doResetQr(p: Profile) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await resetQrToken(p.id);
|
||||
setNewToken(res.qr_token);
|
||||
setQrFor(p);
|
||||
// refresh the list so the token column updates
|
||||
await load();
|
||||
push('success', `New QR token issued for ${p.full_name}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Reset failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!profiles)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Attendees</h1>
|
||||
<div className="sub">{profiles.length} people · manage profiles, QR tokens, and points.</div>
|
||||
</div>
|
||||
<input
|
||||
className="input"
|
||||
style={{ maxWidth: 280 }}
|
||||
placeholder="Search name, company, email, token…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Role</th>
|
||||
<th>QR token</th>
|
||||
<th style={{ textAlign: 'right' }}>Points</th>
|
||||
<th style={{ textAlign: 'right' }}>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered.map((p) => (
|
||||
<tr key={p.id}>
|
||||
<td>
|
||||
<div className="cell-person">
|
||||
<Avatar name={p.full_name} id={p.id} size={38} fs={13} />
|
||||
<div>
|
||||
<div className="n">{p.full_name}</div>
|
||||
<div className="e">{p.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<RoleBadge role={p.role} />
|
||||
</td>
|
||||
<td>
|
||||
<span className="mono small">{p.qr_token ?? '—'}</span>
|
||||
</td>
|
||||
<td style={{ textAlign: 'right' }}>
|
||||
<span className="pts">{p.points}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div className="row-actions">
|
||||
<button className="btn small" onClick={() => setEditing(p)}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small" onClick={() => { setNewToken(null); setQrFor(p); }}>
|
||||
QR
|
||||
</button>
|
||||
<button className="btn small" onClick={() => setPointsFor(p)}>
|
||||
Points
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{filtered.length === 0 && <div style={{ padding: 16 }}><Empty icon="🔍" text="No matches" /></div>}
|
||||
</div>
|
||||
|
||||
{editing && (
|
||||
<EditProfileModal
|
||||
profile={editing}
|
||||
onClose={() => setEditing(null)}
|
||||
onSaved={async (msg) => {
|
||||
setEditing(null);
|
||||
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 attendee 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
|
||||
profile={pointsFor}
|
||||
onClose={() => setPointsFor(null)}
|
||||
onSaved={async (msg) => {
|
||||
setPointsFor(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EditProfileModal({
|
||||
profile,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
profile: Profile;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(profile.full_name);
|
||||
const [company, setCompany] = useState(profile.company ?? '');
|
||||
const [role, setRole] = useState<Role>(profile.role);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await updateProfile(profile.id, {
|
||||
full_name: name.trim(),
|
||||
company: company.trim() || null,
|
||||
role,
|
||||
});
|
||||
onSaved(`Updated ${name.trim()}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Update failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Edit — ${profile.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>Company</label>
|
||||
<input className="input" value={company} onChange={(e) => setCompany(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Role</label>
|
||||
<select className="input" value={role} onChange={(e) => setRole(e.target.value as Role)}>
|
||||
<option value="attendee">attendee</option>
|
||||
<option value="staff">staff</option>
|
||||
<option value="admin">admin</option>
|
||||
</select>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function AdjustPointsModal({
|
||||
profile,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
profile: Profile;
|
||||
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(profile.id, d, reason.trim() || 'manual adjustment');
|
||||
onSaved(`${d > 0 ? '+' : ''}${d} points for ${profile.full_name}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Adjustment failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Points — ${profile.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={profile.full_name} id={profile.id} size={52} fs={18} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 700 }}>{profile.full_name}</div>
|
||||
<div className="muted small">
|
||||
Current: <span className="pts">{profile.points}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Adjustment (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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
getAllCheckins,
|
||||
getAllConnections,
|
||||
getAllContacts,
|
||||
getAllFeedback,
|
||||
getAllProfiles,
|
||||
getAllSessions,
|
||||
getActiveEvent,
|
||||
getLeaderboard,
|
||||
} from '../lib/api';
|
||||
import type { Checkin, Connection, Feedback, LeaderboardRow, Profile, Session } from '../lib/types';
|
||||
import type { Checkin, Connection, Contact, Event, Feedback, LeaderboardRow } from '../lib/types';
|
||||
import { Avatar, Empty, Spinner } from '../components/ui';
|
||||
|
||||
type View = 'dashboard' | 'attendees' | 'schedule' | 'activity';
|
||||
import type { View } from '../App';
|
||||
|
||||
export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
const [profiles, setProfiles] = useState<Profile[] | null>(null);
|
||||
const [event, setEvent] = useState<Event | null>(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||
const [checkins, setCheckins] = useState<Checkin[]>([]);
|
||||
const [connections, setConnections] = useState<Connection[]>([]);
|
||||
const [feedback, setFeedback] = useState<Feedback[]>([]);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
const [lb, setLb] = useState<LeaderboardRow[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@@ -25,21 +25,27 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const [p, c, conn, f, s, l] = await Promise.all([
|
||||
getAllProfiles(),
|
||||
const ev = await getActiveEvent();
|
||||
if (cancelled) return;
|
||||
setEvent(ev);
|
||||
if (!ev) {
|
||||
setLoaded(true);
|
||||
return;
|
||||
}
|
||||
const [c, ck, conn, f, l] = await Promise.all([
|
||||
getAllContacts(),
|
||||
getAllCheckins(),
|
||||
getAllConnections(),
|
||||
getAllFeedback(),
|
||||
getAllSessions(),
|
||||
getLeaderboard(),
|
||||
]);
|
||||
if (cancelled) return;
|
||||
setProfiles(p);
|
||||
setCheckins(c);
|
||||
setConnections(conn);
|
||||
setFeedback(f);
|
||||
setSessions(s);
|
||||
setLb(l);
|
||||
setContacts(c);
|
||||
setCheckins(ck.filter((x) => x.event_id === ev.id));
|
||||
setConnections(conn.filter((x) => x.event_id === ev.id));
|
||||
setFeedback(f.filter((x) => x.event_id === ev.id));
|
||||
setLb(l.filter((x) => x.event_id === ev.id));
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
@@ -49,19 +55,40 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const nameOf = useMemo(() => {
|
||||
const m = new Map(contacts.map((c) => [c.email, c.full_name]));
|
||||
return (email: string) => m.get(email) ?? email;
|
||||
}, [contacts]);
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!profiles)
|
||||
if (!loaded)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
const attendees = profiles.filter((p) => p.role === 'attendee');
|
||||
const accepted = connections.filter((c) => c.status === 'accepted').length;
|
||||
const avgRating = feedback.length
|
||||
? (feedback.reduce((s, f) => s + f.rating, 0) / feedback.length).toFixed(1)
|
||||
: '—';
|
||||
if (!event) {
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Dashboard</h1>
|
||||
<div className="sub">Live overview of the event.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<Empty icon="📅" text="No active event. Create one and set it active in the Events view." />
|
||||
<div style={{ textAlign: 'center', marginTop: 12 }}>
|
||||
<button className="btn primary" onClick={() => onNavigate('events')}>
|
||||
Go to Events →
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const top = lb.slice(0, 5);
|
||||
|
||||
return (
|
||||
@@ -69,35 +96,49 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Dashboard</h1>
|
||||
<div className="sub">Live overview of the event.</div>
|
||||
<div className="sub">Live overview of the active event.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card event-card">
|
||||
<div className="row between" style={{ flexWrap: 'wrap', gap: 12 }}>
|
||||
<div>
|
||||
<div className="event-name">{event.name}</div>
|
||||
<div className="muted small">
|
||||
{fmtDate(event.start_date)}
|
||||
{event.end_date !== event.start_date ? ` – ${fmtDate(event.end_date)}` : ''}
|
||||
{event.location ? ` · ${event.location}` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<span className="pill green">● Active</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="stat-grid">
|
||||
<div className="stat">
|
||||
<span className="ico">👥</span>
|
||||
<span className="val">{attendees.length}</span>
|
||||
<span className="lbl">Attendees</span>
|
||||
<span className="ico">🎟️</span>
|
||||
<span className="val">{event.num_registrations}</span>
|
||||
<span className="lbl">Registrations</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<span className="ico">✅</span>
|
||||
<span className="val">{checkins.length}</span>
|
||||
<span className="lbl">Check-ins</span>
|
||||
<span className="val">{event.num_checked_in_registrations}</span>
|
||||
<span className="lbl">Checked in</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<span className="ico">🤝</span>
|
||||
<span className="val">{accepted}</span>
|
||||
<span className="lbl">Connections accepted</span>
|
||||
<span className="ico">🗓️</span>
|
||||
<span className="val">{event.num_sessions}</span>
|
||||
<span className="lbl">Sessions</span>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<span className="ico">⭐</span>
|
||||
<span className="val">{avgRating}</span>
|
||||
<span className="lbl">Avg. session rating</span>
|
||||
<span className="ico">🎤</span>
|
||||
<span className="val">{event.num_speakers}</span>
|
||||
<span className="lbl">Speakers</span>
|
||||
</div>
|
||||
<div className="stat accent">
|
||||
<span className="ico">🏆</span>
|
||||
<span className="val">{sessions.length}</span>
|
||||
<span className="lbl">Sessions scheduled</span>
|
||||
<span className="ico">⭐</span>
|
||||
<span className="val">{event.avg_feedback != null ? event.avg_feedback.toFixed(1) : '—'}</span>
|
||||
<span className="lbl">Avg. feedback</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -105,7 +146,7 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
<div className="card">
|
||||
<div className="row between" style={{ marginBottom: 14 }}>
|
||||
<h2 className="h2">🏆 Top points</h2>
|
||||
<button className="btn small ghost" onClick={() => onNavigate('attendees')}>
|
||||
<button className="btn small ghost" onClick={() => onNavigate('registrations')}>
|
||||
View all →
|
||||
</button>
|
||||
</div>
|
||||
@@ -114,12 +155,12 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
{top.map((r, i) => (
|
||||
<div key={r.profile_id} className="row" style={{ gap: 12 }}>
|
||||
<div key={r.contact_email} className="row" style={{ gap: 12 }}>
|
||||
<span style={{ width: 22, fontWeight: 900, color: 'var(--muted)' }}>{i + 1}</span>
|
||||
<Avatar name={r.full_name} id={r.profile_id} size={36} fs={13} />
|
||||
<Avatar name={r.full_name} id={r.contact_email} size={36} fs={13} />
|
||||
<div className="grow">
|
||||
<div style={{ fontWeight: 700, fontSize: 14 }}>{r.full_name}</div>
|
||||
{r.company && <div className="muted small">{r.company}</div>}
|
||||
<div className="muted small">{r.contact_email}</div>
|
||||
</div>
|
||||
<span className="pts">{r.points}</span>
|
||||
</div>
|
||||
@@ -135,7 +176,7 @@ export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||||
View all →
|
||||
</button>
|
||||
</div>
|
||||
<ActivityFeed checkins={checkins} connections={connections} feedback={feedback} profiles={profiles} limit={6} />
|
||||
<ActivityFeed checkins={checkins} connections={connections} feedback={feedback} nameOf={nameOf} limit={6} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -146,34 +187,34 @@ function ActivityFeed({
|
||||
checkins,
|
||||
connections,
|
||||
feedback,
|
||||
profiles,
|
||||
nameOf,
|
||||
limit,
|
||||
}: {
|
||||
checkins: Checkin[];
|
||||
connections: Connection[];
|
||||
feedback: Feedback[];
|
||||
profiles: Profile[];
|
||||
nameOf: (email: string) => string;
|
||||
limit: number;
|
||||
}) {
|
||||
const byId = new Map(profiles.map((p) => [p.id, p]));
|
||||
type Item = { at: string; icon: string; text: string };
|
||||
const name = (email: string) => nameOf(email);
|
||||
const items: Item[] = [
|
||||
...checkins.map((c) => ({
|
||||
at: c.created_at,
|
||||
icon: '✅',
|
||||
text: `${byId.get(c.profile_id)?.full_name ?? 'Someone'} checked in`,
|
||||
text: `${name(c.contact_email)} checked in`,
|
||||
})),
|
||||
...connections
|
||||
.filter((c) => c.status === 'accepted')
|
||||
.map((c) => ({
|
||||
at: c.resolved_at ?? c.created_at,
|
||||
icon: '🤝',
|
||||
text: `${byId.get(c.from_id)?.full_name ?? 'Someone'} connected with ${byId.get(c.to_id)?.full_name ?? 'someone'}`,
|
||||
text: `${name(c.from_email)} connected with ${name(c.to_email)}`,
|
||||
})),
|
||||
...feedback.map((f) => ({
|
||||
at: f.created_at,
|
||||
icon: '⭐',
|
||||
text: `${byId.get(f.profile_id)?.full_name ?? 'Someone'} rated a session ${f.rating}★`,
|
||||
text: `${name(f.contact_email)} rated a session ${f.rating}★`,
|
||||
})),
|
||||
]
|
||||
.sort((a, b) => (a.at < b.at ? 1 : -1))
|
||||
@@ -194,3 +235,7 @@ function ActivityFeed({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function fmtDate(d: string): string {
|
||||
return new Date(d + 'T00:00:00').toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { activateEvent, getAllEvents, upsertEvent } from '../lib/api';
|
||||
import type { Event } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Empty, Modal, Spinner } from '../components/ui';
|
||||
|
||||
export function Events() {
|
||||
const { push } = useToast();
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [modal, setModal] = useState<{ event: Event | null } | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
setEvents(await getAllEvents());
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
async function doActivate(ev: Event) {
|
||||
if (!confirm(`Set "${ev.name}" as the active event? All other events will be deactivated.`)) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await activateEvent(ev.id);
|
||||
await load();
|
||||
push('success', `${ev.name} is now active`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Failed to activate');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!loaded)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Events</h1>
|
||||
<div className="sub">
|
||||
{events.length} event{events.length === 1 ? '' : 's'} · only one can be active at a time.
|
||||
</div>
|
||||
</div>
|
||||
<button className="btn primary" onClick={() => setModal({ event: null })}>
|
||||
+ New event
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
{events.length === 0 ? (
|
||||
<Empty icon="📅" text="No events yet. Create one to get started." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Event</th>
|
||||
<th>Dates</th>
|
||||
<th>Location</th>
|
||||
<th>Stats</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{events.map((ev) => (
|
||||
<tr key={ev.id}>
|
||||
<td>
|
||||
<div style={{ fontWeight: 700 }}>{ev.name}</div>
|
||||
{ev.is_active && <span className="pill green">active</span>}
|
||||
</td>
|
||||
<td className="muted">
|
||||
{fmtDate(ev.start_date)} – {fmtDate(ev.end_date)}
|
||||
</td>
|
||||
<td className="muted">{ev.location || '—'}</td>
|
||||
<td className="muted small">
|
||||
{ev.num_registrations} reg · {ev.num_sessions} sessions · {ev.num_speakers} speakers
|
||||
{ev.avg_feedback != null && ` · ⭐ ${ev.avg_feedback.toFixed(1)}`}
|
||||
</td>
|
||||
<td>
|
||||
{ev.is_active ? (
|
||||
<span className="pill green">Active</span>
|
||||
) : (
|
||||
<button className="btn small" disabled={busy} onClick={() => doActivate(ev)}>
|
||||
Set active
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<button className="btn small" onClick={() => setModal({ event: ev })}>
|
||||
Edit
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{modal && (
|
||||
<EventModal
|
||||
event={modal.event}
|
||||
onClose={() => setModal(null)}
|
||||
onSaved={async (msg) => {
|
||||
setModal(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EventModal({
|
||||
event,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
event: Event | null;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(event?.name ?? '');
|
||||
const [startDate, setStartDate] = useState(event ? event.start_date.slice(0, 10) : '');
|
||||
const [endDate, setEndDate] = useState(event ? event.end_date.slice(0, 10) : '');
|
||||
const [location, setLocation] = useState(event?.location ?? '');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
if (!name.trim() || !startDate || !endDate) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await upsertEvent(event?.id ?? null, {
|
||||
name: name.trim(),
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
location: location.trim() || null,
|
||||
});
|
||||
onSaved(event ? 'Event updated' : 'Event created');
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Save failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={event ? 'Edit event' : 'New event'}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !name.trim() || !startDate || !endDate} onClick={save}>
|
||||
{busy ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Name</label>
|
||||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. APPE 2027" />
|
||||
</div>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label>Start date</label>
|
||||
<input className="input" type="date" value={startDate} onChange={(e) => setStartDate(e.target.value)} />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>End date</label>
|
||||
<input className="input" type="date" value={endDate} onChange={(e) => setEndDate(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Location</label>
|
||||
<input className="input" value={location} onChange={(e) => setLocation(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function fmtDate(d: string): string {
|
||||
return new Date(d + 'T00:00:00').toLocaleDateString([], { month: 'short', day: 'numeric', year: 'numeric' });
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
createRegistration,
|
||||
getAllContacts,
|
||||
getActiveEvent,
|
||||
getRegistrations,
|
||||
setCheckedIn,
|
||||
setRegistrationType,
|
||||
} from '../lib/api';
|
||||
import type { Contact, Event, Registration, RegistrationType } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Avatar, Empty, Modal, Spinner, Toggle, TypeBadge } from '../components/ui';
|
||||
|
||||
const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor'];
|
||||
|
||||
export function Registrations() {
|
||||
const { push } = useToast();
|
||||
const [event, setEvent] = useState<Event | null>(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||
const [registrations, setRegistrations] = useState<Registration[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState('');
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const ev = await getActiveEvent();
|
||||
setEvent(ev);
|
||||
if (ev) {
|
||||
const [c, r] = await Promise.all([getAllContacts(), getRegistrations(ev.id)]);
|
||||
setContacts(c);
|
||||
setRegistrations(r);
|
||||
}
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const byEmail = useMemo(() => new Map(contacts.map((c) => [c.email, c])), [contacts]);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!registrations) return [];
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return registrations;
|
||||
return registrations.filter((r) => {
|
||||
const c = byEmail.get(r.contact_email);
|
||||
return (
|
||||
(c?.full_name ?? '').toLowerCase().includes(q) ||
|
||||
r.contact_email.toLowerCase().includes(q) ||
|
||||
r.type.toLowerCase().includes(q)
|
||||
);
|
||||
});
|
||||
}, [registrations, query, byEmail]);
|
||||
|
||||
async function changeType(r: Registration, type: RegistrationType) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await setRegistrationType(r.contact_email, type);
|
||||
await load();
|
||||
push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email} → ${type}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Update failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleCheckedIn(r: Registration, v: boolean) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await setCheckedIn(r.id, v);
|
||||
await load();
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Update 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>Registrations</h1>
|
||||
<div className="sub">Ticket types and check-ins 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>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Registrations</h1>
|
||||
<div className="sub">
|
||||
{event.name} · {registrations.length} registrations · {registrations.filter((r) => r.checked_in).length} checked in.
|
||||
</div>
|
||||
</div>
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<input
|
||||
className="input"
|
||||
style={{ maxWidth: 240 }}
|
||||
placeholder="Search name, email, type…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
<button className="btn primary" onClick={() => setAdding(true)}>
|
||||
+ Register
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Contact</th>
|
||||
<th>Type</th>
|
||||
<th>Checked in</th>
|
||||
<th style={{ textAlign: 'right' }}>Points</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered.map((r) => {
|
||||
const c = byEmail.get(r.contact_email);
|
||||
return (
|
||||
<tr key={r.id}>
|
||||
<td>
|
||||
<div className="cell-person">
|
||||
<Avatar name={c?.full_name ?? r.contact_email} id={r.contact_email} size={38} fs={13} />
|
||||
<div>
|
||||
<div className="n">{c?.full_name ?? r.contact_email}</div>
|
||||
<div className="e">{r.contact_email}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div className="row" style={{ gap: 8 }}>
|
||||
<TypeBadge type={r.type} />
|
||||
<select
|
||||
className="input"
|
||||
style={{ width: 130, padding: '6px 10px', fontSize: 12.5 }}
|
||||
value={r.type}
|
||||
disabled={busy}
|
||||
onChange={(e) => changeType(r, e.target.value as RegistrationType)}
|
||||
>
|
||||
{TYPES.map((t) => (
|
||||
<option key={t} value={t}>
|
||||
{t}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<Toggle checked={r.checked_in} onChange={(v) => toggleCheckedIn(r, v)} />
|
||||
</td>
|
||||
<td style={{ textAlign: 'right' }}>
|
||||
<span className="pts">{r.points}</span>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
{filtered.length === 0 && <div style={{ padding: 16 }}><Empty icon="🎟️" text="No registrations yet" /></div>}
|
||||
</div>
|
||||
|
||||
{adding && (
|
||||
<AddRegistrationModal
|
||||
contacts={contacts}
|
||||
existing={new Set(registrations.map((r) => r.contact_email))}
|
||||
onClose={() => setAdding(false)}
|
||||
onSaved={async (msg) => {
|
||||
setAdding(false);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddRegistrationModal({
|
||||
contacts,
|
||||
existing,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
contacts: Contact[];
|
||||
existing: Set<string>;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const available = contacts.filter((c) => !existing.has(c.email));
|
||||
const [email, setEmail] = useState(available[0]?.email ?? '');
|
||||
const [type, setType] = useState<RegistrationType>('attendee');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
if (!email) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await createRegistration(email, type);
|
||||
onSaved(`Registered ${email} as ${type}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Registration failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title="Register contact"
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !email} onClick={save}>
|
||||
{busy ? 'Registering…' : 'Register'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Contact</label>
|
||||
<select className="input" value={email} onChange={(e) => setEmail(e.target.value)}>
|
||||
{available.length === 0 && <option value="">All contacts already registered</option>}
|
||||
{available.map((c) => (
|
||||
<option key={c.email} value={c.email}>
|
||||
{c.full_name} — {c.email}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Type</label>
|
||||
<select className="input" value={type} onChange={(e) => setType(e.target.value as RegistrationType)}>
|
||||
{TYPES.map((t) => (
|
||||
<option key={t} value={t}>
|
||||
{t}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{type === 'sponsor' && (
|
||||
<p className="muted small">
|
||||
A sponsor registration requires a sponsor lookup — add the sponsor in the Sponsors view first.
|
||||
</p>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,31 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import { getAllSessions, getAllSlots } from '../lib/api';
|
||||
import type { Session, Slot } from '../lib/types';
|
||||
import {
|
||||
evaluateSessionFeedback,
|
||||
getAllContacts,
|
||||
getAllSessionSpeakers,
|
||||
getActiveEvent,
|
||||
getSessions,
|
||||
getSlots,
|
||||
removeSessionMaterial,
|
||||
sessionMaterialUrl,
|
||||
setSessionSpeakers,
|
||||
uploadSessionMaterial,
|
||||
} from '../lib/api';
|
||||
import type { Contact, Event, Session, SessionSpeaker, Slot, SlotType } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Empty, Modal, Spinner } from '../components/ui';
|
||||
import { Empty, Modal, Spinner, TypeBadge } from '../components/ui';
|
||||
|
||||
const SLOT_TYPES: SlotType[] = ['session', 'lunch_break', 'coffee_break', 'keynote', 'close_up'];
|
||||
|
||||
export function Schedule() {
|
||||
const { push } = useToast();
|
||||
const [slots, setSlots] = useState<Slot[] | null>(null);
|
||||
const [event, setEvent] = useState<Event | null>(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [slots, setSlots] = useState<Slot[]>([]);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
const [speakers, setSpeakers] = useState<SessionSpeaker[]>([]);
|
||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [slotModal, setSlotModal] = useState<{ slot: Slot | null } | null>(null);
|
||||
@@ -17,9 +34,22 @@ export function Schedule() {
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const [s, ss] = await Promise.all([getAllSlots(), getAllSessions()]);
|
||||
setSlots(s);
|
||||
setSessions(ss);
|
||||
const ev = await getActiveEvent();
|
||||
setEvent(ev);
|
||||
if (ev) {
|
||||
const [s, ss, sp, c] = await Promise.all([
|
||||
getSlots(ev.id),
|
||||
getSessions(ev.id),
|
||||
getAllSessionSpeakers(),
|
||||
getAllContacts(),
|
||||
]);
|
||||
setSlots(s);
|
||||
setSessions(ss);
|
||||
const ids = new Set(ss.map((x) => x.id));
|
||||
setSpeakers(sp.filter((x) => ids.has(x.session_id)));
|
||||
setContacts(c);
|
||||
}
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
@@ -29,6 +59,18 @@ export function Schedule() {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const speakersFor = useMemo(() => {
|
||||
const m = new Map<string, string[]>();
|
||||
for (const sp of speakers) {
|
||||
const arr = m.get(sp.session_id) ?? [];
|
||||
arr.push(sp.contact_email);
|
||||
m.set(sp.session_id, arr);
|
||||
}
|
||||
return m;
|
||||
}, [speakers]);
|
||||
|
||||
const nameOf = (email: string) => contacts.find((c) => c.email === email)?.full_name ?? email;
|
||||
|
||||
async function deleteSlot(slot: Slot) {
|
||||
if (!confirm(`Delete "${slot.name}" and all its sessions?`)) return;
|
||||
setBusy(true);
|
||||
@@ -59,20 +101,51 @@ export function Schedule() {
|
||||
}
|
||||
}
|
||||
|
||||
async function doEvaluate(sess: Session) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await evaluateSessionFeedback(sess.id);
|
||||
await load();
|
||||
push('success', `AI feedback evaluated for ${sess.title}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Evaluation failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!slots)
|
||||
if (!loaded)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
if (!event) {
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Schedule</h1>
|
||||
<div className="sub">Slots, sessions, speakers, and materials.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<Empty icon="📅" text="No active event. Set an event active in the Events view first." />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Schedule</h1>
|
||||
<div className="sub">{slots.length} slots · {sessions.length} sessions.</div>
|
||||
<div className="sub">
|
||||
{event.name} · {slots.length} slots · {sessions.length} sessions.
|
||||
</div>
|
||||
</div>
|
||||
<button className="btn primary" onClick={() => setSlotModal({ slot: null })}>
|
||||
+ New slot
|
||||
@@ -86,6 +159,7 @@ export function Schedule() {
|
||||
<div key={slot.id} className="card">
|
||||
<div className="row between" style={{ marginBottom: 12 }}>
|
||||
<div className="row" style={{ gap: 12 }}>
|
||||
<TypeBadge type={slot.type} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 800, fontSize: 16 }}>{slot.name}</div>
|
||||
<div className="muted small">
|
||||
@@ -112,24 +186,39 @@ export function Schedule() {
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{slotSessions.map((s) => (
|
||||
<div key={s.id} className="row between" style={{ padding: '10px 12px', background: 'var(--surface-2)', borderRadius: 12 }}>
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontWeight: 700, fontSize: 14 }}>{s.title}</div>
|
||||
<div className="muted small">
|
||||
{[s.room, s.speakers, s.capacity ? `cap ${s.capacity}` : null].filter(Boolean).join(' · ') || '—'}
|
||||
{slotSessions.map((s) => {
|
||||
const spk = (speakersFor.get(s.id) ?? []).map(nameOf).join(', ');
|
||||
return (
|
||||
<div key={s.id} className="row between" style={{ padding: '10px 12px', background: 'var(--surface-2)', borderRadius: 12 }}>
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontWeight: 700, fontSize: 14 }}>{s.title}</div>
|
||||
<div className="muted small">
|
||||
{[s.room, spk || 'no speakers', s.capacity ? `cap ${s.capacity}` : null].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
<div className="muted small" style={{ marginTop: 4 }}>
|
||||
{s.average_feedback != null && <span>⭐ {s.average_feedback.toFixed(1)}</span>}
|
||||
{s.material_path && <span> · 📎 material</span>}
|
||||
{s.ai_generated_feedback && (
|
||||
<span className="ai-state"> · 🤖 {s.ai_generated_feedback}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="row-actions">
|
||||
{s.ai_generated_feedback === 'Pending AI Evaluation' && (
|
||||
<button className="btn small" disabled={busy} onClick={() => doEvaluate(s)}>
|
||||
Evaluate
|
||||
</button>
|
||||
)}
|
||||
<button className="btn small" onClick={() => setSessModal({ session: s, slotId: slot.id })}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small danger" disabled={busy} onClick={() => deleteSession(s)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row-actions">
|
||||
<button className="btn small" onClick={() => setSessModal({ session: s, slotId: slot.id })}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small danger" disabled={busy} onClick={() => deleteSession(s)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -140,6 +229,7 @@ export function Schedule() {
|
||||
{slotModal && (
|
||||
<SlotModal
|
||||
slot={slotModal.slot}
|
||||
eventId={event.id}
|
||||
onClose={() => setSlotModal(null)}
|
||||
onSaved={async (msg) => {
|
||||
setSlotModal(null);
|
||||
@@ -152,6 +242,9 @@ export function Schedule() {
|
||||
<SessionModal
|
||||
session={sessModal.session}
|
||||
slotId={sessModal.slotId}
|
||||
eventId={event.id}
|
||||
contacts={contacts}
|
||||
currentSpeakers={speakersFor.get(sessModal.session?.id ?? '') ?? []}
|
||||
onClose={() => setSessModal(null)}
|
||||
onSaved={async (msg) => {
|
||||
setSessModal(null);
|
||||
@@ -166,14 +259,17 @@ export function Schedule() {
|
||||
|
||||
function SlotModal({
|
||||
slot,
|
||||
eventId,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
slot: Slot | null;
|
||||
eventId: string;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(slot?.name ?? '');
|
||||
const [type, setType] = useState<SlotType>(slot?.type ?? 'session');
|
||||
const [date, setDate] = useState(slot ? slot.slot_date.slice(0, 10) : '');
|
||||
const [start, setStart] = useState(slot ? slot.start_time.slice(0, 5) : '09:00');
|
||||
const [end, setEnd] = useState(slot ? slot.end_time.slice(0, 5) : '10:00');
|
||||
@@ -183,7 +279,7 @@ function SlotModal({
|
||||
if (!name.trim() || !date) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const payload = { name: name.trim(), slot_date: date, start_time: start, end_time: end };
|
||||
const payload = { name: name.trim(), type, slot_date: date, start_time: start, end_time: end, event_id: eventId };
|
||||
if (slot) {
|
||||
const { error: err } = await supabase.from('slots').update(payload).eq('id', slot.id);
|
||||
if (err) throw err;
|
||||
@@ -219,6 +315,16 @@ function SlotModal({
|
||||
<label>Name</label>
|
||||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Morning keynote" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Type</label>
|
||||
<select className="input" value={type} onChange={(e) => setType(e.target.value as SlotType)}>
|
||||
{SLOT_TYPES.map((t) => (
|
||||
<option key={t} value={t}>
|
||||
{t.replace('_', ' ')}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Date</label>
|
||||
<input className="input" type="date" value={date} onChange={(e) => setDate(e.target.value)} />
|
||||
@@ -240,19 +346,26 @@ function SlotModal({
|
||||
function SessionModal({
|
||||
session,
|
||||
slotId,
|
||||
eventId,
|
||||
contacts,
|
||||
currentSpeakers,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
session: Session | null;
|
||||
slotId: number;
|
||||
eventId: string;
|
||||
contacts: Contact[];
|
||||
currentSpeakers: string[];
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [title, setTitle] = useState(session?.title ?? '');
|
||||
const [room, setRoom] = useState(session?.room ?? '');
|
||||
const [speakers, setSpeakers] = useState(session?.speakers ?? '');
|
||||
const [capacity, setCapacity] = useState(session?.capacity?.toString() ?? '');
|
||||
const [description, setDescription] = useState(session?.description ?? '');
|
||||
const [speakerEmails, setSpeakerEmails] = useState<string[]>(currentSpeakers);
|
||||
const [material, setMaterial] = useState<File | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
@@ -262,17 +375,27 @@ function SessionModal({
|
||||
const payload = {
|
||||
title: title.trim(),
|
||||
room: room.trim() || null,
|
||||
speakers: speakers.trim() || null,
|
||||
capacity: capacity ? parseInt(capacity, 10) : null,
|
||||
description: description.trim() || null,
|
||||
slot_id: slotId,
|
||||
event_id: eventId,
|
||||
};
|
||||
let sessionId = session?.id;
|
||||
if (session) {
|
||||
const { error: err } = await supabase.from('sessions').update(payload).eq('id', session.id);
|
||||
if (err) throw err;
|
||||
} else {
|
||||
const { error: err } = await supabase.from('sessions').insert(payload);
|
||||
const { data: ins, error: err } = await supabase.from('sessions').insert(payload).select().single();
|
||||
if (err) throw err;
|
||||
sessionId = (ins as Session).id;
|
||||
}
|
||||
// Speakers (a session must keep >= 1 speaker).
|
||||
if (sessionId && speakerEmails.length > 0) {
|
||||
await setSessionSpeakers(sessionId, speakerEmails);
|
||||
}
|
||||
// Material upload (if a new file was chosen).
|
||||
if (sessionId && material) {
|
||||
await uploadSessionMaterial(sessionId, material);
|
||||
}
|
||||
onSaved(session ? 'Session updated' : 'Session created');
|
||||
} catch (e) {
|
||||
@@ -282,6 +405,12 @@ function SessionModal({
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSpeaker(email: string) {
|
||||
setSpeakerEmails((prev) =>
|
||||
prev.includes(email) ? prev.filter((x) => x !== email) : [...prev, email],
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
@@ -292,7 +421,7 @@ function SessionModal({
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !title.trim()} onClick={save}>
|
||||
<button className="btn primary" disabled={busy || !title.trim() || speakerEmails.length === 0} onClick={save}>
|
||||
{busy ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</>
|
||||
@@ -312,14 +441,71 @@ function SessionModal({
|
||||
<input className="input" type="number" value={capacity} onChange={(e) => setCapacity(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Speakers</label>
|
||||
<input className="input" value={speakers} onChange={(e) => setSpeakers(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Description</label>
|
||||
<textarea className="input" value={description} onChange={(e) => setDescription(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label>Speakers ({speakerEmails.length})</label>
|
||||
<div className="speaker-pick">
|
||||
{contacts.map((c) => (
|
||||
<label key={c.email} className={`speaker-opt ${speakerEmails.includes(c.email) ? 'on' : ''}`}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={speakerEmails.includes(c.email)}
|
||||
onChange={() => toggleSpeaker(c.email)}
|
||||
/>
|
||||
{c.full_name}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
{speakerEmails.length === 0 && (
|
||||
<span className="muted small">A session needs at least one speaker.</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{session && (
|
||||
<div className="field">
|
||||
<label>Material</label>
|
||||
{session.material_path ? (
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<a className="btn small" href={sessionMaterialUrl(session.material_path)} target="_blank" rel="noreferrer">
|
||||
📎 View current
|
||||
</a>
|
||||
<button
|
||||
className="btn small danger"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
try {
|
||||
await removeSessionMaterial(session.id);
|
||||
onSaved('Material removed');
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Remove failed');
|
||||
}
|
||||
}}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<span className="muted small">No material uploaded yet.</span>
|
||||
)}
|
||||
<input
|
||||
className="input"
|
||||
type="file"
|
||||
onChange={(e) => setMaterial(e.target.files?.[0] ?? null)}
|
||||
/>
|
||||
{material && <span className="muted small">Will upload: {material.name}</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{session && session.ai_generated_feedback && (
|
||||
<div className="field">
|
||||
<label>AI feedback</label>
|
||||
<div className="ai-box">{session.ai_generated_feedback}</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user