Skip to content

feat(escrow): persist wizard draft state and add step navigation guar… - #615

Closed
datagerl wants to merge 3 commits into
StayLitCodes:mainfrom
datagerl:feat/escrow-wizard-draft-persistence
Closed

feat(escrow): persist wizard draft state and add step navigation guar…#615
datagerl wants to merge 3 commits into
StayLitCodes:mainfrom
datagerl:feat/escrow-wizard-draft-persistence

Conversation

@datagerl

Copy link
Copy Markdown
Contributor

Description

The CreateEscrowWizard (7-step form) previously lost all entered data on
page refresh, accidental navigation, or the browser back button — there
was no draft persistence, no popstate handling, and no beforeunload
warning. Users filling out milestones, conditions, and parties could
lose several minutes of work on any interruption.

This PR completes draft persistence and step-navigation guards for the
wizard.

Changes Made

  • useWizardDraft hook: debounced (1s) localStorage autosave, draft
    restore with 7-day expiry, manual save, clear/discard
  • CreateEscrowWizard:
    • Restores draft on mount via a "Resume draft?" prompt
    • Clears the draft on successful escrow creation
    • Reflects the current step in ?step= for bookmarkable/shareable URLs
    • Handles popstate so the browser back button steps backward through
      the wizard instead of navigating away
    • Warns on beforeunload when there are unsaved changes past step 1
    • Adds a Cancel action in the header, wired to the existing
      "Discard draft?" confirmation modal (previously unused/dead code) —
      this is now the actual trigger for that criterion
    • Adds a manual Save draft button next to Next/Submit
    • Shows a "Draft saved at " indicator in the header

Testing Done

  • apps/frontend/hooks/useWizardDraft.test.ts — 9 new tests (save,
    debounce timing/reset, restore, 7-day expiry boundary, corrupted JSON,
    clear/discard)
  • apps/frontend/components/escrow/CreateEscrowWizard.test.tsx — 15
    tests (step validation, URL step sync, back-button navigation,
    autosave + indicator, manual save, beforeunload warning,
    resume/discard prompts, expired-draft cleanup, cancel/discard flow).
    This file previously could not run at all (missing ToastProvider,
    written before the template-selector step existed) — rewritten to
    match current component behavior.
  • Full frontend suite run for regressions: pnpm test. The only
    failures are 7 pre-existing suites unrelated to this change (wallet
    modal, escrow events/list hooks, transaction tracker — all
    network/MSW related), not touched here.

Acceptance Criteria

  • Auto-save wizard state to localStorage on every step change (debounced 1s)
  • Restore draft from localStorage on mount with "Resume draft?" prompt
  • Clear saved draft on successful escrow creation
  • Clear expired drafts older than 7 days
  • Browser back button navigates to previous wizard step instead of leaving page
  • beforeunload event warns when user tries to close tab with unsaved changes
  • Show "Discard draft?" confirmation when navigating away mid-wizard
  • Current step reflected in URL query param (?step=3) for bookmarkability
  • Draft indicator in wizard header shows "Draft saved" with timestamp
  • Manual "Save draft" button alongside "Next" / "Submit"
  • Unit tests for draft save/restore and step navigation

Out of Scope

Several other test suites in apps/frontend were already failing before
this change (network-dependent hook/wallet tests) — left untouched as
unrelated pre-existing issues.

Checklist

  • Tests added/updated
  • No new TypeScript errors introduced
  • Backward compatible (draft key/shape unchanged from prior partial implementation)

closes #603

…ds Wire up localStorage draft persistence for the 7-step CreateEscrowWizard so in-progress escrows survive refreshes, accidental navigation, and the browser back button. - Auto-save wizard state to localStorage, debounced 1s, on every step/field change - Restore drafts on mount via a "Resume draft?" prompt; clear drafts older than 7 days - Clear the saved draft on successful escrow creation - Sync the current step to a ?step= URL query param for bookmarkability - Handle popstate so the browser back button moves through wizard steps instead of leaving the page - Warn via beforeunload when closing the tab with unsaved changes - Add a Cancel action in the wizard header, wired to the existing "Discard draft?" confirmation, so navigating away mid-wizard is guarded - Add a manual "Save draft" button alongside Next/Submit Add unit tests for useWizardDraft (save/restore/expiry/corrupted data) and for CreateEscrowWizard (step navigation, autosave, resume/discard, cancel flow). Update the existing wizard test file, which predated the template-selector step and was not runnable (missing ToastProvider). Closes: draft persistence for CreateEscrowWizard
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@datagerl Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…S[currentStep].fields to Path<CreateEscrowFormData>[] instead of string[] so it satisfies trigger()'s expected field path union, fixing a build-blocking type error in CreateEscrowWizard.tsx.
@Cedarich

Copy link
Copy Markdown
Contributor

@datagerl kindly fix CI

@Cedarich Cedarich closed this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(frontend): Add draft auto-save, browser back handling, and unsaved-changes warning to CreateEscrowWizard

2 participants