Add delete event button with confirmation dialog to admin page

This commit is contained in:
2025-04-30 17:56:15 -04:00
parent f01e4590fc
commit 48d96e4b69

View File

@@ -75,6 +75,7 @@ const EventAdmin: React.FC = () => {
guest_names: '', guest_names: '',
items_bringing: [] as string[], items_bringing: [] as string[],
}); });
const [deleteEventDialogOpen, setDeleteEventDialogOpen] = useState(false);
useEffect(() => { useEffect(() => {
fetchEventAndRsvps(); fetchEventAndRsvps();
@@ -272,6 +273,16 @@ const EventAdmin: React.FC = () => {
} }
}; };
const handleDeleteEvent = async () => {
try {
await axios.delete(`/api/events/${slug}`);
navigate('/');
} catch (error) {
setError('Failed to delete event');
setDeleteEventDialogOpen(false);
}
};
if (loading) { if (loading) {
return ( return (
<Container maxWidth="lg"> <Container maxWidth="lg">
@@ -434,6 +445,17 @@ const EventAdmin: React.FC = () => {
</TableBody> </TableBody>
</Table> </Table>
</TableContainer> </TableContainer>
<Box sx={{ display: 'flex', justifyContent: 'flex-end', mt: 4 }}>
<Button
variant="contained"
color="error"
startIcon={<DeleteIcon />}
onClick={() => setDeleteEventDialogOpen(true)}
>
Delete Event
</Button>
</Box>
</Paper> </Paper>
<Dialog <Dialog
@@ -552,6 +574,27 @@ const EventAdmin: React.FC = () => {
<Button onClick={handleEditSubmit} color="primary">Save Changes</Button> <Button onClick={handleEditSubmit} color="primary">Save Changes</Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
<Dialog
open={deleteEventDialogOpen}
onClose={() => setDeleteEventDialogOpen(false)}
>
<DialogTitle>Delete Event</DialogTitle>
<DialogContent>
<Typography>
Are you sure you want to delete "{event.title}"? This action cannot be undone.
</Typography>
<Typography color="error" sx={{ mt: 2 }}>
All RSVPs associated with this event will also be deleted.
</Typography>
</DialogContent>
<DialogActions>
<Button onClick={() => setDeleteEventDialogOpen(false)}>Cancel</Button>
<Button onClick={handleDeleteEvent} color="error" variant="contained">
Delete Event
</Button>
</DialogActions>
</Dialog>
</Container> </Container>
); );
}; };