Skip to content

feat(finance): add expense save toasts#34

Merged
ItsThompson merged 7 commits into
mainfrom
ft/log-expense-redirect-remove
Jul 4, 2026
Merged

feat(finance): add expense save toasts#34
ItsThompson merged 7 commits into
mainfrom
ft/log-expense-redirect-remove

Conversation

@ItsThompson

@ItsThompson ItsThompson commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace the new-expense success redirect (standard and pro-rata) with Sonner toasts: Expense saved and Expense schedule saved, plus a generic Failed to save expense toast on API/network failure
  • Reset visible form state to fresh-load defaults after a successful submit without refetching tags or suggestions; success copy is derived from the submitted request kind so it stays correct if the form changes while the request is in flight
  • Preserve existing inline validation and API error messages, and keep only the submit button disabled while saving
  • Centralize default tag selection so initial load and post-success reset share one source, reusing useExpenseFields.reset(...) instead of hand-copying defaults
  • Extract a dependency-injected toLocalISODate util into src/lib/date-utils.ts and reuse it in useExpenseFields, removing duplicated local-date formatting
  • Move SubmittedExpenseKind into a dedicated types.ts and replace the deprecated FormEvent with SyntheticEvent<HTMLFormElement>
  • Share new-expense test fixtures, fetch mocks, and query helpers via __tests__/test-utils.tsx, and add a buildIntersectionObserverEntry helper in the dashboard outline test
  • Restore the finance typecheck with types: ["vitest/globals", "node"] in tsconfig.app.json (the app typecheck compiles test files under src, which use global and un-imported vitest globals)

Verification

  • cd frontend/apps/finance && npx tsc -p tsconfig.app.json --noEmit → 0 errors
  • cd frontend/apps/finance && npm run test → 38 files, 426 tests passed
  • cd frontend/apps/finance && npm run test -- --coverage → thresholds met (stmts 92.14, branch 85.11, funcs 88.94, lines 93.65)
  • cd frontend/apps/finance && npm run lint → 0 errors
  • cd frontend/apps/finance && npm run build → built successfully

- Add Vitest and Node ambient types to the finance app tsconfig.

- Update test mocks for TypeScript 6 DOM and unused-parameter checks.

- Use browser-safe timeout inference instead of NodeJS.Timeout.
- Replace new-expense success redirects with Sonner success toasts.

- Reset visible form state through useExpenseFields without refetching bootstrap data.

- Cover success, failure, validation, pro-rata, and autocomplete flows.
Comment thread frontend/apps/finance/src/features/new-expense/hooks/useNewExpenseForm.ts Outdated
Comment thread frontend/apps/finance/src/features/new-expense/hooks/useNewExpenseForm.ts Outdated
Comment thread frontend/apps/finance/src/features/new-expense/hooks/useNewExpenseForm.ts Outdated
Comment thread frontend/apps/finance/src/features/dashboard/__tests__/DashboardOutline.test.tsx Outdated
Comment thread frontend/apps/finance/src/features/new-expense/hooks/useNewExpenseForm.ts Outdated
Comment thread frontend/apps/finance/src/features/new-expense/__tests__/new-expense.test.tsx Outdated
Comment thread frontend/apps/finance/tsconfig.app.json
- Branch directly on isProRata and return the kind literal, dropping the redundant submit-time snapshot consts since the async closure already captures render-scoped state
- Move SubmittedExpenseKind into its own types.ts and keep isProRata as the single toggle source of truth
- Replace the deprecated FormEvent type with SyntheticEvent<HTMLFormElement>
- Add toLocalISODate util that formats a Date (default now) as a local YYYY-MM-DD string, avoiding UTC off-by-one from toISOString
- Replace the private todayISO in useExpenseFields with the shared util
- Cover the util with injected fixed-date and default-now tests
- Extract shared fixtures, a fetch-mock builder, and query helpers into new-expense __tests__/test-utils and refactor the three specs to use them
- Remove per-file duplicated mock data and handlers without weakening any assertion
- Replace the double-cast IntersectionObserverEntry with a buildIntersectionObserverEntry helper in the DashboardOutline test
Comment thread frontend/apps/finance/src/lib/date-utils.ts
- Move new-expense mock data and the fetch mock into a dedicated __mocks__ folder (fixtures + fetch + barrel)
- Build the user and tag fixtures with the shared @gofin/test-utils factories instead of inline literals
- Keep test-utils for shared test functions only (render, waiters, fetch-call query helpers)
- logExpense waits for the success toast (standard vs pro-rata) instead of a /dashboard redirect
- specs that verify dashboard state now navigate to /dashboard explicitly before asserting
- inline Log Expense submits assert the "Expense saved" toast, keeping the same coverage
@ItsThompson ItsThompson merged commit 056e3d5 into main Jul 4, 2026
5 checks passed
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.

2 participants