feat(po): prompt to save as draft when leaving with unsaved changes #116
No reviewers
Labels
No labels
bug
claude-failed
claude-pr
claude-queue
claude-working
epic
feature
interactive
portal
triaged
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: shad0w/pelagia-portal#116
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/po-draft-prompt"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #18.
Problem
Navigating away from a PO create or edit screen with unsaved changes silently lost the in-progress data.
Solution
A reusable
<UnsavedChangesGuard>(components/po/unsaved-changes-guard.tsx) wired intonew-po-formandedit-po-form. It arms once the form is dirty (any input/change on the form, plus the React-state editors — line items, terms, files, accounting code) and guards both navigation paths:beforeunload). Browsers can't render custom buttons here, so save-as-draft isn't offered on this path.<a>) → a capture-phase click interceptor opens a modal offering:dirtyis reset before a successful submit's redirect, so saving never trips the prompt.Scope / limitations
beforeunloadprompt only — robust popstate interception in the App Router is fragile, and the dominant "leave" paths (sidebar/header clicks, refresh, close, typing a URL) are covered./approvals/[id]is out of scope — it saves in place viarouter.refresh()and has no draft concept.Verification
beforeunloadarming).pnpm test→ 296 passedpnpm exec tsc --noEmit→ clean🤖 Generated with Claude Code