From 38381bc03a50b99f2d4d48f56aa6fcb3efe23a79 Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 23 Nov 2026 16:02:38 +0100 Subject: [PATCH] refactor(costs): let the summary card tell an unknown balance itself Keeps the Costs panel within its size budget. --- .../src/components/Budget/CostsPanel.test.tsx | 6 ++---- client/src/components/Budget/CostsPanel.tsx | 19 ++++++------------- .../components/Budget/CostsSummaryCard.tsx | 11 ++++++++++- .../src/components/Budget/useCostsLedger.ts | 2 ++ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/client/src/components/Budget/CostsPanel.test.tsx b/client/src/components/Budget/CostsPanel.test.tsx index 4b1f4d308..5024c9ec8 100644 --- a/client/src/components/Budget/CostsPanel.test.tsx +++ b/client/src/components/Budget/CostsPanel.test.tsx @@ -1084,11 +1084,9 @@ describe('CostsPanel — settle up', () => { render() await screen.findByText('Balances') - // Settle up, Balances, Final budget and the owe and owed cards all hang off the one failed request. await waitFor(() => expect(screen.getAllByText('Unknown error')).toHaveLength(5)) - expect(screen.queryByText("Everyone's square")).toBeNull() - expect(screen.queryByText("You're all settled up")).toBeNull() - expect(screen.queryByText('Nothing owed to you')).toBeNull() + for (const gone of ["Everyone's square", "You're all settled up", 'Nothing owed to you']) + expect(screen.queryByText(gone)).toBeNull() }) it('FE-W5COSTS-013: the "you owe" card lists who I still have to pay', async () => { diff --git a/client/src/components/Budget/CostsPanel.tsx b/client/src/components/Budget/CostsPanel.tsx index bd0c5da6d..812932936 100644 --- a/client/src/components/Budget/CostsPanel.tsx +++ b/client/src/components/Budget/CostsPanel.tsx @@ -77,7 +77,7 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps me, base, tripCurrency, ctx, settlement, settlementError, loadSettlement, balancesKnown, knownNames, splitting, search, setSearch, segment: filter, setSegment: setFilter, catFilter, setCatFilter, dayFilter, setDayFilter, totals, filtered, filteredSettlements, catBreakdown, countedCount, leftOutLabel, toggleLeftOutCat, countAllCats, exportCsv: handleExportCsv, - deleteExpense: handleDelete, undoSettlement, settleFlow, settleAll, canSettle, setBase, baseOptions, + deleteExpense: handleDelete, undoSettlement, settleFlow, settleAll, canSettle, setBase, baseOptions, settledUp, } = useCostsLedger({ tripId, trip, budgetItems, memberCount: tripMembers.length, actions: { loadBudgetItems, deleteBudgetItem }, canEdit, t, toast, settlementOnTripChange: true, skipUnfinishedShares: true, csvCurrencyAsStored: true, @@ -288,22 +288,20 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps {!splitting ?
{totalCard}
: (
} tone="owe" - foot={!balancesKnown ? balancesUnknown() - : totals.owe > 0.01 + icon={} tone="owe" failed={settlementError} + foot={totals.owe > 0.01 ? f.from.user_id === me).map(f => f.to.user_id)} lead={t('costs.to')} Avatar={Avatar} name={personName} /> : {t('costs.allSettled')}} /> } tone="owed" - foot={!balancesKnown ? balancesUnknown() - : totals.owed > 0.01 + icon={} tone="owed" failed={settlementError} + foot={totals.owed > 0.01 ? f.to.user_id === me).map(f => f.from.user_id)} lead={t('costs.from')} Avatar={Avatar} name={personName} /> : {t('costs.nothingOwed')}} /> } tone="unfinished" foot={totals.outstandingCount > 0 ? {totals.outstandingCount} {t('costs.outstandingItems', { count: totals.outstandingCount })} - : balancesKnown && !settlement?.flows?.length && {t('costs.allSettled')}} /> + : settledUp && {t('costs.allSettled')}} /> {totalCard}
)} @@ -445,11 +443,6 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps ) - // The owe and owed cards say why their figure is missing instead of claiming zero. - function balancesUnknown() { - return {t(settlementError ? 'common.unknownError' : 'common.loading')} - } - // Settle-up and Balances both come from the one settlement request, so they // share the notice that says the numbers are missing rather than zero. function loadFailed() { diff --git a/client/src/components/Budget/CostsSummaryCard.tsx b/client/src/components/Budget/CostsSummaryCard.tsx index 329b99ad0..9453aa943 100644 --- a/client/src/components/Budget/CostsSummaryCard.tsx +++ b/client/src/components/Budget/CostsSummaryCard.tsx @@ -1,3 +1,4 @@ +import { useTranslation } from '../../i18n'; import { currencyDecimals, currencyLocale, formatMoney } from '../../utils/formatters'; import { fs } from '../shared/DialogShell'; @@ -26,6 +27,7 @@ export default function SummaryCard({ icon, foot, tone, + failed = false, }: { label: string; sub: string; @@ -35,7 +37,10 @@ export default function SummaryCard({ icon: React.ReactNode; foot: React.ReactNode; tone: 'owe' | 'owed' | 'total' | 'unfinished'; + /** With no amount: the read failed rather than still running. */ + failed?: boolean; }) { + const { t } = useTranslation(); const color = TONE_COLOR[tone]; // formatToParts keeps the design's "big integer + muted symbol/decimals" styling // while letting Intl place the symbol and pick separators per locale + currency. @@ -102,7 +107,11 @@ export default function SummaryCard({ )}
- {foot} + {amount == null ? ( + {t(failed ? 'common.unknownError' : 'common.loading')} + ) : ( + foot + )}
diff --git a/client/src/components/Budget/useCostsLedger.ts b/client/src/components/Budget/useCostsLedger.ts index c0c4c0d28..71bd15d55 100644 --- a/client/src/components/Budget/useCostsLedger.ts +++ b/client/src/components/Budget/useCostsLedger.ts @@ -238,6 +238,7 @@ export function useCostsLedger({ return flows.map((f) => ({ ...f, amount: Math.round(f.amount * displayPerTrip * unit) / unit })); }, [settlementError, settlement, settledIn, base, tripCurrency, displayPerTrip, flows]); const balancesKnown = shownFlows != null; + const settledUp = balancesKnown && !settlement?.flows?.length; // `ctx` carries the rates. They can land after the expenses, and without it in the // deps the cards kept the sums they were first added up with while the rows moved on. const totals = useMemo( @@ -367,6 +368,7 @@ export function useCostsLedger({ loadSettlement, flows, balancesKnown, + settledUp, canSettle, splitting, knownNames,