Events: toggle switch to activate/deactivate (single-active)

- Replace the 'Set active' button / 'Active' pill in the Events table with a
  toggle switch. Activating an event deactivates all others (enforced by the
  existing DB trigger + partial unique index); deactivating just turns it off.
- Add deactivateEvent() API helper.
- Update docs (admin-app.md, next-steps.md).
This commit is contained in:
Lago committed 2026-08-24 11:01:32 +02:00
1 parent a54ce69c4d
commit 8054d0ace2
4 files changed
+21 -20

No files matched your search

+6
View File
@@ -159,6 +159,12 @@ export async function activateEvent(id: string): Promise<void> {
if (error) throw new ApiError(error.message); if (error) throw new ApiError(error.message);
} }
/** Deactivate an event (sets is_active = false). */
export async function deactivateEvent(id: string): Promise<void> {
const { error } = await supabase.from('events').update({ is_active: false }).eq('id', id);
if (error) throw new ApiError(error.message);
}
// ---- Points ------------------------------------------------------------------ // ---- Points ------------------------------------------------------------------
/** Admin manual points adjustment for the active event (audited as 'admin'). */ /** Admin manual points adjustment for the active event (audited as 'admin'). */
+13 -18
View File
@@ -1,8 +1,8 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { activateEvent, getAllEvents, upsertEvent } from '../lib/api'; import { activateEvent, deactivateEvent, getAllEvents, upsertEvent } from '../lib/api';
import type { Event } from '../lib/types'; import type { Event } from '../lib/types';
import { useToast } from '../context/ToastContext'; import { useToast } from '../context/ToastContext';
import { Empty, Modal, Spinner } from '../components/ui'; import { Empty, Modal, Spinner, Toggle } from '../components/ui';
export function Events() { export function Events() {
const { push } = useToast(); const { push } = useToast();
@@ -10,7 +10,6 @@ export function Events() {
const [loaded, setLoaded] = useState(false); const [loaded, setLoaded] = useState(false);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [modal, setModal] = useState<{ event: Event | null } | null>(null); const [modal, setModal] = useState<{ event: Event | null } | null>(null);
const [busy, setBusy] = useState(false);
async function load() { async function load() {
try { try {
@@ -25,17 +24,15 @@ export function Events() {
load(); load();
}, []); }, []);
async function doActivate(ev: Event) { async function toggleActive(ev: Event, active: boolean) {
if (!confirm(`Set "${ev.name}" as the active event? All other events will be deactivated.`)) return; if (active && !confirm(`Set "${ev.name}" as the active event? All other events will be deactivated.`)) return;
setBusy(true);
try { try {
await activateEvent(ev.id); if (active) await activateEvent(ev.id);
else await deactivateEvent(ev.id);
await load(); await load();
push('success', `${ev.name} is now active`); push('success', active ? `${ev.name} is now active` : `${ev.name} deactivated`);
} catch (e) { } catch (e) {
push('error', e instanceof Error ? e.message : 'Failed to activate'); push('error', e instanceof Error ? e.message : 'Failed to update event');
} finally {
setBusy(false);
} }
} }
@@ -93,13 +90,11 @@ export function Events() {
{ev.avg_feedback != null && ` · ⭐ ${ev.avg_feedback.toFixed(1)}`} {ev.avg_feedback != null && ` · ⭐ ${ev.avg_feedback.toFixed(1)}`}
</td> </td>
<td> <td>
{ev.is_active ? ( <Toggle
<span className="pill green">Active</span> checked={ev.is_active}
) : ( onChange={(v) => toggleActive(ev, v)}
<button className="btn small" disabled={busy} onClick={() => doActivate(ev)}> label={ev.is_active ? 'Active' : 'Inactive'}
Set active />
</button>
)}
</td> </td>
<td> <td>
<button className="btn small" onClick={() => setModal({ event: ev })}> <button className="btn small" onClick={() => setModal({ event: ev })}>
+1 -1
View File
@@ -19,7 +19,7 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). | | **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). |
| **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). | | **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
| **Activity** | Tables of check-ins, connections, and feedback (per active event). | | **Activity** | Tables of check-ins, connections, and feedback (per active event). |
| **Events** | Create event, set active (only one), edit dates/location. | | **Events** | Create event, toggle active/inactive (a switch; only one can be active at a time — activating one deactivates the rest), edit dates/location. |
## Auth guard ## Auth guard
+1 -1
View File
@@ -131,7 +131,7 @@ rebuilt the views on the new model:
- **Schedule** — slots (with type) + sessions (speakers 1:N, material upload, - **Schedule** — slots (with type) + sessions (speakers 1:N, material upload,
`average_feedback`, `ai_generated_feedback` + "Evaluate" stub button). `average_feedback`, `ai_generated_feedback` + "Evaluate" stub button).
- **Activity** — check-ins / connections / feedback (per active event). - **Activity** — check-ins / connections / feedback (per active event).
- **Event management** — create event, set active (only one), edit - **Event management** — create event, toggle active/inactive (only one active at a time), edit
dates/location. dates/location.
### Phase 5 — Convivo App ✅ ### Phase 5 — Convivo App ✅