fix(ui): harden summary and settings workflows

This commit is contained in:
Lucas Winther committed 2026-09-29 19:41:58 +02:00
1 parent c93ff9908c
commit aed2313167
10 files changed
+159 -36

No files matched your search

+5 -3
View File
@@ -174,7 +174,7 @@ export function expectedGroups(
*/
export function ExpectedBand({ monthId }: { monthId: MonthId }) {
const dataset = useDataset();
const { mutate } = useMutate();
const { mutate, error } = useMutate();
const [amounts, setAmounts] = useState<Record<string, string>>({});
const { pending, overdue, comingUp } = useMemo(
@@ -239,7 +239,7 @@ export function ExpectedBand({ monthId }: { monthId: MonthId }) {
size="sm"
variant="outline"
disabled={invalid}
onClick={() => {
onClick={async () => {
// Captured before mutate, per AGENTS.md: mutate defers behind
// the write queue and React resets the input first, so reading
// in the callback commits stale text. `invalid` already guards
@@ -247,12 +247,13 @@ export function ExpectedBand({ monthId }: { monthId: MonthId }) {
// `parsed` is either a real amount or the field was never
// touched.
if (invalid) return;
mutate((draft) =>
const saved = await mutate((draft) =>
confirmOccurrence(draft, occurrence.recurringId, occurrence.date, {
date: recordedDate ?? undefined,
amount: parsed ?? undefined,
}),
);
if (!saved) return;
setAmounts((current) => {
const next = { ...current };
delete next[key];
@@ -272,6 +273,7 @@ export function ExpectedBand({ monthId }: { monthId: MonthId }) {
title="Expected"
hint="Committed but not yet spent. These do not touch a post's balance until you confirm one, which records it as an ordinary purchase you can edit or delete afterwards."
>
{error && <p role="alert" className="mb-3 text-sm text-destructive">Could not confirm: {error}</p>}
{pending.length > 0 && (
<ul className="divide-y divide-budget-rule">
{pending.map((occurrence) => row(occurrence, recordedDateFor("pending", today)))}