Fix: 'delete all contacts for event' no longer deletes the logged-in admin

The bulk delete now excludes the currently-logged-in contact (me.email) so
you can't delete your own account out from under yourself.
This commit is contained in:
Lago committed 2026-09-09 12:54:36 +02:00
1 parent 98f65e8665
commit 7559f879c8
1 file changed
+8 -3
+8 -3
View File
@@ -13,12 +13,14 @@ import {
} from '../lib/api'; } from '../lib/api';
import type { Contact, Event, Registration, RegistrationType, Sponsor, SponsorType } from '../lib/types'; import type { Contact, Event, Registration, RegistrationType, Sponsor, SponsorType } from '../lib/types';
import { useToast } from '../context/ToastContext'; import { useToast } from '../context/ToastContext';
import { useAuth } from '../context/AuthContext';
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui'; import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui';
const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor']; const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor'];
export function Registrations() { export function Registrations() {
const { push } = useToast(); const { push } = useToast();
const { contact: me } = useAuth();
const [events, setEvents] = useState<Event[]>([]); const [events, setEvents] = useState<Event[]>([]);
const [selectedId, setSelectedId] = useState(''); const [selectedId, setSelectedId] = useState('');
const [loaded, setLoaded] = useState(false); const [loaded, setLoaded] = useState(false);
@@ -73,14 +75,17 @@ export function Registrations() {
async function deleteAllContactsForEvent() { async function deleteAllContactsForEvent() {
if (!event) return; if (!event) return;
const emails = [...new Set(registrations.map((r) => r.contact_email))]; // Never delete the contact you're logged in as (it would log you out).
const emails = [...new Set(registrations.map((r) => r.contact_email))].filter(
(e) => e !== me?.email,
);
if (emails.length === 0) { if (emails.length === 0) {
push('error', 'No registrations for this event to delete.'); push('error', 'No other contacts registered for this event to delete.');
return; return;
} }
if ( if (
!confirm( !confirm(
`Delete ${emails.length} contact(s) registered for "${event.name}"? Their registrations for this event are removed (the contact is deleted entirely).`, `Delete ${emails.length} contact(s) registered for "${event.name}"? Their registrations for this event are removed (the contact is deleted entirely). Your own account is kept.`,
) )
) )
return; return;