Skip to content

Commit

Permalink
Refactor delete confirmation logic; replace state variable for delete…
Browse files Browse the repository at this point in the history
… checkbox and update related functions
  • Loading branch information
haukened committed Nov 7, 2024
1 parent dd91343 commit 72e4dd3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/routes/admin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
let dialogOpen = $state(false);
let dialogAction = $state("create" as "create" | "update" | "delete" | "reg");
let disableRegCloseButton = $state(true);
let actuallyDelete = $state(false);
let disableDeleteButton = $derived(!actuallyDelete);
let actuallyDeleteCheckBox = $state(false);
let disableDeleteButton = $derived(!actuallyDeleteCheckBox);
let regToken = $state({
value: "",
Expand Down Expand Up @@ -88,6 +88,10 @@
const clearRegToken = () => {
regToken = undefined;
}
const clearCheckbox = () => {
actuallyDeleteCheckBox = false;
}
const dateFormatter = new Intl.DateTimeFormat("en-US", {
year: "numeric",
Expand All @@ -104,20 +108,23 @@
closeDialog();
clearFormData();
clearRegToken();
clearCheckbox();
$errors._errors.forEach(error => {
toast.error(error);
});
}
if ($message) {
if ($message.text) {
closeDialog();
clearCheckbox();
toast.success($message.text);
$message.text = undefined;
}
if ($message.token) {
closeDialog();
openRegDialog($message.token);
clearRegToken();
clearCheckbox();
}
}
});
Expand Down Expand Up @@ -258,7 +265,7 @@
<input type="hidden" name="email" bind:value={$formData.email} />
<Dialog.Footer class="flex flex-row !justify-between">
<div class="flex flex-row items-center space-x-2">
<Checkbox id="actually-delete" bind:checked={actuallyDelete}/>
<Checkbox id="actually-delete" bind:checked={actuallyDeleteCheckBox}/>
<Label for="actually-delete">{m.adminConfirmDelete()}</Label>
</div>
<Button disabled={disableDeleteButton} type="submit" variant="destructive">{m._delete()}</Button>
Expand Down

0 comments on commit 72e4dd3

Please sign in to comment.