Skip to content

fix(dashboard): report localStorage cache + delete account flow#23

Merged
BODMAT merged 5 commits into
developmentfrom
fix/report-cache-delete-account
Jun 2, 2026
Merged

fix(dashboard): report localStorage cache + delete account flow#23
BODMAT merged 5 commits into
developmentfrom
fix/report-cache-delete-account

Conversation

@BODMAT

@BODMAT BODMAT commented Jun 2, 2026

Copy link
Copy Markdown
Owner

What

Closes two UX gaps found after Week 4 merge: AI reports were lost on page reload (no persistence), and there was no way for a user to delete their account. Adds per-user localStorage caching for reports with auto-load on range switch, and a 2-step animated delete account flow with a new DELETE endpoint.

Changes

Code

  • app/dashboard/reports/report-form.tsx — localStorage cache per range; lazy useState init loads last result on mount; range/date event handlers check cache (no useEffect for state — required by lint); createdAt badge added to ResultPanel; NEW REPORT button removed (range switch replaces it)
  • app/dashboard/reports/page.tsx — passes userEmail to ReportForm for cache key scoping
  • app/api/auth/delete-account/route.tsDELETE endpoint; verifies auth, calls prisma.user.delete (cascades to Sessions → Events/Tracks, UserSetting), clears session cookie
  • app/dashboard/account-menu.tsx — replaces LogoutButton; 2-step modal (account options → delete confirmation); spring animation identical to ApiKeyModal; Escape key, error display, clearReportCache on both logout and delete, typeof document SSR guard for createPortal
  • app/dashboard/app-header.tsx — swaps <LogoutButton /> for <AccountMenu userEmail={email} />
  • app/dashboard/logout-button.tsx — deleted (dead code)

Tooling / config

n/a

Docs / plan

n/a — fix branch, no formal plan file required

Design decisions

  • Event handlers instead of useEffect for cache reads — project lint rule (react-hooks/set-state-in-effect) forbids setState inside effects; lazy useState init handles the initial load, range/date onChange handlers cover subsequent changes
  • Cache key includes normalized emailwt:report:${email}:${range} prevents cross-account bleed when switching Google accounts on the same browser
  • clearReportCache on both logout and delete — on logout the cache keys remain valid (same email next login sees own data), but clearing on logout is explicit hygiene; on delete it removes orphaned keys
  • typeof document !== "undefined" guard"use client" components still run on the server in Next.js App Router; document.body as a createPortal argument is evaluated before React sees it, so a short-circuit guard is required; mounted state would also work but is blocked by the same lint rule
  • 2-step modal flow — delete is irreversible; first modal (account options) separates intent from confirmation; second modal (confirmation) requires an explicit "DELETE EVERYTHING" click; Escape in modal 2 returns to modal 1, not all the way out

Verification

  • npx tsc --noEmit (dashboard) — clean
  • npm run lint (dashboard) — clean
  • npm run typecheck (extension) — clean
  • Manual test: generate a report → reload page → report still shown for that range; switch range → correct cached report loads; switch account → no cross-bleed; open ⎋ → account modal; click DELETE ACCOUNT → confirmation modal; Escape returns to account modal; DELETE EVERYTHING → redirect to login; account data gone from DB

Out of scope (future PRs)

  • Cache expiry / TTL (currently cached forever per range)
  • "Clear all cached reports" button in settings

Closes

  • n/a (UX improvements, not a formal AC)

@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worktrace Ready Ready Preview, Comment Jun 2, 2026 5:37pm

@BODMAT BODMAT merged commit f490844 into development Jun 2, 2026
4 checks passed
@BODMAT BODMAT deleted the fix/report-cache-delete-account branch June 2, 2026 17:38
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.

1 participant