Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

refactor(costs): let the summary card tell an unknown balance itself

Maurice38381bc03a50
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(<CostsPanel tripId={1} tripMembers={tripMembers} />)
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 ? <div style={{ marginBottom: 36 }}>{totalCard}</div> : (
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 16, marginBottom: 36 }} className="costs-summary">
<SummaryCard label={t('costs.youOwe')} sub={t('costs.youOweSub')} amount={balancesKnown ? totals.owe : null} currency={base} locale={locale}
- icon={<ArrowDown size={18} />} tone="owe"
- foot={!balancesKnown ? balancesUnknown()
- : totals.owe > 0.01
+ icon={<ArrowDown size={18} />} tone="owe" failed={settlementError}
+ foot={totals.owe > 0.01
? <FlowPills ids={(settlement?.flows || []).filter(f => f.from.user_id === me).map(f => f.to.user_id)} lead={t('costs.to')} Avatar={Avatar} name={personName} />
: <span className="text-content-faint">{t('costs.allSettled')}</span>} />
<SummaryCard label={t('costs.youreOwed')} sub={t('costs.youreOwedSub')} amount={balancesKnown ? totals.owed : null} currency={base} locale={locale}
- icon={<ArrowUp size={18} />} tone="owed"
- foot={!balancesKnown ? balancesUnknown()
- : totals.owed > 0.01
+ icon={<ArrowUp size={18} />} tone="owed" failed={settlementError}
+ foot={totals.owed > 0.01
? <FlowPills ids={(settlement?.flows || []).filter(f => f.to.user_id === me).map(f => f.from.user_id)} lead={t('costs.from')} Avatar={Avatar} name={personName} />
: <span className="text-content-faint">{t('costs.nothingOwed')}</span>} />
<SummaryCard label={t('costs.outstanding')} sub={t('costs.outstandingSub')} amount={totals.outstanding} currency={base} locale={locale}
icon={<AlertCircle size={18} />} tone="unfinished"
foot={totals.outstandingCount > 0
? <span><b>{totals.outstandingCount}</b> {t('costs.outstandingItems', { count: totals.outstandingCount })}</span>
- : balancesKnown && !settlement?.flows?.length && <span className="text-content-faint">{t('costs.allSettled')}</span>} />
+ : settledUp && <span className="text-content-faint">{t('costs.allSettled')}</span>} />
{totalCard}
</div>)}
@@ -445,11 +443,6 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps
</div>
)
- // The owe and owed cards say why their figure is missing instead of claiming zero.
- function balancesUnknown() {
- return <span className="text-content-faint">{t(settlementError ? 'common.unknownError' : 'common.loading')}</span>
- }
-
// 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({
)}
</div>
<div className="mt-auto flex flex-wrap items-center gap-1.5 text-content-muted" style={fs(12.5, 'body')}>
- {foot}
+ {amount == null ? (
+ <span className="text-content-faint">{t(failed ? 'common.unknownError' : 'common.loading')}</span>
+ ) : (
+ foot
+ )}
</div>
</div>
</section>
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,