diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index 1898b12..826fe6b 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -4587,3 +4587,48 @@ rows", transactions 2 "show more" in steps of 20, plus a view-only list. ### Open problems - Not checked visually in a browser in this session. + +## HO-122: Confirm before deleting or disconnecting; fix links on a filtered new transaction + +- **Date:** 2026-10-11 (UTC) +- **Author:** Muhammad Tahub Khatri with Claude Code +- **Branch / PR:** `fix/ui-confirmations` / PR linked from the branch + +### What changed +- **Broken links:** adding a transaction from a filtered list + (`/transactions/new?account=…`) built "Review transfers" as + `…/transactions?account=…/transfers` and left the Bills link pointing + at Transactions. `transactionsPath()` in `transaction-form.tsx` drops + the query for those links; Cancel keeps the filter. +- **Confirmations:** new shared `Confirm` (`src/components/ui/confirm.tsx`), + a `
` that names the action, says what happens, and holds a + "Confirm …" button, like Recurring's "Remove tracking". Used for: + - Import: Discard (deletes the preview and its saved CSV) + - Budgets: Remove budget + - Bills: Unlink payment + - Settings: Disconnect (phone) +- **Day panel ×:** the first press turns it into "Remove?" on the same + button (focus stays), the second removes; moving away resets it. +- Not changed: Bills "Stop tracking bill" and "Dismiss pattern" and + Recurring "Not recurring" have a Restore, so they stay one click. +- **Dates:** Transfers showed raw ISO dates ("2026-07-14") and Recurring + the raw next date; both now read "Jul 14, 2026". +- **Live regions:** Bills and Budgets form results keep an empty + `role="status"` mounted (`.live-region`, no space while empty), so the + first message is announced. +- Tests: `transaction-form.test.ts` (Vitest) for `transactionsPath`; + e2e updated for every confirmed action (`pdf-import`, `bills`, + `budgets`, `agent-link`, `calendar`) and `transactions.spec.ts` checks + the hint links on a filtered new transaction. + +### Verified +- `pnpm lint`, `typecheck`, `format:check`, `docs:check` and `build` + pass. `pnpm test:unit`: everything passes except the Neon storage tests, + which need `storage-tests` credentials this container does not have. +- Playwright was not run (Muhammad runs it). + +### What's next +- One shared button style for every feature (still per feature). + +### Open problems +- None. diff --git a/src/app/globals.css b/src/app/globals.css index 955e699..a3cf908 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -175,6 +175,17 @@ select { color: inherit; } +/* A status message that stays in the page so screen readers announce its + first message; while empty it takes no space. */ +.live-region:empty { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; +} + :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; diff --git a/src/components/ui/confirm.module.css b/src/components/ui/confirm.module.css new file mode 100644 index 0000000..5cb019f --- /dev/null +++ b/src/components/ui/confirm.module.css @@ -0,0 +1,32 @@ +/* Uses the tokens in src/app/globals.css (ADR-046). */ + +.confirm { + display: grid; + justify-items: start; + gap: 0.5rem; +} + +.confirm > summary { + padding: 0.5rem 1rem; + border: 1px solid var(--line); + border-radius: 8px; + background: var(--surface); + color: var(--ink); + cursor: pointer; + list-style: none; +} + +.confirm > summary::-webkit-details-marker { + display: none; +} + +.confirm > summary:hover, +.confirm[open] > summary { + background: var(--tint); +} + +.consequence { + max-width: 40rem; + color: var(--ink-soft); + font-size: 0.875rem; +} diff --git a/src/components/ui/confirm.tsx b/src/components/ui/confirm.tsx new file mode 100644 index 0000000..6d8ebf3 --- /dev/null +++ b/src/components/ui/confirm.tsx @@ -0,0 +1,26 @@ +import type { ReactNode } from "react"; +import styles from "./confirm.module.css"; + +type Props = { + /** What the action does, e.g. "Remove budget". Opens the confirmation. */ + label: string; + /** One sentence on what happens and what can't be undone. */ + consequence: string; + /** The button that does it, labelled "Confirm …". */ + children: ReactNode; +}; + +/** + * An action that deletes or disconnects something, behind one more click: + * the first names it, the panel says what happens, the button inside does + * it. The same shape as Recurring's "Remove tracking". + */ +export function Confirm({ label, consequence, children }: Props) { + return ( +
+ {label} +

{consequence}

+ {children} +
+ ); +} diff --git a/src/features/bills/ui/bills-page.tsx b/src/features/bills/ui/bills-page.tsx index 0b78e60..8c55ed4 100644 --- a/src/features/bills/ui/bills-page.tsx +++ b/src/features/bills/ui/bills-page.tsx @@ -1,4 +1,5 @@ import Link from "next/link"; +import { Confirm } from "@/components/ui/confirm"; import { shiftDays } from "@/features/recurring/client"; import { cents, formatCents, toDecimalString } from "@/lib/money"; import { isSettled, type CycleStatus, type CycleView } from "../domain/cycles"; @@ -215,16 +216,21 @@ function BillDetail({ data }: { data: BillsView }) {

) : null} {editable ? ( - + consequence="This invoice will no longer count this transaction as its payment. The transaction itself stays." + > + + ) : null} ))} diff --git a/src/features/bills/ui/forms.tsx b/src/features/bills/ui/forms.tsx index beb6d15..3a4e514 100644 --- a/src/features/bills/ui/forms.tsx +++ b/src/features/bills/ui/forms.tsx @@ -88,7 +88,10 @@ function Feedback({ state }: { state: FormState }) { return ( <> {state.errors.form ?

{state.errors.form}

: null} - {state.message ?

{state.message}

: null} + {/* Always there, so the first message is announced too. */} +

+ {state.message} +

); } diff --git a/src/features/budgets/ui/budgets-page.tsx b/src/features/budgets/ui/budgets-page.tsx index 3ab4be8..0d49f37 100644 --- a/src/features/budgets/ui/budgets-page.tsx +++ b/src/features/budgets/ui/budgets-page.tsx @@ -1,4 +1,5 @@ import Link from "next/link"; +import { Confirm } from "@/components/ui/confirm"; import { absolute, formatCents } from "@/lib/money"; import { copyBudgetsAction, @@ -191,15 +192,20 @@ export function BudgetsPage({ data }: { data: BudgetsView }) { )} /> {row.allocation !== null ? ( - + consequence="This clears the plan for this category this month. Spending stays as it is; you can set a new budget any time." + > + + ) : null} ) : null} diff --git a/src/features/budgets/ui/forms.tsx b/src/features/budgets/ui/forms.tsx index 7968609..8ab29d6 100644 --- a/src/features/budgets/ui/forms.tsx +++ b/src/features/budgets/ui/forms.tsx @@ -53,7 +53,10 @@ export function BudgetForm({

) : null} {state.errors.form ?

{state.errors.form}

: null} - {state.message ?

{state.message}

: null} + {/* Always there, so the first message is announced too. */} +

+ {state.message} +

); } @@ -72,7 +75,10 @@ export function BudgetOperation({ {pending ? "Saving…" : label} {state.errors.form ?

{state.errors.form}

: null} - {state.message ?

{state.message}

: null} + {/* Always there, so the first message is announced too. */} +

+ {state.message} +

); } diff --git a/src/features/cashflow/ui/day-panel.tsx b/src/features/cashflow/ui/day-panel.tsx index 4591f4a..cf6d174 100644 --- a/src/features/cashflow/ui/day-panel.tsx +++ b/src/features/cashflow/ui/day-panel.tsx @@ -200,6 +200,35 @@ function AddForm({ ); } +/** + * × asks once more before it removes: the first press turns it into + * "Remove?", the second removes. It stays the same button, so focus stays + * on it; moving away puts the × back. + */ +function RemoveButton({ + name, + disabled, + onRemove, +}: { + name: string; + disabled: boolean; + onRemove: () => void; +}) { + const [armed, setArmed] = useState(false); + return ( + + ); +} + export function DayPanel({ workspaceId, day, @@ -309,26 +338,18 @@ export function DayPanel({ > It happened - + onRemove={() => remove(item)} + /> ) : canEdit && item.removable ? ( - + onRemove={() => remove(item)} + /> ) : item.isPlan ? ( ) : ( diff --git a/src/features/imports/ui/preview-panel.tsx b/src/features/imports/ui/preview-panel.tsx index ee1a81f..7e8fb14 100644 --- a/src/features/imports/ui/preview-panel.tsx +++ b/src/features/imports/ui/preview-panel.tsx @@ -2,6 +2,7 @@ import { useActionState, useId } from "react"; import { useFormStatus } from "react-dom"; +import { Confirm } from "@/components/ui/confirm"; import { formatCents, formatSigned } from "@/lib/money"; import { type Check, formatStatementDate } from "../domain/checks"; import type { StatementRow } from "../domain/statement"; @@ -29,7 +30,7 @@ function DiscardButton() { const { pending } = useFormStatus(); return ( ); } @@ -143,9 +144,14 @@ export function PreviewPanel({ -
- - + +
+ + +
)} diff --git a/src/features/messaging/ui/phone-link-card.tsx b/src/features/messaging/ui/phone-link-card.tsx index 3038b99..869b884 100644 --- a/src/features/messaging/ui/phone-link-card.tsx +++ b/src/features/messaging/ui/phone-link-card.tsx @@ -2,6 +2,7 @@ import { useRouter } from "next/navigation"; import { useEffect, useOptimistic, useState, useTransition } from "react"; +import { Confirm } from "@/components/ui/confirm"; import { APP_NAME } from "@/config/app"; import { formatLinkCode } from "../domain/link-code"; import { @@ -234,14 +235,19 @@ export function PhoneLinkCard({ workspaceId, state, agentPhone }: Props) { iPhone’s Notifications settings.

- + + or text STOP
diff --git a/src/features/recurring/ui/recurring-page.tsx b/src/features/recurring/ui/recurring-page.tsx index 64e1d96..dd95676 100644 --- a/src/features/recurring/ui/recurring-page.tsx +++ b/src/features/recurring/ui/recurring-page.tsx @@ -1,6 +1,7 @@ import Link from "next/link"; import { NavRefresh } from "@/components/ui/nav-refresh"; import { formatCents } from "@/lib/money"; +import { longDate } from "../domain/evidence"; import type { FormAction } from "../domain/forms"; import type { Payment, summarizePayments } from "../domain/payments"; import { ChargeEvidence } from "./charge-evidence"; @@ -103,7 +104,11 @@ function PaymentCard({ ? "Expected next payday" : "Expected next charge"} -
{payment.nextOn ?? "Unknown — add a date to resume tracking"}
+
+ {payment.nextOn + ? longDate(payment.nextOn) + : "Unknown — add a date to resume tracking"} +
{payment.sampleCount ? ( diff --git a/src/features/transactions/ui/transaction-form.test.ts b/src/features/transactions/ui/transaction-form.test.ts new file mode 100644 index 0000000..c07f28a --- /dev/null +++ b/src/features/transactions/ui/transaction-form.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from "vitest"; +import { transactionsPath } from "./transaction-form"; + +describe("transactionsPath", () => { + it("drops the account filter, so Review transfers and Bills links work", () => { + const path = transactionsPath("/w/ws-1/transactions?account=acc-1"); + + expect(path).toBe("/w/ws-1/transactions"); + expect(`${path}/transfers`).toBe("/w/ws-1/transactions/transfers"); + expect(path.replace(/\/transactions$/, "/bills")).toBe("/w/ws-1/bills"); + }); + + it("leaves a plain Transactions path as it is", () => { + expect(transactionsPath("/w/ws-1/transactions")).toBe( + "/w/ws-1/transactions", + ); + }); +}); diff --git a/src/features/transactions/ui/transaction-form.tsx b/src/features/transactions/ui/transaction-form.tsx index ca838bd..982d509 100644 --- a/src/features/transactions/ui/transaction-form.tsx +++ b/src/features/transactions/ui/transaction-form.tsx @@ -69,6 +69,13 @@ function Note({ } /** Add or edit a transaction by hand (F-04). */ +/** + * The Transactions page itself. Cancel can carry an account filter + * (`…/transactions?account=…`), which links to subpages must drop. + */ +export const transactionsPath = (cancelHref: string): string => + cancelHref.split("?")[0]!; + export function TransactionForm({ action, initial, @@ -91,6 +98,7 @@ export function TransactionForm({ transfer: useId(), }; const { errors } = state; + const transactionsHref = transactionsPath(cancelHref); // After a rejected submit, show what was typed rather than the start values. const value = (name: TransactionFormField): string => state.values ? (state.values[name] ?? "") : initial[name]; @@ -242,10 +250,10 @@ export function TransactionForm({ )}

- Review transfers to pair - activity or remove a relationship. Linked bill evidence must be reviewed - in{" "} - + Review transfers to + pair activity or remove a relationship. Linked bill evidence must be + reviewed in{" "} + Bills {" "} before changing its transfer label. diff --git a/src/features/transfers/ui/review-page.tsx b/src/features/transfers/ui/review-page.tsx index 20e9a23..07eccca 100644 --- a/src/features/transfers/ui/review-page.tsx +++ b/src/features/transfers/ui/review-page.tsx @@ -28,6 +28,16 @@ function href( if (value !== undefined) search.set(key, String(value)); return `/w/${workspaceId}/transactions/transfers?${search}`; } +// "Oct 9, 2026", read as a calendar date (UTC), so it is the same on the +// server and in the browser. +const dateFormat = new Intl.DateTimeFormat("en-US", { + month: "short", + day: "numeric", + year: "numeric", + timeZone: "UTC", +}); +const day = (iso: string) => dateFormat.format(new Date(`${iso}T00:00:00Z`)); + function amount(row: ReviewRow) { return Number.isSafeInteger(row.amountCents) ? formatSigned(cents(row.amountCents)) @@ -38,7 +48,7 @@ function Fact({ row }: { row: ReviewRow }) {

{row.accountName} - {row.postedOn} · {amount(row)} + {day(row.postedOn)} · {amount(row)} {row.description} @@ -125,7 +135,7 @@ function ReviewForm({ onChange={() => setSelected(row.id)} /> - {row.accountName} · {row.postedOn} ·{" "} + {row.accountName} · {day(row.postedOn)} ·{" "} {amount(row)}
{row.description} @@ -217,8 +227,8 @@ export function TransferReviewPage({

{defaultWindow ? "90-day review window" : "Selected review window"}:{" "} - {query.from} through {query.to}. This page shows bounded recorded - activity, not a complete account history. + {day(query.from)} through {day(query.to)}. This page shows bounded + recorded activity, not a complete account history.

{!data.canEdit && (

diff --git a/tests/e2e/agent-link.spec.ts b/tests/e2e/agent-link.spec.ts index 06bd27a..bea48d7 100644 --- a/tests/e2e/agent-link.spec.ts +++ b/tests/e2e/agent-link.spec.ts @@ -188,7 +188,8 @@ test("the opt-in is off until chosen, and Disconnect unlinks", async ({ await expect(optIn).toBeChecked(); await hydrated(page, "main button"); - await page.getByRole("button", { name: "Disconnect" }).click(); + await page.getByText("Disconnect", { exact: true }).click(); + await page.getByRole("button", { name: "Confirm disconnect" }).click(); await expect( page.getByRole("button", { name: "Connect iMessage" }), diff --git a/tests/e2e/bills.spec.ts b/tests/e2e/bills.spec.ts index 869bbad..940b9cb 100644 --- a/tests/e2e/bills.spec.ts +++ b/tests/e2e/bills.spec.ts @@ -149,9 +149,12 @@ test("tracks variable invoices, partial/full payments, unlinking and manual mark detail(f.page).getByText("Paid from posted activity", { exact: true }), ).toBeVisible(); await detail(f.page) - .getByRole("button", { name: "Unlink payment" }) + .getByText("Unlink payment", { exact: true }) .first() .click(); + await detail(f.page) + .getByRole("button", { name: "Confirm unlink payment" }) + .click(); await expect( detail(f.page).getByText("Partially paid", { exact: true }), ).toBeVisible(); @@ -271,7 +274,10 @@ test("requires explicit payment confirmation and reviews edited or deleted payme await expect( detail(f.page).getByRole("link", { name: "View recorded transaction" }), ).toHaveCount(0); - await detail(f.page).getByRole("button", { name: "Unlink payment" }).click(); + await detail(f.page).getByText("Unlink payment", { exact: true }).click(); + await detail(f.page) + .getByRole("button", { name: "Confirm unlink payment" }) + .click(); await expect( detail(f.page).getByText("Unpaid", { exact: true }), ).toBeVisible(); diff --git a/tests/e2e/budgets.spec.ts b/tests/e2e/budgets.spec.ts index 74432fc..2c73726 100644 --- a/tests/e2e/budgets.spec.ts +++ b/tests/e2e/budgets.spec.ts @@ -221,7 +221,10 @@ test("distinguishes zero from unset, keeps spending after removal and retains in "aria-valuenow", "100", ); - await card(f.page).getByRole("button", { name: "Remove budget" }).click(); + await card(f.page).getByText("Remove budget", { exact: true }).click(); + await card(f.page) + .getByRole("button", { name: "Confirm remove budget" }) + .click(); await expect(figure(card(f.page), "Allocation")).toHaveText("Not set"); await expect(figure(card(f.page), "Spent")).toHaveText("$340.00"); await expect(card(f.page).getByRole("progressbar")).toHaveCount(0); diff --git a/tests/e2e/calendar.spec.ts b/tests/e2e/calendar.spec.ts index e561da5..5b007af 100644 --- a/tests/e2e/calendar.spec.ts +++ b/tests/e2e/calendar.spec.ts @@ -126,7 +126,15 @@ test("opens on today with the account's balance, and adding and removing spendin ).toBeVisible(); await expect(cell(page, today)).toContainText("Bus pass"); - await dayPanel(page).getByRole("button", { name: "Remove Bus pass" }).click(); + // × asks once more, on the same button, before it removes. + const remove = dayPanel(page).getByRole("button", { + name: "Remove Bus pass", + }); + await remove.click(); + await expect(headline(page)).toHaveText("You have $484.00 today."); + await dayPanel(page) + .getByRole("button", { name: "Confirm remove Bus pass" }) + .click(); await expect(headline(page)).toHaveText("You have $500.00 today."); await expect(dayPanel(page).getByText("Bus pass")).toHaveCount(0); @@ -406,6 +414,9 @@ test("plans spending on a later day, sees what it does, and removes it", async ( await dayPanel(page) .getByRole("button", { name: "Remove Concert tickets" }) .click(); + await dayPanel(page) + .getByRole("button", { name: "Confirm remove Concert tickets" }) + .click(); await expect(dayPanel(page).getByText("Concert tickets")).toHaveCount(0); await expect(dayPanel(page).locator(".panel-totals")).toContainText( "$500.00", diff --git a/tests/e2e/pdf-import.spec.ts b/tests/e2e/pdf-import.spec.ts index 5537dbb..3a64702 100644 --- a/tests/e2e/pdf-import.spec.ts +++ b/tests/e2e/pdf-import.spec.ts @@ -146,7 +146,9 @@ test("keeps a preview waiting until it is discarded", async ({ await expect(waiting).toContainText("Everyday ••1234 (360 Checking, PDF)"); await waiting.getByRole("link", { name: "Review" }).click(); await hydrated(page, "form button"); - await page.getByRole("button", { name: "Discard" }).click(); + // Discarding deletes the saved copy, so it asks once more. + await page.getByText("Discard", { exact: true }).click(); + await page.getByRole("button", { name: "Confirm discard" }).click(); await expect(page).toHaveURL(/\/w\/[^/]+\/import$/); await expect( diff --git a/tests/e2e/transactions.spec.ts b/tests/e2e/transactions.spec.ts index 82de7a0..544e8b1 100644 --- a/tests/e2e/transactions.spec.ts +++ b/tests/e2e/transactions.spec.ts @@ -156,6 +156,22 @@ test("filters the list to one account", async ({ browser, baseURL }) => { await expect(page).toHaveURL(/\?account=[0-9a-f-]{36}$/); await expect(row(page, "Electric")).toBeVisible(); await expect(row(page, "Coffee")).toHaveCount(0); + // Adding from the filtered list: Cancel keeps the filter, but the hint's + // links go to Review transfers and Bills themselves. + await page.getByRole("link", { name: "Add a transaction" }).click(); + await expect(page).toHaveURL(/\/transactions\/new\?account=/); + const main = page.getByRole("main"); + await expect( + main.getByRole("link", { name: "Review transfers" }), + ).toHaveAttribute("href", /\/w\/[^/]+\/transactions\/transfers$/); + await expect(main.getByRole("link", { name: "Bills" })).toHaveAttribute( + "href", + /\/w\/[^/]+\/bills$/, + ); + await expect(page.getByRole("link", { name: "Cancel" })).toHaveAttribute( + "href", + /\/transactions\?account=[0-9a-f-]{36}$/, + ); }); test("another user's transaction is not found", async ({