Show the financial independence card on the Plan hub

JA
5d ago
+361-1

Base: up/retirement-plan-ui-page (stacked) | Head: up/retirement-plan-ui-card | Draft

Part of #5567

Fork pre-flight: jaysbeekay/sure#974 (same commits)

Stacked on #5752

Third of five UI PRs: the way in to the planner.

Problem

The planner page has no entry point. The Plan hub (/plan) already fronts budgets and goals for preview users, and its nav entry is already preview-gated, so it is the natural place for retirement planning to surface.

Resulting behaviour

The Plan hub gets a third card, "Financial independence", beside the budget and goals cards, built the same way (DS::Card, the same header shape).

  • With a saved plan, the card shows:

    • the FI number (DS::Stat, :xl), with the year of living costs and withdrawal rate it comes from;
    • progress towards it, with a bar like the neighbouring cards, which stops at 100% while the figure keeps counting;
    • the savings rate, marked "from your income and spending" when it is derived, with the yearly tracked income it applies to ("of $48,000 a year", privacy-sensitive);
    • a warning (DS::Alert) when no income is tracked, or when a derived rate is 0 because tracked spending meets or exceeds tracked income.

    Settings and Year-by-year planner links lead to the modal and the page. The FI number and the spending behind it are both privacy-sensitive: the spending and the rate together give the number away.

  • Without a saved plan, the card is a DS::EmptyState with "Set up your plan", which opens the settings modal. It works nothing out: the projection needs two income-statement medians and a converted balance total, which can fetch a missing exchange rate, and that is not worth paying on every hub view for every preview user.

  • Accounts left out for want of a rate are counted under the figures.

  • PlansController#show captures Date.current once, so the card's projection and the budget resolve the same day.

Size: 162 non-test lines added, 1 removed.

Validation

  • After the savings-rate hints (review on #5567): component tests for the income figure, the spending warning and the no-income warning, each of which failed before. Full suite at the top of the stack (7110d042f): 18749 runs, 1 failure (a date-dependent AccountsControllerTest case that fails the same way before this change), 8 ReleaseNotesWorkflowTest errors. Each changed line has a mutation that a test catches.
  • Full suite bin/rails test at this head 139b68474: 18665 runs, 0 failures. The 8 errors are ReleaseNotesWorkflowTest, which needs node, missing from the test image.
  • bin/rubocop, erb_lint and Brakeman: clean.
  • Tests: the FI number from the viewer's spending, with a link to the planner; no plan writes nothing and builds no projection (expects(:projection).never); no spending asks for it; past independence the bar is full and the figure says how far past; the summary component's derived and saved savings rates, projected total, unconverted count, and privacy marking.
  • Mutations, each caught by a failing assertion:
    • a projection built without a plan;
    • the empty state never shown;
    • the FI figure losing its marker;
    • the spending hint not privacy-sensitive;
    • the savings rate always labelled derived.

Blast radius

PlansController#show gains the plan lookup and, for a saved plan, its projection. The budget now resolves with the date captured at the top of the action, the same day Date.current gave it before. The budget and goals cards are unchanged.

Migration notes

No migration.

Screenshots

Savings-rate hints

The card with tracked spending equal to tracked income.

Before:

DesktopPhone
Light
Dark

After:

DesktopPhone
Light
Dark

The card

Before, desktop and phone:

Plan hub before

Plan hub before, phone

After, no saved plan:

Card empty state

Card empty state, phone

After, with #251's figures:

Card with a plan

Card with a plan, phone


Summary by cubic

Adds a "Financial independence" card to the Plan hub so users with a saved retirement plan can see their FI number, progress, and savings rate without leaving the hub. Without a saved plan the card shows an empty state that opens the settings modal, and computes nothing.

  • Progress floors and clamps at 0, so the figure never reads 100% before independence, never goes negative, and keeps counting past 100%; the bar stops at 100%.
  • The FI number and the living costs hint behind it are both privacy-sensitive, since the living costs and withdrawal rate together give the number away.
  • Accounts without an exchange rate for today are excluded and counted under the figures.
  • The projected total at retirement was dropped: the year-by-year planner, behind the card's planner link, is the one path a plan has.
  • PlansController#show captures Date.current once so the card's projection and the budget resolve the same day.
  • The savings rate names the income it applies to (hidden with the figures) and gets a warning when a derived rate hits 0 because spending meets or exceeds income, or when no income is tracked at all.
  • A plan with income but no living costs has no FI number, yet still shows the savings rate and its income beside the "add some spending" line.

Summary by CodeRabbit

  • New Features
    • The Plans page now shows a retirement summary with your financial-independence target, current assets, progress, and savings rate when a saved plan is available.
    • Use the summary links to update your plan or open the planner. If you haven’t set up a plan, you’ll see an option to get started.
  • Improvements
    • The summary explains when savings rates are estimated, income isn’t tracked, or expenses are unavailable.
    • It also warns when accounts are excluded because exchange rates are missing and shows progress beyond the financial-independence target.