diff --git a/web/src/lib/components/user-data-table.svelte b/web/src/lib/components/user-data-table.svelte index e302aa9..4bdcc11 100644 --- a/web/src/lib/components/user-data-table.svelte +++ b/web/src/lib/components/user-data-table.svelte @@ -4,6 +4,7 @@ import { Button } from '$lib/components/ui/button/index.js'; import { toast } from 'svelte-sonner'; import * as Dialog from '$lib/components/ui/dialog/index.js'; + import * as AlertDialog from '$lib/components/ui/alert-dialog/index.js'; import { Label } from '$lib/components/ui/label/index.js'; import * as RadioGroup from '$lib/components/ui/radio-group/index.js'; import { Input } from '$lib/components/ui/input/index.js'; @@ -14,9 +15,11 @@ let { users }: { users: components['schemas']['UserRead'][] } = $props(); let sortedUsers = $derived(users.sort((a, b) => a.email.localeCompare(b.email))); let selectedUser: components['schemas']['UserRead'] | null = $state(null); + let userToDelete: components['schemas']['UserRead'] | null = $state(null); let newPassword: string = $state(''); let newEmail: string = $state(''); let dialogOpen = $state(false); + let deleteDialogOpen = $state(false); async function saveUser() { if (!selectedUser) return; @@ -47,6 +50,27 @@ await invalidateAll(); } } + + async function deleteUser() { + if (!userToDelete) return; + + const { error } = await client.DELETE('/api/v1/users/{id}', { + params: { + path: { + id: userToDelete.id + } + } + }); + + if (error) { + toast.error(`Failed to delete user ${userToDelete.email}: ${error}`); + } else { + toast.success(`User ${userToDelete.email} deleted successfully.`); + deleteDialogOpen = false; + userToDelete = null; + await invalidateAll(); + } + } @@ -75,15 +99,26 @@ - +
+ + +
{/each} @@ -189,3 +224,27 @@ + + + + Delete User + + Are you sure you want to delete the user {userToDelete?.email}? This action + cannot be undone. + + + + { + deleteDialogOpen = false; + userToDelete = null; + }}>Cancel + deleteUser()} + class="bg-destructive text-destructive-foreground hover:bg-destructive/90" + >Delete + + +