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).

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:
committed 2026-08-24 11:01:32 +02:00
1 parent 24909cf8ab
commit a0bcf866dc
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);
}
/** 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 ------------------------------------------------------------------
/** 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 { activateEvent, getAllEvents, upsertEvent } from '../lib/api';
import { activateEvent, deactivateEvent, getAllEvents, upsertEvent } from '../lib/api';
import type { Event } from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Empty, Modal, Spinner } from '../components/ui';
import { Empty, Modal, Spinner, Toggle } from '../components/ui';
export function Events() {
const { push } = useToast();
@@ -10,7 +10,6 @@ export function Events() {
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 {
@@ -25,17 +24,15 @@ export function Events() {
load();
}, []);
async function doActivate(ev: Event) {
if (!confirm(`Set "${ev.name}" as the active event? All other events will be deactivated.`)) return;
setBusy(true);
async function toggleActive(ev: Event, active: boolean) {
if (active && !confirm(`Set "${ev.name}" as the active event? All other events will be deactivated.`)) return;
try {
await activateEvent(ev.id);
if (active) await activateEvent(ev.id);
else await deactivateEvent(ev.id);
await load();
push('success', `${ev.name} is now active`);
push('success', active ? `${ev.name} is now active` : `${ev.name} deactivated`);
} catch (e) {
push('error', e instanceof Error ? e.message : 'Failed to activate');
} finally {
setBusy(false);
push('error', e instanceof Error ? e.message : 'Failed to update event');
}
}
@@ -93,13 +90,11 @@ export function Events() {
{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>
)}
<Toggle
checked={ev.is_active}
onChange={(v) => toggleActive(ev, v)}
label={ev.is_active ? 'Active' : 'Inactive'}
/>
</td>
<td>
<button className="btn small" onClick={() => setModal({ event: ev })}>