feat(console): add in-app destructive-action confirmation

Deleting a route or a group used `window.confirm`, which blocks the page
and ignores the console theme. A promise-based `useConfirm()` now drives
one <ConfirmDialog /> built on the reka-ui AlertDialog that
@elysola/ui ships; reka-ui is pre-bundled so dev keeps a single copy and
the dialog stacks with the Rc dialogs.

A request never outlives its asker: one made after the asking component
unmounted resolves false, and one still open when it unmounts is
cancelled.
This commit is contained in:
翅膀 committed 2026-10-17 00:12:36 +08:00
1 parent d57e5c29c4
commit 24f5d0477c
8 files changed
+239 -7

No files matched your search

+10 -3
View File
@@ -315,6 +315,8 @@
@close="groupEditorOpen = false"
@save="onSaveGroup"
/>
<ConfirmDialog />
</div>
</template>
@@ -343,6 +345,7 @@ import AdminHome from "~/components/AdminHome.vue";
const { t, toggle } = useI18n();
const { push } = useToasts();
const { confirm } = useConfirm();
const route = useRoute();
const router = useRouter();
@@ -582,7 +585,8 @@ async function onToggle(route: Route): Promise<void> {
async function onDelete(route: Route): Promise<void> {
const group = selectedGroup.value;
if (!group) return;
if (!window.confirm(t("confirm.deleteRoute", { name: route.name || route.id }))) return;
if (!(await confirm({ title: t("confirm.deleteRoute", { name: route.name || route.id }) })))
return;
try {
await saveGroupRoutes(
group.id,
@@ -665,8 +669,11 @@ async function onDeleteGroup(group: Group): Promise<void> {
} catch {
// Count is best-effort; proceed without the warning.
}
const warn = used ? t("confirm.deleteGroupWarn", { n: used }) : "";
if (!window.confirm(t("confirm.deleteGroup", { name: group.name || group.id }) + warn)) return;
const confirmed = await confirm({
title: t("confirm.deleteGroup", { name: group.name || group.id }),
description: used ? t("confirm.deleteGroupWarn", { n: used }).trim() : undefined,
});
if (!confirmed) return;
try {
await saveGroups(groups.value.filter((g) => g.id !== group.id));
push(t("toast.groupDeleted"));