fix(admin): wire delete-user button via enhance callback instead of requestSubmit()
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 2m46s
CI / OCR Service Tests (pull_request) Successful in 36s
CI / Backend Unit Tests (pull_request) Failing after 2m52s
CI / Unit & Component Tests (push) Failing after 2m51s
CI / OCR Service Tests (push) Successful in 40s
CI / Backend Unit Tests (push) Failing after 2m58s
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 2m46s
CI / OCR Service Tests (pull_request) Successful in 36s
CI / Backend Unit Tests (pull_request) Failing after 2m52s
CI / Unit & Component Tests (push) Failing after 2m51s
CI / OCR Service Tests (push) Successful in 40s
CI / Backend Unit Tests (push) Failing after 2m58s
The delete button used type=button + requestSubmit() to trigger the form, which did not reliably fire SvelteKit's enhance submit listener. Replaced with a type=submit button and an async enhance callback that guards with the confirm dialog and calls cancel() on rejection. Also clears the unsaved-changes dirty flag before the redirect so beforeNavigate doesn't silently block the post-delete navigation. Closes #277 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #279.
This commit is contained in:
@@ -15,16 +15,6 @@ const unsaved = createUnsavedWarning();
|
||||
|
||||
const selectedGroupIds = $derived(data.editUser.groups?.map((g: { id: string }) => g.id) ?? []);
|
||||
|
||||
let deleteFormEl = $state<HTMLFormElement | null>(null);
|
||||
|
||||
async function handleDelete() {
|
||||
const confirmed = await confirm({
|
||||
title: m.admin_user_delete_confirm({ username: data.editUser.email }),
|
||||
destructive: true
|
||||
});
|
||||
if (confirmed) deleteFormEl!.requestSubmit();
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (form?.success) unsaved.clearOnSuccess();
|
||||
});
|
||||
@@ -51,10 +41,23 @@ $effect(() => {
|
||||
<h2 class="flex-1 font-sans text-sm font-bold text-ink">
|
||||
{m.admin_user_edit_heading({ username: data.editUser.email })}
|
||||
</h2>
|
||||
<form bind:this={deleteFormEl} method="POST" action="?/delete" use:enhance>
|
||||
<form
|
||||
method="POST"
|
||||
action="?/delete"
|
||||
use:enhance={async ({ cancel }) => {
|
||||
const confirmed = await confirm({
|
||||
title: m.admin_user_delete_confirm({ username: data.editUser.email }),
|
||||
destructive: true
|
||||
});
|
||||
if (!confirmed) {
|
||||
cancel();
|
||||
} else {
|
||||
unsaved.clearOnSuccess();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onclick={handleDelete}
|
||||
type="submit"
|
||||
class="rounded-sm border border-red-200 bg-red-50 px-3 py-1 font-sans text-xs font-bold tracking-widest text-red-700 uppercase transition-colors hover:bg-red-100 dark:border-red-900 dark:bg-red-950/30 dark:text-red-400"
|
||||
>
|
||||
{m.btn_delete()}…
|
||||
|
||||
Reference in New Issue
Block a user