mirror of
https://github.com/we-promise/sure.git
synced 2026-05-31 16:29:03 +00:00
Reshape the goals feature to live on top of linked-account balances. A goal's balance is now the live balance of every depository account linked to it — no parallel ledger, no "log a contribution" step. The "Add contribution" affordance is replaced by a 7-day GoalPledge (kind: transfer | manual_save). GoalPledge::Reconciler matches incoming Transactions (via Account::ProviderImportAdapter) and Valuations (via Account::ReconciliationManager) against open pledges within ±5 days, ±$0.50, or ±1% — single hook covers every provider (Plaid, SimpleFIN, Lunchflow, Enable Banking, Brex, IBKR, Kraken, SnapTrade) plus manual balance edits. A 15-minute Sidekiq cron sweeps expired pledges. Goal model: balance derived from linked_accounts.sum(&:balance), new pace (90-day net non-transfer inflow), months_of_runway, last_matched_pledge_*, pledge_action_label_key (the "I just transferred…" vs "I just saved…" verb switch). UI: - Index gets a 3-card KPI strip (Contributed last 30d / Needs this month / On track) plus a pending-pledges callout. - Show page swaps the "Add contribution" CTA for the pledge modal, replaces the contribution list with a pending-pledge banner, and rebuilds the funding widget into per-account rows with a 12-bucket weekly sparkline and last-30 inflow. - Projection chart adds a required-line (dashed light from today → target) and a translucent pending-pledge bump at today's X. Schema (3 migrations): 1. goal_pledges table with PG enums (goal_pledge_kind, goal_pledge_status), open-by-expiry index, and unique-when-not-null matched_transaction_id. 2. Drop goal_contributions. 3. Partial unique index on transactions ((extra -> 'goal' ->> 'pledge_id')) built CONCURRENTLY so it doesn't block prod. After pulling: run bin/rails db:migrate, then commit the schema.rb sync separately (or let CI regenerate). Deferred to v1.1: allocation columns, contention/archived banners, "why is this behind?" diagnostic, reallocate flow, refresh-sync + Plaid throttle, unallocated-cash chip, joint-account approval, goal_activities log, polymorphic matched_entry_id/type for manual pledge audit.
158 lines
8.5 KiB
Plaintext
158 lines
8.5 KiB
Plaintext
<%# locals: (goal:, linkable_accounts:) %>
|
|
|
|
<div data-controller="goal-stepper"
|
|
data-goal-stepper-currency-value="<%= Current.family.primary_currency_code %>"
|
|
data-goal-stepper-summary-with-date-value="<%= t("goals.form_stepper.step2.review.summary_with_date") %>"
|
|
data-goal-stepper-summary-no-date-value="<%= t("goals.form_stepper.step2.review.summary_no_date") %>"
|
|
data-goal-stepper-account-count-one-value="<%= t("goals.form_stepper.step2.review.account_count.one") %>"
|
|
data-goal-stepper-account-count-other-value="<%= t("goals.form_stepper.step2.review.account_count.other") %>"
|
|
data-goal-stepper-suggested-with-date-value="<%= t("goals.form_stepper.step2.review.suggested_with_date") %>"
|
|
data-goal-stepper-suggested-no-date-value="<%= t("goals.form_stepper.step2.review.suggested_no_date") %>">
|
|
<% if goal.errors[:base].any? %>
|
|
<%= render "shared/form_errors", model: goal %>
|
|
<% end %>
|
|
|
|
<%# Connected stepper %>
|
|
<div class="flex items-center gap-3 mb-6">
|
|
<div class="flex items-center gap-2" data-goal-stepper-target="step1Indicator">
|
|
<span data-goal-stepper-target="step1Circle" class="w-7 h-7 rounded-full inline-flex items-center justify-center bg-inverse text-inverse text-xs font-medium">1</span>
|
|
<span class="text-sm font-medium text-primary"><%= t("goals.form_stepper.step1.label") %></span>
|
|
</div>
|
|
<div class="flex-1 border-t-2 border-secondary" data-goal-stepper-target="stepperLine"></div>
|
|
<div class="flex items-center gap-2" data-goal-stepper-target="step2Indicator">
|
|
<span data-goal-stepper-target="step2Circle" class="w-7 h-7 rounded-full inline-flex items-center justify-center border border-secondary text-secondary text-xs font-medium">2</span>
|
|
<span class="text-sm font-medium text-secondary"><%= t("goals.form_stepper.step2.label") %></span>
|
|
</div>
|
|
</div>
|
|
|
|
<%= styled_form_with model: goal, url: goals_path, class: "space-y-4", data: { action: "keydown.enter->goal-stepper#blockEnter" } do |f| %>
|
|
<section data-goal-stepper-target="step1Panel" class="space-y-5">
|
|
<div>
|
|
<h3 class="text-lg font-semibold text-primary mb-1"><%= t("goals.form_stepper.step1.heading") %></h3>
|
|
<p class="text-sm text-secondary"><%= t("goals.form_stepper.step1.subheading") %></p>
|
|
</div>
|
|
|
|
<div class="flex justify-center">
|
|
<%= render "color_picker", form: f, colors: Goal::COLORS, icons: Goal::ICONS %>
|
|
</div>
|
|
|
|
<div>
|
|
<%= f.text_field :name,
|
|
placeholder: t("goals.form_stepper.step1.fields.name_placeholder"),
|
|
autofocus: true,
|
|
label: t("goals.form_stepper.step1.fields.name"),
|
|
data: { goal_stepper_target: "nameInput", action: "input->goal-stepper#nameChanged" } %>
|
|
<p class="hidden mt-1.5 text-xs text-destructive" data-goal-stepper-target="nameError"><%= t("goals.form_stepper.errors.name_required") %></p>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<%= f.money_field :target_amount,
|
|
label: t("goals.form_stepper.step1.fields.target_amount"),
|
|
hide_currency: true,
|
|
amount_data: { goal_stepper_target: "amountInput", action: "input->goal-stepper#amountChanged" } %>
|
|
<p class="hidden mt-1.5 text-xs text-destructive" data-goal-stepper-target="amountError"><%= t("goals.form_stepper.errors.amount_required") %></p>
|
|
</div>
|
|
<%= f.date_field :target_date,
|
|
label: t("goals.form_stepper.step1.fields.target_date") %>
|
|
</div>
|
|
|
|
<div>
|
|
<div class="mb-2">
|
|
<span class="block text-sm font-medium text-primary"><%= t("goals.form_stepper.step1.fields.funding_accounts") %></span>
|
|
<p class="text-xs text-secondary mt-0.5"><%= t("goals.form_stepper.step1.fields.funding_accounts_hint") %></p>
|
|
</div>
|
|
<div class="bg-container-inset rounded-lg p-1">
|
|
<% grouped = linkable_accounts.group_by { |a| a.subtype.to_s.presence || "other" } %>
|
|
<% grouped.each_with_index do |(subtype, accts), group_idx| %>
|
|
<div class="px-3 py-2 text-[11px] font-medium uppercase tracking-wide text-secondary"><%= t("goals.form_stepper.step1.subtypes.#{subtype}", default: subtype.titleize) %></div>
|
|
<div class="bg-container rounded-md <%= "mb-1" if group_idx < grouped.size - 1 %>">
|
|
<% accts.each_with_index do |account, idx| %>
|
|
<label class="flex items-center gap-3 px-3 py-2.5 cursor-pointer hover:bg-surface-hover <%= "border-t border-subdued" if idx > 0 %>">
|
|
<%= check_box_tag "goal[account_ids][]",
|
|
account.id,
|
|
false,
|
|
id: "goal_account_ids_#{account.id}",
|
|
class: "checkbox checkbox--light shrink-0",
|
|
data: {
|
|
goal_stepper_target: "linkedAccountCheckbox",
|
|
action: "change->goal-stepper#linkedAccountChanged",
|
|
account_name: account.name,
|
|
account_subtype: account.subtype || subtype,
|
|
account_balance: account.balance
|
|
} %>
|
|
<%= render Goals::AvatarComponent.new(name: account.name, color: Goals::AvatarComponent.color_for(account.name), size: "md") %>
|
|
<div class="flex-1 min-w-0">
|
|
<p class="text-sm font-medium text-primary truncate"><%= account.name %></p>
|
|
<p class="text-xs text-secondary"><%= (account.subtype || subtype).titleize %></p>
|
|
</div>
|
|
<span class="text-sm text-primary tabular-nums"><%= Money.new(account.balance, account.currency).format %></span>
|
|
</label>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<p class="hidden mt-1.5 text-xs text-destructive" data-goal-stepper-target="accountsError"><%= t("goals.form_stepper.errors.accounts_required") %></p>
|
|
</div>
|
|
|
|
<%= render DS::Disclosure.new(title: t("goals.form_stepper.step1.fields.notes_summary"), align: "right") do %>
|
|
<%= f.text_area :notes,
|
|
label: t("goals.form_stepper.step1.fields.notes"),
|
|
rows: 3,
|
|
placeholder: t("goals.form_stepper.step1.fields.notes_placeholder") %>
|
|
<% end %>
|
|
|
|
</section>
|
|
|
|
<section data-goal-stepper-target="step2Panel" class="space-y-5 hidden">
|
|
<div>
|
|
<h3 class="text-lg font-semibold text-primary mb-1"><%= t("goals.form_stepper.step2.heading") %></h3>
|
|
<p class="text-sm text-secondary"><%= t("goals.form_stepper.step2.subheading") %></p>
|
|
</div>
|
|
|
|
<div class="border border-subdued rounded-lg p-5 space-y-3">
|
|
<div class="flex items-center gap-3">
|
|
<%= render DS::FilledIcon.new(variant: :container, icon: "target", size: "lg", rounded: false) %>
|
|
<div class="min-w-0 flex-1">
|
|
<p class="text-base font-medium text-primary truncate" data-goal-stepper-target="reviewName">—</p>
|
|
<p class="text-sm text-secondary tabular-nums" data-goal-stepper-target="reviewSummary">—</p>
|
|
</div>
|
|
</div>
|
|
|
|
<p class="text-sm text-primary tabular-nums border-t border-subdued pt-3" data-goal-stepper-target="reviewSuggested">—</p>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="flex items-center pt-2">
|
|
<div class="hidden" data-goal-stepper-target="footerLeftButton">
|
|
<%= render DS::Button.new(
|
|
variant: "ghost",
|
|
text: t("goals.form_stepper.back"),
|
|
icon: "arrow-left",
|
|
icon_position: :left,
|
|
data: {
|
|
action: "click->goal-stepper#footerLeft"
|
|
}
|
|
) %>
|
|
</div>
|
|
<div class="ml-auto">
|
|
<%= render DS::Button.new(
|
|
text: t("goals.form_stepper.continue"),
|
|
variant: "primary",
|
|
icon: "arrow-right",
|
|
icon_position: :right,
|
|
data: {
|
|
goal_stepper_target: "footerRightButton",
|
|
action: "click->goal-stepper#footerRight"
|
|
}
|
|
) %>
|
|
</div>
|
|
<button type="submit"
|
|
class="sr-only"
|
|
tabindex="-1"
|
|
aria-hidden="true"
|
|
data-goal-stepper-target="submitButton"><%= t("goals.form_stepper.submit") %></button>
|
|
</div>
|
|
<% end %>
|
|
</div>
|