From 01ad13623c0b287cf96ce9546b51eaad0530ab60 Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 2 Dec 2026 22:03:08 +0100 Subject: [PATCH] fix(ui): refine trip forms and planner empty states --- client/scripts/size-baseline.json | 2 +- .../components/Budget/CostsPanel.helpers.ts | 22 +++ .../src/components/Budget/CostsPanel.test.tsx | 10 +- client/src/components/Budget/CostsPanel.tsx | 60 +++---- .../components/Collections/ListsRail.test.tsx | 5 + .../src/components/Collections/ListsRail.tsx | 2 +- .../Planner/DayPlanPlaceSubline.tsx | 18 +- .../components/Trips/TripFormModal.test.tsx | 6 +- client/src/components/Trips/TripFormModal.tsx | 58 +++--- client/src/components/shared/DialogShell.tsx | 4 +- .../screens/collections/MCollListNav.tsx | 2 +- .../mobile/screens/dashboard/MDashboard.tsx | 4 +- .../screens/dashboard/MNewTripSheet.tsx | 36 ++-- .../screens/trip/sheets/PlSheetChrome.tsx | 19 +- .../mobile/screens/trip/tabs/MCostsTab.tsx | 169 +++++++++++------- .../mobile/screens/trip/tabs/tabChrome.tsx | 2 +- client/src/pages/DashboardPage.tsx | 34 ++-- .../src/pages/collections/useCollections.ts | 5 +- client/src/pages/dashboard/useDashboard.ts | 11 +- 19 files changed, 286 insertions(+), 183 deletions(-) diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json index 8f908e437..607b0ed91 100644 --- a/client/scripts/size-baseline.json +++ b/client/scripts/size-baseline.json @@ -4,7 +4,7 @@ "src/components/Admin/AdminPluginsPanel.test.tsx": 2704, "src/components/Admin/AdminPluginsPanel.tsx": 1265, "src/components/Budget/CostsPanel.test.tsx": 2725, - "src/components/Budget/CostsPanel.tsx": 1607, + "src/components/Budget/CostsPanel.tsx": 1588, "src/components/Map/MapView.tsx": 1191, "src/components/Map/MapViewGL.test.tsx": 2919, "src/components/Map/MapViewGL.tsx": 2083, diff --git a/client/src/components/Budget/CostsPanel.helpers.ts b/client/src/components/Budget/CostsPanel.helpers.ts index 90c240a43..a72af269b 100644 --- a/client/src/components/Budget/CostsPanel.helpers.ts +++ b/client/src/components/Budget/CostsPanel.helpers.ts @@ -17,6 +17,7 @@ import { amountToInputString, currencyDecimals } from '../../utils/formatters' import { localIsoDate } from '../../utils/localDate' import type { ExpensePrefill } from './CostsPanel' import type { BudgetItem } from '../../types' +import type { CostsSettlement } from './costsModel' // The split and receipt fields guard their own precision on every keystroke, so the // guard has to follow the currency: a three-decimal one (KWD, BHD, …) seeds three @@ -329,3 +330,24 @@ export function expenseEditorFor( if (receipt) return { key: 'receipt', editing: null, prefill: receipt, close: closeReceipt } return null } + +/** Expenses and settle-up payments grouped newest day first in the Costs ledger. */ +export function groupLedgerByDay(expenses: readonly BudgetItem[], payments: readonly CostsSettlement[], locale: string, noDate: string) { + const entries = [ + ...expenses.map(e => ({ kind: 'expense' as const, date: e.expense_date || '', e })), + ...payments.map(s => ({ kind: 'payment' as const, date: settlementDate(s), s })), + ].sort((a, b) => b.date.localeCompare(a.date)) + const groups = new Map() + for (const entry of entries) { + let label = noDate + if (entry.date) { + try { + label = new Date(entry.date + 'T00:00:00Z').toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' }) + } catch { label = entry.date } + } + const group = groups.get(label) + if (group) group.push(entry) + else groups.set(label, [entry]) + } + return [...groups].map(([day, entries]) => ({ day, entries })) +} diff --git a/client/src/components/Budget/CostsPanel.test.tsx b/client/src/components/Budget/CostsPanel.test.tsx index 5024c9ec8..904af97f5 100644 --- a/client/src/components/Budget/CostsPanel.test.tsx +++ b/client/src/components/Budget/CostsPanel.test.tsx @@ -944,13 +944,13 @@ describe('CostsPanel — overview', () => { expect(labels).toEqual(['Food & drink', 'Transport']) expect(within(breakdown).getByText('90 €')).toBeInTheDocument() expect(within(breakdown).getByText('30 €')).toBeInTheDocument() - }) + }); - it('FE-W5COSTS-006: an empty trip shows the empty ledger and the empty breakdown', async () => { + it('FE-W5COSTS-006: an empty trip shows the empty ledger without a total or category breakdown', async () => { mount([]) - - expect(await screen.findByText('No expenses yet. Add your first one.')).toBeInTheDocument() - expect(screen.getByText('No expenses yet.')).toBeInTheDocument() + expect(await screen.findByText('No expenses yet. Add your first one.')).toBeInTheDocument(); + expect(screen.queryByRole('region', { name: 'Total trip spend' })).toBeNull(); + expect(screen.queryByRole('region', { name: 'By category' })).toBeNull(); expect(screen.getByText("Everyone's square")).toBeInTheDocument() }) diff --git a/client/src/components/Budget/CostsPanel.tsx b/client/src/components/Budget/CostsPanel.tsx index 812932936..88abe0b7f 100644 --- a/client/src/components/Budget/CostsPanel.tsx +++ b/client/src/components/Budget/CostsPanel.tsx @@ -13,7 +13,7 @@ import { CustomDatePicker } from '../shared/CustomDateTimePicker' import { useReceiptScan } from './useReceiptScan' import { ReceiptScanModal } from './ReceiptScanModal' import { SPLIT_COLORS } from './BudgetPanel.constants' -import { finalBudgetFor, finalBudgetSources, formerParticipantRows, NOTE_MAX, paidByUser, readUserNote, settlementDate } from './CostsPanel.helpers' +import { groupLedgerByDay, finalBudgetFor, finalBudgetSources, formerParticipantRows, NOTE_MAX, paidByUser, readUserNote } from './CostsPanel.helpers' import { COST_CATEGORY_LIST, catMeta } from './costsCategories' import { baseTotal as baseTotalOf, booked as bookedAmount, isUnfinished as isUnfinishedModel, lineOf as lineOfModel, memberShareOf, @@ -52,12 +52,6 @@ interface CostsPanelProps { tripMembers?: TripMember[] } -// One row in the unified Costs ledger — either an expense or a settle-up payment, -// carrying the date used to group it by day. -type LedgerEntry = - | { kind: 'expense'; date: string; e: BudgetItem } - | { kind: 'payment'; date: string; s: Settlement } - const round2 = (n: number) => Math.round(n * 100) / 100 const FIELD_H = 40 // shared height for the amount / currency / day row in the modal const COSTS_VIEW_KEY = 'trek:costs-view' @@ -66,6 +60,7 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps const { trip, budgetItems, deleteBudgetItem, loadBudgetItems, addBudgetItem, updateBudgetItem } = useTripStore() const can = useCanDo() const canEdit = can('budget_edit', trip) + const hasExpenses = budgetItems.length > 0 const receiptScan = useReceiptScan(tripId, canEdit) const toast = useToast() const { t, locale } = useTranslation() @@ -143,27 +138,9 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps // Nobody paid, so nobody owes (#2225). const myShareOf = (e: BudgetItem) => settledShareOf(e, ctx) - // ── day grouping ───────────────────────────────────────────────────────── - const dayGroups = useMemo(() => { - const entries: LedgerEntry[] = [ - ...filtered.map(e => ({ kind: 'expense' as const, date: e.expense_date || '', e })), - ...filteredSettlements.map(s => ({ kind: 'payment' as const, date: settlementDate(s), s })), - ] - const labelOf = (date: string) => { - if (!date) return t('costs.noDate') - try { return new Date(date + 'T00:00:00Z').toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' }) } catch { return date } - } - // Newest day first; within a day, expenses before payments (insertion order). - const sorted = entries.slice().sort((a, b) => (b.date || '').localeCompare(a.date || '')) - const groups: { day: string; entries: LedgerEntry[] }[] = [] - for (const en of sorted) { - const day = labelOf(en.date) - let g = groups.find(x => x.day === day) - if (!g) { g = { day, entries: [] }; groups.push(g) } - g.entries.push(en) - } - return groups - }, [filtered, filteredSettlements, locale, t]) + const noDate = t('costs.noDate') + const dayGroups = useMemo(() => groupLedgerByDay(filtered, filteredSettlements, locale, noDate), [filtered, filteredSettlements, locale, noDate]) + const emptyLedger = !hasExpenses && dayGroups.length === 0 // ── filter dropdown options (category + single day) ────────────────────── const categoryOptions = useMemo(() => [ @@ -285,8 +262,8 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps }} /> {/* ── Summary cards; with nothing to split (#2689) the total stands alone ── */} - {!splitting ?
{totalCard}
: ( -
+ {!splitting ? (hasExpenses &&
{totalCard}
) : ( +
} tone="owe" failed={settlementError} foot={totals.owe > 0.01 @@ -302,7 +279,7 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps foot={totals.outstandingCount > 0 ? {totals.outstandingCount} {t('costs.outstandingItems', { count: totals.outstandingCount })} : settledUp && {t('costs.allSettled')}} /> - {totalCard} + {hasExpenses && totalCard}
)} {/* ── Main grid ── */} @@ -310,10 +287,10 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps sidebar the last, so it lines up with the total-spend card. */}
{/* expenses */} -
+
{dayBanner} - {view === 'table' ? ( + {emptyLedger ? : view === 'table' && hasExpenses ? ( filtered.length === 0 && budgetItems.length > 0 ? (
{t('costs.noMatch')}
) : ( @@ -379,14 +356,14 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps } {/* by category; the table view sums up four ways instead */} - {view === 'table' ? ( + {hasExpenses && (view === 'table' ? ( fmt(v)} personName={personName} splitting={splitting} /> ) : (
{sideHead(t('costs.byCategory'))}
{categoryBars}
- )} + ))}
@@ -493,7 +470,7 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps return (
{/* Total card */} -
+ {hasExpenses ?
{t('costs.totalSpend')}
{bigMoney(totals.totalSpend, 24, 'rgba(255,255,255,0.6)')}
{splitting &&
@@ -512,7 +489,10 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps {t('costs.scan.button')} )} -
+
:
+ {receiptScan.offered && {t('costs.scan.button')}} + {canEdit && { setEditing(null); setModalOpen(true) }}>{t('costs.addExpense')}} +
} {/* Owe / Owed, outstanding and settling up: only with something to split (#2689) */} {splitting && <> @@ -582,7 +562,7 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps setDayFilter(String(v))} options={dayOptions} size="sm" searchable style={{ flex: 1, minWidth: 0 }} />
{dayBanner} - {dayGroups.length === 0 + {emptyLedger ? : dayGroups.length === 0 ?
{search ? t('costs.noMatch') : t('costs.emptyText')}
: dayGroups.map(g => { const dtot = g.entries.reduce((a, en) => en.kind === 'expense' ? a + baseTotal(en.e) : a, 0) @@ -611,10 +591,10 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps } {/* By category */} -
+ {hasExpenses &&
{t('costs.byCategory')}
{categoryBars} -
+
}
) diff --git a/client/src/components/Collections/ListsRail.test.tsx b/client/src/components/Collections/ListsRail.test.tsx index 891378789..9ddd9c062 100644 --- a/client/src/components/Collections/ListsRail.test.tsx +++ b/client/src/components/Collections/ListsRail.test.tsx @@ -153,4 +153,9 @@ describe('ListsRail', () => { renderRail({ onSelectLibrary: vi.fn(), libraryCount: null }); expect(screen.getByRole('button', { name: /All places/ })).toHaveTextContent(/^All places$/); }); + + it('hides All places when the library is known to be empty', () => { + renderRail({ onSelectLibrary: vi.fn(), libraryCount: 0 }); + expect(screen.queryByRole('button', { name: /All places/ })).not.toBeInTheDocument(); + }); }); diff --git a/client/src/components/Collections/ListsRail.tsx b/client/src/components/Collections/ListsRail.tsx index 5e951b5eb..8a3cf2b12 100644 --- a/client/src/components/Collections/ListsRail.tsx +++ b/client/src/components/Collections/ListsRail.tsx @@ -75,7 +75,7 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
- {onSelectLibrary && ( + {onSelectLibrary && libraryCount !== 0 && (