Repository navigation
fix(frontend): confirm dialog focuses the safe action and is accessible #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| DEFAULT_INVENTORY_SUB_SECTION, | ||
| } from './inventory'; | ||
| import { isAdmin } from './auth'; | ||
| import { confirmDialog } from './confirmDialog'; | ||
| import { canAccess } from './permissions'; | ||
|
|
||
| interface TabMeta { | ||
|
|
@@ -123,6 +124,16 @@ function renderNoAccess(tabId: string): void { | |
| /** | ||
| * Switch between tabs | ||
| */ | ||
| function confirmLeaveSettings(): Promise<boolean> { | ||
| return confirmDialog({ | ||
| title: 'Leave without saving?', | ||
| body: 'You have unsaved settings changes. Leaving this tab discards them.', | ||
| confirmLabel: 'Leave without saving', | ||
| cancelLabel: 'Stay on this tab', | ||
| destructive: true, | ||
| }); | ||
| } | ||
|
|
||
| export function switchTab(tabName: string, opts: SwitchTabOptions = {}): void { | ||
| if (!isKnownKey(TABS, tabName)) tabName = 'home'; | ||
|
|
||
|
|
@@ -134,7 +145,10 @@ export function switchTab(tabName: string, opts: SwitchTabOptions = {}): void { | |
| tabName !== 'admin' && | ||
| isUnsavedChanges() | ||
| ) { | ||
| if (!confirm('You have unsaved settings changes. Leave without saving?')) return; | ||
| void confirmLeaveSettings().then(leave => { | ||
| if (leave) switchTab(tabName, { ...opts, skipDirtyGuard: true }); | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| document.querySelectorAll<HTMLButtonElement>('.tab-btn').forEach(btn => { | ||
|
|
@@ -359,10 +373,15 @@ export function initRouter(): void { | |
| target !== 'admin' && | ||
| isUnsavedChanges() | ||
| ) { | ||
| if (!confirm('You have unsaved settings changes. Leave without saving?')) { | ||
| if (delta !== 0) window.history.go(-delta); | ||
| return; | ||
| } | ||
| void confirmLeaveSettings().then(leave => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Handle subsequent Back events while confirmation is pending. If the user presses Back twice while Admin settings are dirty, this handler opens two dialogs with different history targets. If the user stays in the second dialog and then confirms the first, 🤖 Prompt for AI Agents |
||
| if (leave) { | ||
| historyId = newId; | ||
| switchTab(target, { push: false, skipDirtyGuard: true }); | ||
| } else if (delta !== 0) { | ||
| window.history.go(-delta); | ||
| } | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| historyId = newId; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.