mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
feat(planner): bring the plan tab and every trip dialog into the new look
The Plan tab was the last trip tab still in the old design. It now reads like Bookings, Costs, Lists, Files and Collab, without losing a function: - Day plan: each day is a card with a head band (day tile with weather, stay and rental pills, a "+" menu for place, stay, transport, transit and note), rows with "..." menus, white badges and a white route bar. - Places column: add, search and filters in three rows, a show dropdown, category and rating filters, and a selection bar at the foot. - Place inspector, day details and the stay editor on the shared dialog frame; the place form in the editor look with the name in the head band. - Clicking a booking or transport anywhere on the plan opens the booking detail popup first; Edit leads to the editor. The popup is one host shared with the Bookings and Transports tabs. - Files and Collab dialogs, notes, polls, links and chat moved to the same frame; shared DialogShell and dialogParts hold the building blocks. - The map hover card shows the place photo and follows the theme. Every new and reworded string is translated into all locales, and a few older English leftovers (help center, cost split, import hints) with them. Phone screens keep their own look.
This commit is contained in:
@@ -23,7 +23,7 @@ const tripMembers = [
|
||||
]
|
||||
|
||||
/** Bob's buttons in the expense form — his final-budget row in the sidebar answers to his name too. */
|
||||
const bobInForm = () => screen.getAllByRole('button', { name: /bob/i }).filter(b => !b.hasAttribute('aria-expanded'))
|
||||
const bobInForm = () => screen.getAllByRole('checkbox', { name: /bob/i })
|
||||
|
||||
beforeEach(() => {
|
||||
resetAllStores()
|
||||
@@ -52,7 +52,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
await screen.findByText('Dinner')
|
||||
await screen.findByText('Payment')
|
||||
// The payment row exposes an inline undo (no need to open a separate History modal).
|
||||
expect(screen.getByTitle('Undo')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Undo' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('records a manual payment via the Add payment button', async () => {
|
||||
@@ -70,7 +70,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '25')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '25')
|
||||
// The footer submit is the second "Add payment" control once the modal is open.
|
||||
const addButtons = screen.getAllByRole('button', { name: 'Add payment' })
|
||||
const submit = addButtons[addButtons.length - 1]
|
||||
@@ -242,7 +242,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await screen.findByText('Lunch')
|
||||
await user.click(screen.getAllByTitle('Edit')[0])
|
||||
await user.click(screen.getAllByRole('button', { name: 'Edit' })[0])
|
||||
await user.click(await screen.findByRole('button', { name: 'Save' }))
|
||||
|
||||
await waitFor(() => expect(patched).toBeTruthy())
|
||||
@@ -296,7 +296,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
expect(foot).toHaveTextContent('2 expenses need a payer') // the two payer-less, non-zero expenses
|
||||
// Sum is 90 + 30 = 120 — the paid (60) and zero-total items are excluded.
|
||||
// Sum is 90 + 30 = 120 — the paid (60) and zero-total items are excluded.
|
||||
const card = screen.getByText('Outstanding amount').closest('div[style*="border-radius: 22"]')
|
||||
const card = screen.getByRole('region', { name: 'Outstanding amount' })
|
||||
expect(card).toHaveTextContent('120') // 120,00 € (locale separator), i.e. 90 + 30
|
||||
})
|
||||
|
||||
@@ -317,7 +317,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
// "Your share" is the first of the two bold figures in the Total spend card's
|
||||
// footer; the second is "You paid". 60 from the paid expense only — the 40
|
||||
// nobody has paid for is not a share, though it still counts as spend.
|
||||
const card = screen.getByText('Total trip spend').closest('div[style*="border-radius: 22"]')!
|
||||
const card = screen.getByRole('region', { name: 'Total trip spend' })!
|
||||
const figures = [...card.querySelectorAll('b')].map(b => b.textContent ?? '')
|
||||
expect(figures[0]).toContain('60')
|
||||
expect(figures[0]).not.toContain('100')
|
||||
@@ -344,10 +344,9 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
|
||||
// Deselect everyone so the cost carries no split, and mark it as unpaid: a picked
|
||||
// payer now always goes out (#1766), so "nobody paid" must be said explicitly.
|
||||
await user.click(screen.getByRole('button', { name: 'Y You' }))
|
||||
await user.click(screen.getByRole('button', { name: 'B bob' }))
|
||||
await user.click(screen.getByRole('button', { name: 'You' })) // open the Who-paid select
|
||||
pickOption('No one paid yet')
|
||||
await user.click(screen.getByRole('checkbox', { name: 'You' }))
|
||||
await user.click(screen.getByRole('checkbox', { name: 'bob' }))
|
||||
await user.click(screen.getByRole('radio', { name: 'No one paid yet' }))
|
||||
|
||||
const addBtns = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
const submit = addBtns[addBtns.length - 1] // footer submit
|
||||
@@ -381,8 +380,8 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
|
||||
// A personal expense: alice (the default "You" payer) fronted it, but nobody shares
|
||||
// the split. The web used to drop the payer once no participants remained.
|
||||
await user.click(screen.getByRole('button', { name: 'Y You' }))
|
||||
await user.click(screen.getByRole('button', { name: 'B bob' }))
|
||||
await user.click(screen.getByRole('checkbox', { name: 'You' }))
|
||||
await user.click(screen.getByRole('checkbox', { name: 'bob' }))
|
||||
|
||||
const addBtns = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
const submit = addBtns[addBtns.length - 1] // footer submit
|
||||
@@ -417,10 +416,10 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await screen.findByText('Hotel')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
// Nobody paid this expense — reopening it must not silently reselect "You".
|
||||
expect(await screen.findByRole('button', { name: 'No one paid yet' })).toBeInTheDocument()
|
||||
expect(await screen.findByRole('radio', { name: 'No one paid yet' })).toBeChecked()
|
||||
|
||||
// …and saving an untouched edit must not assign the current user as payer.
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
@@ -439,7 +438,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add expense' }))
|
||||
expect(await screen.findByRole('button', { name: 'You' })).toBeInTheDocument()
|
||||
expect(await screen.findByRole('radio', { name: 'You' })).toBeChecked()
|
||||
})
|
||||
|
||||
// ── Multi-payer (#1426 regression) ─────────────────────────────────────────
|
||||
@@ -543,7 +542,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
// Loading used to be payers.find(...), which silently dropped the second payer.
|
||||
// Seeded with two decimals since #2175, localized for EUR.
|
||||
@@ -572,7 +571,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await screen.findByText('Dinner; tapas')
|
||||
await user.click(screen.getByTitle('Export CSV'))
|
||||
await user.click(screen.getByRole('button', { name: 'Export CSV' }))
|
||||
|
||||
expect(exported).toBeTruthy()
|
||||
const text = await exported!.text()
|
||||
@@ -624,8 +623,8 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
expect(screen.getByDisplayValue('100,00')).toBeDisabled()
|
||||
|
||||
expect(screen.getByText('Individual shares')).toBeInTheDocument()
|
||||
expect(screen.getByText(/75\.00/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/25\.00/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/75,00/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/25,00/)).toBeInTheDocument()
|
||||
|
||||
const addBtns = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
await user.click(addBtns[addBtns.length - 1])
|
||||
@@ -655,7 +654,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await screen.findByText('Sushi')
|
||||
const card = screen.getByText('Total trip spend').closest('div[style*="border-radius: 22"]')
|
||||
const card = screen.getByRole('region', { name: 'Total trip spend' })
|
||||
// Yen, unconverted and with JPY's zero decimals — not a euro/dollar default.
|
||||
expect(card).toHaveTextContent('¥3,000')
|
||||
})
|
||||
@@ -680,7 +679,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '25')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '25')
|
||||
const addButtons = screen.getAllByRole('button', { name: 'Add payment' })
|
||||
await user.click(addButtons[addButtons.length - 1])
|
||||
|
||||
@@ -703,7 +702,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '25')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '25')
|
||||
// Bob paid me back in dollars — the server freezes the USD rate on write.
|
||||
await user.click(screen.getByText(/^EUR/))
|
||||
await user.click(await screen.findByText(/^USD/))
|
||||
@@ -732,7 +731,7 @@ describe('CostsPanel — settlements in the ledger', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={tripMembers} />)
|
||||
|
||||
await screen.findByText('Payment')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
// The stored USD amount comes back as-is (padded to two decimals, #2175),
|
||||
// not silently reread as euros.
|
||||
@@ -831,7 +830,7 @@ describe('CostsPanel — overview', () => {
|
||||
mount([], { balances: [{ user_id: 1, username: 'alice', avatar_url: null, balance: 0 }] })
|
||||
|
||||
// Both travellers appear; neither has a signed amount.
|
||||
const balances = (await screen.findByText('Balances')).parentElement as HTMLElement
|
||||
const balances = (await screen.findByRole('region', { name: 'Balances' })) as HTMLElement
|
||||
expect(within(balances).getAllByText('0,00 €')).toHaveLength(2)
|
||||
})
|
||||
|
||||
@@ -868,7 +867,7 @@ describe('CostsPanel — overview', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const card = (await screen.findByText('Final budget')).parentElement as HTMLElement
|
||||
const card = (await screen.findByRole('region', { name: 'Final budget' })) as HTMLElement
|
||||
await waitFor(() => expect(within(card).getAllByText('61,00 €')).toHaveLength(2))
|
||||
// The main view stays one figure per person until someone asks for more.
|
||||
expect(within(card).queryByText('Expenses paid')).toBeNull()
|
||||
@@ -880,7 +879,7 @@ describe('CostsPanel — overview', () => {
|
||||
// 100 USD is never converted again here. What was entered labels the row (#2525).
|
||||
expect(within(card).getAllByText('+92,00 €')).toHaveLength(2)
|
||||
expect(within(card).queryByText(/100,00/)).toBeNull()
|
||||
expect(within(card).getByText('· $100.00')).toBeInTheDocument()
|
||||
expect(within(card).getByText('$100.00')).toBeInTheDocument()
|
||||
// Received and still pending both lower her cost, each line with its one row.
|
||||
expect(within(card).getAllByText('−15,00 €')).toHaveLength(2)
|
||||
expect(within(card).getAllByText('−16,00 €')).toHaveLength(2)
|
||||
@@ -902,7 +901,7 @@ describe('CostsPanel — overview', () => {
|
||||
mount([dinner(), taxi()])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
const breakdown = screen.getByText('By category').parentElement as HTMLElement
|
||||
const breakdown = screen.getByRole('region', { name: 'By category' }) as HTMLElement
|
||||
const labels = within(breakdown).getAllByText(/Food & drink|Transport/).map(el => el.textContent)
|
||||
// Bars are ordered by spend, so the 90 € food row comes before the 30 € taxi.
|
||||
expect(labels).toEqual(['Food & drink', 'Transport'])
|
||||
@@ -924,7 +923,7 @@ describe('CostsPanel — overview', () => {
|
||||
mount([expense({ id: 110, name: 'Mystery', category: 'other', total_price: 90 })])
|
||||
|
||||
await screen.findByText('Mystery')
|
||||
const card = screen.getByText('Total trip spend').closest('div[style*="border-radius: 22"]')
|
||||
const card = screen.getByRole('region', { name: 'Total trip spend' })
|
||||
expect(card).toHaveTextContent('90.00 XX')
|
||||
})
|
||||
})
|
||||
@@ -1001,10 +1000,10 @@ describe('CostsPanel — settle up', () => {
|
||||
}))
|
||||
mount([], { settlements: [{ id: 7, from_user_id: 2, to_user_id: 1, amount: 30, created_at: '2025-06-16 10:00:00' }] })
|
||||
|
||||
fireEvent.click(await screen.findByTitle('Undo'))
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Undo' }))
|
||||
await waitFor(() => expect(deleted).toBe(1))
|
||||
|
||||
fireEvent.click(screen.getByTitle('Undo'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Undo' }))
|
||||
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Unknown error', 'error', undefined))
|
||||
delete window.__addToast
|
||||
})
|
||||
@@ -1057,7 +1056,7 @@ describe('CostsPanel — settle up', () => {
|
||||
mount([], { flows: [{ from: { user_id: 1, username: 'alice' }, to: { user_id: 2, username: 'bob' }, amount: 20 }] })
|
||||
|
||||
await screen.findByText('You owe')
|
||||
const card = screen.getByText('You owe').closest('div[style*="border-radius: 22"]') as HTMLElement
|
||||
const card = screen.getByRole('region', { name: 'You owe' }) as HTMLElement
|
||||
expect(within(card).getByText('To')).toBeInTheDocument()
|
||||
expect(within(card).getByText('bob')).toBeInTheDocument()
|
||||
expect(screen.getByText('Nothing owed to you')).toBeInTheDocument()
|
||||
@@ -1073,6 +1072,7 @@ describe('CostsPanel — filtering the ledger', () => {
|
||||
mount([dinner(), taxi()], { settlements: [payment] })
|
||||
|
||||
await screen.findByText('Taxi')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Filter' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Paid by me' }))
|
||||
|
||||
expect(screen.getByText('Dinner')).toBeInTheDocument()
|
||||
@@ -1085,6 +1085,7 @@ describe('CostsPanel — filtering the ledger', () => {
|
||||
mount([dinner(), taxi()], { settlements: [payment] })
|
||||
|
||||
await screen.findByText('Taxi')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Filter' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: "I'm owed" }))
|
||||
|
||||
expect(screen.getByText('Dinner')).toBeInTheDocument()
|
||||
@@ -1096,8 +1097,8 @@ describe('CostsPanel — filtering the ledger', () => {
|
||||
mount([dinner(), taxi()], { settlements: [payment] })
|
||||
|
||||
await screen.findByText('Taxi')
|
||||
fireEvent.click(screen.getByRole('button', { name: /All categories/ }))
|
||||
pickOption('Transport')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Filter' }))
|
||||
fireEvent.click(within(screen.getByRole('menu')).getByRole('button', { name: 'Transport' }))
|
||||
|
||||
expect(screen.getByText('Taxi')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Dinner')).not.toBeInTheDocument()
|
||||
@@ -1108,8 +1109,8 @@ describe('CostsPanel — filtering the ledger', () => {
|
||||
mount([dinner(), taxi()], { settlements: [payment] })
|
||||
|
||||
await screen.findByText('Taxi')
|
||||
fireEvent.click(screen.getByRole('button', { name: /All days/ }))
|
||||
pickOption('Sun, Jun 15')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Filter' }))
|
||||
fireEvent.click(within(screen.getByRole('menu')).getByRole('button', { name: 'Sun, Jun 15' }))
|
||||
|
||||
expect(screen.getByText('Sunday, June 15')).toBeInTheDocument()
|
||||
expect(screen.getByText('1 expenses')).toBeInTheDocument()
|
||||
@@ -1126,8 +1127,8 @@ describe('CostsPanel — filtering the ledger', () => {
|
||||
mount([dinner(), taxi()], { settlements: [{ ...payment, settled_at: '2025-06-15' }] })
|
||||
|
||||
await screen.findByText('Taxi')
|
||||
fireEvent.click(screen.getByRole('button', { name: /All days/ }))
|
||||
pickOption('Sun, Jun 15')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Filter' }))
|
||||
fireEvent.click(within(screen.getByRole('menu')).getByRole('button', { name: 'Sun, Jun 15' }))
|
||||
|
||||
expect(screen.getByText('Dinner')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Taxi')).not.toBeInTheDocument()
|
||||
@@ -1214,7 +1215,7 @@ describe('CostsPanel — expense rows', () => {
|
||||
mount([dinner()])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
fireEvent.click(screen.getByTitle('Delete'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete' }))
|
||||
|
||||
await waitFor(() => expect(addToast).toHaveBeenCalledWith('Unknown error', 'error', undefined))
|
||||
// The optimistic removal is rolled back by the store.
|
||||
@@ -1237,8 +1238,8 @@ describe('CostsPanel — expense rows', () => {
|
||||
expect(screen.queryByRole('button', { name: 'Settle up' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Add payment' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Settle' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByTitle('Delete')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTitle('Undo')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Delete' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Undo' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1274,7 +1275,7 @@ describe('CostsPanel — mobile layout', () => {
|
||||
expect(screen.getByText("You're owed")).toBeInTheDocument()
|
||||
expect(screen.getByText('Outstanding amount')).toBeInTheDocument()
|
||||
// The unfinished expense is flagged with a badge on its icon instead of a pill.
|
||||
expect(screen.getByTitle('Total only — not settled yet')).toHaveTextContent('!')
|
||||
expect(screen.getByRole('img', { name: 'Total only — not settled yet' })).toHaveTextContent('!')
|
||||
expect(screen.queryByText('Unfinished')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -1315,8 +1316,8 @@ describe('CostsPanel — payment modal', () => {
|
||||
}))
|
||||
mount([], { settlements: [{ id: 7, from_user_id: 2, to_user_id: 1, amount: 30, created_at: '2025-06-16 10:00:00' }] })
|
||||
|
||||
await user.click(await screen.findByTitle('Edit'))
|
||||
const amount = await screen.findByPlaceholderText('0.00')
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit' }))
|
||||
const amount = await screen.findByPlaceholderText('0,00')
|
||||
await user.clear(amount)
|
||||
await user.type(amount, '12,50')
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
@@ -1330,7 +1331,7 @@ describe('CostsPanel — payment modal', () => {
|
||||
mount([])
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '10')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '10')
|
||||
|
||||
// Default is You → bob; pointing "to" back at me makes it a no-op transfer.
|
||||
await user.click(screen.getByRole('button', { name: 'bob' }))
|
||||
@@ -1348,7 +1349,7 @@ describe('CostsPanel — payment modal', () => {
|
||||
mount([])
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '10')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '10')
|
||||
const submits = screen.getAllByRole('button', { name: 'Add payment' })
|
||||
await user.click(submits[submits.length - 1])
|
||||
|
||||
@@ -1370,7 +1371,7 @@ describe('CostsPanel — payment modal', () => {
|
||||
|
||||
try {
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '10')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '10')
|
||||
const submits = screen.getAllByRole('button', { name: 'Add payment' })
|
||||
await user.click(submits[submits.length - 1])
|
||||
|
||||
@@ -1390,7 +1391,7 @@ describe('CostsPanel — payment modal', () => {
|
||||
}))
|
||||
mount([], { settlements: [{ id: 7, from_user_id: 2, to_user_id: 1, amount: 30, settled_at: '2025-06-10', created_at: '2025-06-16 10:00:00' }] })
|
||||
|
||||
await user.click(await screen.findByTitle('Edit'))
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
|
||||
await waitFor(() => expect(put).toBeTruthy())
|
||||
@@ -1403,7 +1404,7 @@ describe('CostsPanel — payment modal', () => {
|
||||
const user = userEvent.setup()
|
||||
mount([], { settlements: [{ id: 7, from_user_id: 2, to_user_id: 1, amount: 30, settled_at: '2025-06-10', created_at: '2025-06-16 10:00:00' }] })
|
||||
|
||||
await user.click(await screen.findByTitle('Edit'))
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit' }))
|
||||
const save = screen.getByRole('button', { name: 'Save' })
|
||||
expect(save).toBeEnabled()
|
||||
|
||||
@@ -1439,7 +1440,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
mount([expense({ id: 150, name: 'Market run', category: 'groceries', total_price: 30, note, payers: [{ user_id: 1, amount: 30 }], members: [{ user_id: 1, username: 'alice', amount: 15 }, { user_id: 2, username: 'bob', amount: 15 }] })])
|
||||
|
||||
await screen.findByText('Market run')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
expect(await screen.findByDisplayValue('Apples')).toBeInTheDocument()
|
||||
expect(screen.getByDisplayValue('Cake')).toBeInTheDocument()
|
||||
@@ -1461,7 +1462,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
mount([expense({ id: 151, name: 'Market run', category: 'groceries', total_price: 30, note: 'TICKETJSON:{oops', payers: [{ user_id: 1, amount: 30 }], members: [{ user_id: 1, username: 'alice' }] })])
|
||||
|
||||
await screen.findByText('Market run')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
expect(await screen.findByRole('button', { name: /Add item/i })).toBeInTheDocument()
|
||||
expect(screen.queryByPlaceholderText('Item name')).not.toBeInTheDocument()
|
||||
@@ -1482,7 +1483,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
})])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
// Custom shares reopen padded to two decimals (#2175), localized for EUR.
|
||||
expect((await screen.findByDisplayValue('70,00')).tagName).toBe('INPUT')
|
||||
@@ -1496,7 +1497,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
|
||||
// Bringing him back in via the excluded-state hint restores an empty field,
|
||||
// pre-filled as a placeholder with what is still missing from the total.
|
||||
await user.click(screen.getByRole('button', { name: 'Tap to include' }))
|
||||
await user.click(bobInForm()[0])
|
||||
await user.type(screen.getByPlaceholderText('30,00'), '30')
|
||||
|
||||
expect(screen.getByText('Split matches total')).toBeInTheDocument()
|
||||
@@ -1526,6 +1527,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
expect(screen.getByText('50,00 €')).toBeInTheDocument()
|
||||
|
||||
// A different category than the default is carried into the payload.
|
||||
await user.click(screen.getByRole('button', { name: /^Category:/ }))
|
||||
await user.click(screen.getByRole('button', { name: 'Sightseeing' }))
|
||||
const submits = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
await user.click(submits[submits.length - 1])
|
||||
@@ -1550,7 +1552,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
await user.click(screen.getAllByTestId('payer-toggle')[1])
|
||||
// Dropping Bob again leaves Alice absorbing the whole amount.
|
||||
await user.click(screen.getAllByTestId('payer-toggle')[1])
|
||||
expect(screen.getByRole('button', { name: 'Tap to include' })).toBeInTheDocument()
|
||||
expect(screen.getAllByTestId('payer-toggle')[1]).toHaveAttribute('aria-checked', 'false')
|
||||
await user.click(screen.getByRole('button', { name: 'One person paid' }))
|
||||
|
||||
const submits = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
@@ -1572,8 +1574,7 @@ describe('CostsPanel — expense modal', () => {
|
||||
|
||||
await user.type(screen.getByPlaceholderText('e.g. Dinner, souvenirs, gas…'), 'Hotel')
|
||||
await user.type(screen.getAllByPlaceholderText('0,00')[0], '120')
|
||||
await user.click(screen.getByRole('button', { name: 'You' }))
|
||||
pickOption('No one paid yet')
|
||||
await user.click(screen.getByRole('radio', { name: 'No one paid yet' }))
|
||||
|
||||
const submits = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
await user.click(submits[submits.length - 1])
|
||||
@@ -1723,7 +1724,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
])
|
||||
|
||||
await screen.findByText('Tip')
|
||||
fireEvent.click(screen.getByTitle('Export CSV'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }))
|
||||
|
||||
const lines = (await exported!.text()).replace(/^\uFEFF/, '').split('\r\n')
|
||||
expect(lines[0]).toBe('Date;Name;Category;Amount;Currency;Amount (EUR);Note')
|
||||
@@ -1749,7 +1750,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
])
|
||||
|
||||
await screen.findByText('-5 refund')
|
||||
fireEvent.click(screen.getByTitle('Export CSV'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }))
|
||||
|
||||
const lines = (await exported!.text()).replace(/^\uFEFF/, '').split('\r\n')
|
||||
expect(lines[1]).toBe('06/15/2025;"\'=HYPERLINK(""http://evil"",""click"")";Food & drink;12.00;EUR;12.00;\'@SUM(A1:A9)')
|
||||
@@ -1763,7 +1764,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
mount([dinner()])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
fireEvent.click(screen.getByTitle('Delete'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Delete' }))
|
||||
|
||||
await waitFor(() => expect(deleted).toBe(true))
|
||||
expect(screen.queryByText('Dinner')).not.toBeInTheDocument()
|
||||
@@ -1790,7 +1791,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
})])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
const card = screen.getByText('Total trip spend').closest('div[style*="border-radius: 22"]') as HTMLElement
|
||||
const card = screen.getByRole('region', { name: 'Total trip spend' }) as HTMLElement
|
||||
// Not the 50/50 an equal split would have produced.
|
||||
expect(within(card).getByText('80 €')).toBeInTheDocument()
|
||||
expect(within(card).getByText('0 €')).toBeInTheDocument()
|
||||
@@ -1804,7 +1805,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
})])
|
||||
|
||||
await screen.findByText('Bob solo')
|
||||
const card = screen.getByText('Total trip spend').closest('div[style*="border-radius: 22"]') as HTMLElement
|
||||
const card = screen.getByRole('region', { name: 'Total trip spend' }) as HTMLElement
|
||||
expect(within(card).getAllByText('0 €')).toHaveLength(2)
|
||||
})
|
||||
|
||||
@@ -1814,7 +1815,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
mount([expense({ id: 220, name: 'Dinner', category: 'food', total_price: 90, currency: null })])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
const card = screen.getByText('Total trip spend').closest('div[style*="border-radius: 22"]')
|
||||
const card = screen.getByRole('region', { name: 'Total trip spend' })
|
||||
expect(card).toHaveTextContent('90,00 €')
|
||||
})
|
||||
|
||||
@@ -1834,7 +1835,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
)
|
||||
render(<CostsPanel tripId={1} tripMembers={[...tripMembers, { id: 3, username: 'cara', avatar_url: null }]} />)
|
||||
|
||||
await user.click(await screen.findByTitle('Edit'))
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit' }))
|
||||
// No symbol is known, so the code itself prefixes the amount and labels the option.
|
||||
await screen.findByPlaceholderText('0.00')
|
||||
expect(screen.getAllByText('XBT').length).toBeGreaterThanOrEqual(2)
|
||||
@@ -1852,7 +1853,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
mount([expense({ id: 240, name: 'Mining rig', category: 'other', total_price: 2, currency: 'XBT', payers: [{ user_id: 1, amount: 2 }], members: [{ user_id: 1, username: 'alice' }] })])
|
||||
|
||||
await screen.findByText('Mining rig')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
// XBT is unknown to the locale map → dot separator, two decimals (#2175).
|
||||
expect(await screen.findByDisplayValue('2.00')).toBeInTheDocument()
|
||||
@@ -1868,7 +1869,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
render(<CostsPanel tripId={1} tripMembers={[{ id: 1, username: 'alice', avatar_url: null }]} />)
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '10')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '10')
|
||||
|
||||
// From and To both resolve to me, so the transfer stays unsavable.
|
||||
const submits = screen.getAllByRole('button', { name: 'Add payment' })
|
||||
@@ -1897,7 +1898,7 @@ describe('CostsPanel — remaining paths', () => {
|
||||
// Excluding Bob leaves the include hint; tapping it puts him back on the bill.
|
||||
await user.click(screen.getAllByTestId('payer-toggle')[1])
|
||||
await user.click(screen.getAllByTestId('payer-toggle')[1])
|
||||
await user.click(screen.getByRole('button', { name: 'Tap to include' }))
|
||||
await user.click(screen.getAllByTestId('payer-toggle')[1])
|
||||
expect(screen.getAllByTestId('payer-amount')).toHaveLength(2)
|
||||
|
||||
// Three decimals are not a valid money amount, so the field ignores them.
|
||||
@@ -1922,13 +1923,13 @@ describe('CostsPanel — remaining paths', () => {
|
||||
expect(price.value).toBe('10,99')
|
||||
|
||||
// Toggling a participant off and on again leaves the shares unchanged.
|
||||
const bob = screen.getAllByRole('button', { name: /bob/i })[0]
|
||||
const bob = screen.getAllByRole('checkbox', { name: /bob/i })[0]
|
||||
await user.click(bob)
|
||||
await user.click(bob)
|
||||
// 10.99 across two people leaves the odd cent with the lower user id.
|
||||
expect(screen.getByText('Individual shares')).toBeInTheDocument()
|
||||
expect(screen.getByText('€5.50')).toBeInTheDocument()
|
||||
expect(screen.getByText('€5.49')).toBeInTheDocument()
|
||||
expect(screen.getByText('5,50 €')).toBeInTheDocument()
|
||||
expect(screen.getByText('5,49 €')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1951,7 +1952,7 @@ describe('CostsPanel — split modes and guests', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Custom' }))
|
||||
expect(screen.getByText(/Sum of splits/)).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Equally' }))
|
||||
expect(screen.getByText('Split 2 ways · €45.00 each')).toBeInTheDocument()
|
||||
expect(screen.getByText('45,00 € per person')).toBeInTheDocument()
|
||||
|
||||
const submits = screen.getAllByRole('button', { name: 'Add expense' })
|
||||
await user.click(submits[submits.length - 1])
|
||||
@@ -1972,7 +1973,7 @@ describe('CostsPanel — split modes and guests', () => {
|
||||
})])
|
||||
|
||||
await screen.findByText('Hotel')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
|
||||
// Nobody paid, so switching to multi-payer seeds me as the only payer.
|
||||
await user.click(await screen.findByRole('button', { name: 'Multiple people paid' }))
|
||||
@@ -2049,7 +2050,7 @@ describe('CostsPanel — mobile extras', () => {
|
||||
await waitFor(() => expect(document.querySelector('.costs-summary')).toBeNull())
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add payment' }))
|
||||
|
||||
expect(await screen.findByPlaceholderText('0.00')).toBeInTheDocument()
|
||||
expect(await screen.findByPlaceholderText('0,00')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-W5COSTS-062: the mobile search box keeps the caret across keystrokes', async () => {
|
||||
@@ -2093,11 +2094,11 @@ describe('CostsPanel — decimal padding on edit (#2175)', () => {
|
||||
])
|
||||
|
||||
await screen.findByText('Coffee')
|
||||
await user.click(screen.getAllByTitle('Edit')[0])
|
||||
await user.click(screen.getAllByRole('button', { name: 'Edit' })[0])
|
||||
expect(await screen.findByDisplayValue('4,90')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
|
||||
await user.click(screen.getAllByTitle('Edit')[1])
|
||||
await user.click(screen.getAllByRole('button', { name: 'Edit' })[1])
|
||||
expect(await screen.findByDisplayValue('5,00')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -2177,10 +2178,10 @@ describe('CostsPanel — negative amounts (#2176)', () => {
|
||||
// Not "Unfinished": the refund has its recipient recorded.
|
||||
expect(within(row).queryByText('Unfinished')).toBeNull()
|
||||
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
// The negative payer reopens selected instead of resetting to "Nobody",
|
||||
// and the total is seeded signed and padded.
|
||||
expect(await screen.findByRole('button', { name: 'You' })).toBeInTheDocument()
|
||||
expect(await screen.findByRole('radio', { name: 'You' })).toBeChecked()
|
||||
expect(screen.getByDisplayValue('-100,00')).toBeInTheDocument()
|
||||
|
||||
// Saving untouched must not silently drop the negative payer.
|
||||
@@ -2205,7 +2206,7 @@ describe('CostsPanel — negative amounts (#2176)', () => {
|
||||
])
|
||||
|
||||
await screen.findByText('Dinner')
|
||||
const breakdown = screen.getByText('By category').parentElement as HTMLElement
|
||||
const breakdown = screen.getByRole('region', { name: 'By category' }) as HTMLElement
|
||||
// Food nets 90 − 30 = 60; the fully refunded tour keeps a row of its own.
|
||||
expect(within(breakdown).getByText('60 €')).toBeInTheDocument()
|
||||
expect(within(breakdown).getByText(/[-−]20\s*€/)).toBeInTheDocument()
|
||||
@@ -2221,10 +2222,10 @@ describe('CostsPanel — negative amounts (#2176)', () => {
|
||||
})} />)
|
||||
|
||||
// -70 of -100: 30 still to hand out, not 30 too much.
|
||||
expect(await screen.findByText('Sum of splits: €-70.00 of €-100.00 (under by €30.00)')).toBeInTheDocument()
|
||||
expect(await screen.findByText('Sum of splits: -70,00 € of -100,00 € (under by 30,00 €)')).toBeInTheDocument()
|
||||
|
||||
await user.type(screen.getByPlaceholderText('-30,00'), '-40')
|
||||
expect(screen.getByText('Sum of splits: €-110.00 of €-100.00 (over by €10.00)')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sum of splits: -110,00 € of -100,00 € (over by 10,00 €)')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-W5COSTS-073: the total can be turned into a refund without a minus key', async () => {
|
||||
@@ -2306,19 +2307,20 @@ describe('CostsPanel — expense modal in another language', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Individuell' }))
|
||||
|
||||
// Nothing entered yet, so the whole 90 is still unaccounted for.
|
||||
expect(screen.getByText('Summe der Anteile: €0.00 von €90.00 (es fehlen €90.00)')).toBeInTheDocument()
|
||||
expect(screen.getByText('Summe der Anteile: 0,00 € von 90,00 € (es fehlen 90,00 €)')).toBeInTheDocument()
|
||||
|
||||
const shares = screen.getAllByPlaceholderText('45,00')
|
||||
await user.type(shares[0], '90')
|
||||
expect(screen.getByText('Aufteilung passt zur Summe')).toBeInTheDocument()
|
||||
|
||||
await user.type(shares[1], '10')
|
||||
expect(screen.getByText('Summe der Anteile: €100.00 von €90.00 (€10.00 zu viel)')).toBeInTheDocument()
|
||||
expect(screen.getByText('Summe der Anteile: 100,00 € von 90,00 € (10,00 € zu viel)')).toBeInTheDocument()
|
||||
|
||||
// Back to the equal split: a member taken out of it is marked, not dropped.
|
||||
await user.click(screen.getByRole('button', { name: 'Gleichmäßig' }))
|
||||
await user.click(screen.getByRole('button', { name: /bob/i }))
|
||||
expect(screen.getByText('Nicht dabei')).toBeInTheDocument()
|
||||
// Taken out, the box is simply unticked; no English word leaks into the German dialog.
|
||||
await user.click(screen.getByRole('checkbox', { name: /bob/i }))
|
||||
expect(screen.getByRole('checkbox', { name: /bob/i })).not.toBeChecked()
|
||||
expect(screen.queryByText('Excluded')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -2390,7 +2392,7 @@ describe('CostsPanel: a bill entered in the display currency (#2525)', () => {
|
||||
try {
|
||||
mount([hotel()])
|
||||
await screen.findByText('Aparthotel Silver')
|
||||
fireEvent.click(screen.getByTitle('Export CSV'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }))
|
||||
await waitFor(() => expect(exported).toBeTruthy())
|
||||
const lines = (await exported!.text()).replace(/^\uFEFF/, '').split('\r\n')
|
||||
expect(lines[0]).toBe('Date;Name;Category;Amount;Currency;Amount (EUR);Amount (USD);Note')
|
||||
@@ -2471,7 +2473,7 @@ describe('CostsPanel: a bill entered in the display currency (#2525)', () => {
|
||||
mount([hotel()])
|
||||
|
||||
await screen.findByText('Aparthotel Silver')
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
expect(await screen.findByDisplayValue('801.76')).toBeInTheDocument()
|
||||
// Same currency as the list, so the dialog said nothing, and 801.76 there beside
|
||||
// $791.57 in the list looked like two different expenses.
|
||||
@@ -2480,7 +2482,7 @@ describe('CostsPanel: a bill entered in the display currency (#2525)', () => {
|
||||
expect(within(hint).getByText(/^685,26\s€$/)).toBeInTheDocument()
|
||||
expect(within(hint).getByText('$791.55')).toBeInTheDocument()
|
||||
// Each share next to what it counts as, the figure the row's "you lent" is made of.
|
||||
expect(screen.getByText(/Split 2 ways · \$400\.88 → \$395\.77 each/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/\$400\.88 → \$395\.77 per person/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-W5COSTS-086: the final budget names the bill by what was entered beside its booked figure', async () => {
|
||||
@@ -2499,11 +2501,11 @@ describe('CostsPanel: a bill entered in the display currency (#2525)', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const card = (await screen.findByText('Final budget')).parentElement as HTMLElement
|
||||
const card = (await screen.findByRole('region', { name: 'Final budget' })) as HTMLElement
|
||||
await user.click(await within(card).findByRole('button', { name: /You/ }))
|
||||
expect(within(card).getAllByText('+$791.55')).toHaveLength(2)
|
||||
expect(within(card).getByText('Aparthotel Silver')).toBeInTheDocument()
|
||||
expect(within(card).getByText('· $801.76')).toBeInTheDocument()
|
||||
expect(within(card).getByText('$801.76')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-W5COSTS-089: the final budget lists a bill that reads as typed without a second amount', async () => {
|
||||
@@ -2522,10 +2524,10 @@ describe('CostsPanel: a bill entered in the display currency (#2525)', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const card = (await screen.findByText('Final budget')).parentElement as HTMLElement
|
||||
const card = (await screen.findByRole('region', { name: 'Final budget' })) as HTMLElement
|
||||
await user.click(await within(card).findByRole('button', { name: /You/ }))
|
||||
expect(within(card).getAllByText('+$801.76')).toHaveLength(2)
|
||||
expect(within(card).queryByText('· $801.76')).toBeNull()
|
||||
expect(within(card).queryByText('$801.76')).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-W5COSTS-083: an expense saved without a currency opens in the trip currency, not the display one', async () => {
|
||||
@@ -2541,7 +2543,7 @@ describe('CostsPanel: a bill entered in the display currency (#2525)', () => {
|
||||
// The list reads the missing currency as the trip's own.
|
||||
expect(screen.getByText(/100,00\s€ → \$115\.51/)).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByTitle('Edit'))
|
||||
await user.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
expect(await screen.findByDisplayValue('100,00')).toBeInTheDocument()
|
||||
// Seeding the display currency here would label 100 euro as 100 dollars, and a
|
||||
// plain save would then store it that way.
|
||||
@@ -2675,7 +2677,7 @@ describe('CostsPanel: a bill the server cannot convert', () => {
|
||||
mount([])
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Add payment' }))
|
||||
await user.type(await screen.findByPlaceholderText('0.00'), '25')
|
||||
await user.type(await screen.findByPlaceholderText('0,00'), '25')
|
||||
const submits = screen.getAllByRole('button', { name: 'Add payment' })
|
||||
await user.click(submits[submits.length - 1])
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,30 @@
|
||||
import { Check, Plus, ScanLine } from 'lucide-react'
|
||||
import { useCallback, useRef, useState, type ReactNode } from 'react'
|
||||
import { Check, Download, Filter, Plus, RotateCcw, ScanLine, Search, X } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import type { TripMember } from './BudgetPanelMemberChips'
|
||||
import { Tooltip } from '../shared/Tooltip'
|
||||
import { POPOVER, POPOVER_CAPTION, POPOVER_DIVIDER, useDismissOnOutside } from '../Packing/packingPopoverStyles'
|
||||
import { PopoverItem } from '../Packing/PackingPopover'
|
||||
|
||||
export type OwnerFilter = 'all' | 'mine' | 'owed'
|
||||
|
||||
export interface CostsFilterProps {
|
||||
query: string
|
||||
onQuery: (query: string) => void
|
||||
owner: OwnerFilter
|
||||
onOwner: (owner: OwnerFilter) => void
|
||||
/** The picked category, '' for all; the options start with that "all" entry. */
|
||||
category: string
|
||||
categoryOptions: { value: string; label: string; icon?: ReactNode }[]
|
||||
onCategory: (category: string) => void
|
||||
/** The picked day as YYYY-MM-DD, '' for all; the options start with that "all" entry. */
|
||||
day: string
|
||||
dayOptions: { value: string; label: string }[]
|
||||
onDay: (day: string) => void
|
||||
onResetFilters: () => void
|
||||
onExport: () => void
|
||||
canExport: boolean
|
||||
}
|
||||
|
||||
interface CostsToolbarProps {
|
||||
/** The trip's span as a formatted range and its length in days; null for a trip without dates. */
|
||||
@@ -15,24 +39,29 @@ interface CostsToolbarProps {
|
||||
onAddExpense: () => void
|
||||
/** Opens the receipt scan; left out when the AI model reads no images. */
|
||||
onScanReceipt?: () => void
|
||||
/** Search, filters and export, the way the Transports and Bookings bars carry them. */
|
||||
filters?: CostsFilterProps
|
||||
}
|
||||
|
||||
const BODY_SIZE = 'calc(13px * var(--fs-scale-body, 1))'
|
||||
/** A 36 px control on the bar, in the card colour so it reads on the bar's tint. */
|
||||
const BAR_BTN = 'relative grid h-9 w-9 flex-none place-items-center rounded-[10px] bg-surface-card text-content-secondary hover:text-content disabled:cursor-default disabled:opacity-40'
|
||||
|
||||
/**
|
||||
* The bar on top of the Costs tab, in the same shape as the one Transports,
|
||||
* Bookings, Lists and Files open with: the tab's name, then what the numbers
|
||||
* cover (the trip's days and who travels), and the two actions on the right.
|
||||
* Bookings, Lists and Files open with: the tab's name and what the numbers
|
||||
* cover, then how to narrow the ledger and the actions on the right.
|
||||
*/
|
||||
export default function CostsToolbar({ dateMeta, people, me, colorFor, canEdit, canSettle, onSettleAll, onAddExpense, onScanReceipt }: CostsToolbarProps) {
|
||||
export default function CostsToolbar({ dateMeta, people, me, colorFor, canEdit, canSettle, onSettleAll, onAddExpense, onScanReceipt, filters }: CostsToolbarProps) {
|
||||
const { t } = useTranslation()
|
||||
const searchRef = useRef<HTMLInputElement>(null)
|
||||
const chip = 'inline-flex items-center whitespace-nowrap rounded-full bg-surface-card px-3 py-1.5 font-medium text-content-muted shadow-sm'
|
||||
const button = 'inline-flex items-center gap-1.5 rounded-[10px] border-0 px-[14px] py-[9px] font-medium hover:opacity-[0.88]'
|
||||
const button = 'inline-flex h-9 items-center gap-1.5 rounded-[10px] border-0 px-3.5 font-medium hover:opacity-[0.88]'
|
||||
|
||||
return (
|
||||
<div className="mb-4 flex flex-wrap items-center gap-4 rounded-[18px] bg-surface-tertiary py-3.5 pl-[22px] pr-4">
|
||||
<div className="mb-4 flex flex-wrap items-center gap-2.5 rounded-[18px] bg-surface-tertiary py-3 pl-[22px] pr-3">
|
||||
<h2 className="m-0 shrink-0 text-subtitle font-semibold tracking-[-0.01em] text-content">{t('trip.tabs.budget')}</h2>
|
||||
<div className="h-[22px] w-px shrink-0 bg-edge-faint" />
|
||||
<div className="mx-1.5 h-[22px] w-px shrink-0 bg-edge-faint" />
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1.5" style={{ fontSize: BODY_SIZE }}>
|
||||
{dateMeta && (
|
||||
<span className={`${chip} gap-3`}>
|
||||
@@ -59,23 +88,117 @@ export default function CostsToolbar({ dateMeta, people, me, colorFor, canEdit,
|
||||
<b className="text-content">{t('costs.travelers', { count: people.length })}</b>
|
||||
</span>
|
||||
</div>
|
||||
{canEdit && (
|
||||
<div className="ml-auto flex shrink-0 flex-wrap gap-1.5" style={{ fontSize: BODY_SIZE }}>
|
||||
<button type="button" onClick={onSettleAll} disabled={!canSettle}
|
||||
className={`${button} bg-surface-card text-content disabled:cursor-default disabled:opacity-40`}>
|
||||
<Check size={14} strokeWidth={2.5} />
|
||||
{t('costs.settleUp')}
|
||||
</button>
|
||||
{onScanReceipt && (
|
||||
<button type="button" onClick={onScanReceipt} className={`${button} bg-surface-card text-content`}>
|
||||
<ScanLine size={14} strokeWidth={2.5} />
|
||||
{t('costs.scan.button')}
|
||||
|
||||
{filters && (
|
||||
<>
|
||||
<label className="flex h-9 w-[200px] items-center gap-2 rounded-[10px] bg-surface-card px-3 text-content-faint focus-within:ring-2 focus-within:ring-[color:var(--text-primary)]">
|
||||
<Search size={14} strokeWidth={2} className="flex-none" />
|
||||
<input
|
||||
ref={searchRef}
|
||||
value={filters.query}
|
||||
onChange={e => filters.onQuery(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Escape') { filters.onQuery(''); searchRef.current?.blur() } }}
|
||||
placeholder={t('costs.searchPlaceholder')}
|
||||
aria-label={t('common.search')}
|
||||
className="min-w-0 flex-1 border-0 bg-transparent text-content outline-none placeholder:text-content-faint dark:bg-transparent"
|
||||
style={{ fontSize: BODY_SIZE }}
|
||||
/>
|
||||
{filters.query && (
|
||||
<Tooltip label={t('common.clear')}>
|
||||
<button type="button" onClick={() => filters.onQuery('')} aria-label={t('common.clear')} className="flex-none text-content-faint hover:text-content"><X size={13} /></button>
|
||||
</Tooltip>
|
||||
)}
|
||||
</label>
|
||||
<FilterMenu {...filters} />
|
||||
<Tooltip label={t('budget.exportCsv')}>
|
||||
<button type="button" onClick={filters.onExport} disabled={!filters.canExport} aria-label={t('budget.exportCsv')} className={BAR_BTN}>
|
||||
<Download size={15} strokeWidth={2} />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</>
|
||||
)}
|
||||
|
||||
{canEdit && (
|
||||
<>
|
||||
{filters && <span className="mx-0.5 h-[22px] w-px flex-none bg-edge-faint" />}
|
||||
<div className="flex shrink-0 flex-wrap gap-1.5" style={{ fontSize: BODY_SIZE }}>
|
||||
<button type="button" onClick={onSettleAll} disabled={!canSettle}
|
||||
className={`${button} bg-surface-card text-content disabled:cursor-default disabled:opacity-40`}>
|
||||
<Check size={14} strokeWidth={2.5} />
|
||||
{t('costs.settleUp')}
|
||||
</button>
|
||||
{onScanReceipt && (
|
||||
<button type="button" onClick={onScanReceipt} className={`${button} bg-surface-card text-content`}>
|
||||
<ScanLine size={14} strokeWidth={2.5} />
|
||||
{t('costs.scan.button')}
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={onAddExpense} className={`${button} bg-accent text-accent-text`}>
|
||||
<Plus size={14} strokeWidth={2.5} />
|
||||
{t('costs.addExpense')}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Whose expenses, which category and which day, in one place; the button counts what is switched on. */
|
||||
function FilterMenu(f: CostsFilterProps) {
|
||||
const { t } = useTranslation()
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
const close = useCallback(() => setOpen(false), [])
|
||||
useDismissOnOutside(ref, open, close)
|
||||
const active = (f.owner !== 'all' ? 1 : 0) + (f.category ? 1 : 0) + (f.day ? 1 : 0)
|
||||
const owners: [OwnerFilter, string][] = [['all', t('costs.filter.all')], ['mine', t('costs.filter.mine')], ['owed', t('costs.filter.owed')]]
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative flex-none">
|
||||
<Tooltip label={t('reservations.filter')}>
|
||||
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} aria-label={t('reservations.filter')} className={`${BAR_BTN} ${active ? 'text-content' : ''}`}>
|
||||
<Filter size={15} strokeWidth={2} />
|
||||
{active > 0 && <span className="absolute -right-1 -top-1 grid h-4 min-w-4 place-items-center rounded-full bg-accent px-1 font-geist font-bold text-accent-text" style={{ fontSize: 'calc(9px * var(--fs-scale-caption, 1))' }}>{active}</span>}
|
||||
</button>
|
||||
</Tooltip>
|
||||
{open && (
|
||||
<div role="menu" onKeyDown={e => { if (e.key === 'Escape') close() }} className="absolute right-0 top-11 z-30" style={{ ...POPOVER, width: 310 }}>
|
||||
<div className="mx-1.5 mb-1 mt-1.5 flex rounded-[10px] bg-surface-tertiary p-[3px]">
|
||||
{owners.map(([o, label]) => (
|
||||
<button key={o} type="button" onClick={() => f.onOwner(o)} aria-pressed={f.owner === o}
|
||||
className={`flex-1 rounded-[8px] py-1 font-medium ${f.owner === o ? 'bg-surface-card text-content shadow-sm' : 'text-content-muted hover:text-content'}`}
|
||||
style={{ fontSize: 'calc(12px * var(--fs-scale-body, 1))' }}>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div style={POPOVER_DIVIDER} />
|
||||
<div style={POPOVER_CAPTION}>{t('costs.category')}</div>
|
||||
<div className="max-h-[220px] overflow-y-auto">
|
||||
{f.categoryOptions.map(o => (
|
||||
<PopoverItem key={o.value || 'all'} active={f.category === o.value} onClick={() => f.onCategory(o.value)}
|
||||
icon={o.icon ?? null} label={o.label}
|
||||
trailing={f.category === o.value ? <Check size={13} className="text-content-muted" /> : undefined} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div style={POPOVER_DIVIDER} />
|
||||
<div style={POPOVER_CAPTION}>{t('costs.day')}</div>
|
||||
<div className="max-h-[220px] overflow-y-auto">
|
||||
{f.dayOptions.map(o => (
|
||||
<PopoverItem key={o.value || 'all'} active={f.day === o.value} onClick={() => f.onDay(o.value)} icon={null} label={o.label}
|
||||
trailing={f.day === o.value ? <Check size={13} className="text-content-muted" /> : undefined} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
{active > 0 && (
|
||||
<>
|
||||
<div style={POPOVER_DIVIDER} />
|
||||
<PopoverItem icon={<RotateCcw size={14} />} label={t('reservations.resetFilters')} onClick={() => { f.onResetFilters(); close() }} />
|
||||
</>
|
||||
)}
|
||||
<button type="button" onClick={onAddExpense} className={`${button} bg-accent text-accent-text`}>
|
||||
<Plus size={14} strokeWidth={2.5} />
|
||||
{t('costs.addExpense')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -127,7 +127,10 @@ describe('Scan receipt', () => {
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
|
||||
await openDialog()
|
||||
fireEvent.click(screen.getByRole('dialog').parentElement!)
|
||||
// Only a press that starts and ends on the backdrop closes it.
|
||||
const backdrop = screen.getByRole('dialog').parentElement!
|
||||
fireEvent.mouseDown(backdrop)
|
||||
fireEvent.click(backdrop)
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
expect(dialog).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { createPortal } from 'react-dom'
|
||||
import { useRef, useState } from 'react'
|
||||
import { useId, useRef, useState } from 'react'
|
||||
import { ScanLine, X } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
|
||||
import { RECEIPT_PHOTO_ACCEPT, type ReceiptScan } from './useReceiptScan'
|
||||
|
||||
/**
|
||||
@@ -13,6 +15,8 @@ export function ReceiptScanModal({ scan }: { scan: ReceiptScan }) {
|
||||
const { t } = useTranslation()
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const [dragOver, setDragOver] = useState(false)
|
||||
const isPhone = useIsPhone()
|
||||
const labelId = useId()
|
||||
if (!scan.isOpen) return null
|
||||
|
||||
const onDrop = (e: React.DragEvent) => {
|
||||
@@ -21,6 +25,60 @@ export function ReceiptScanModal({ scan }: { scan: ReceiptScan }) {
|
||||
scan.choose(Array.from(e.dataTransfer.files))
|
||||
}
|
||||
|
||||
const picker = (
|
||||
<input ref={inputRef} type="file" accept={RECEIPT_PHOTO_ACCEPT} hidden data-testid="receipt-scan-input"
|
||||
onChange={(e) => { scan.choose(e.target.files ? Array.from(e.target.files) : []); e.target.value = '' }} />
|
||||
)
|
||||
const dropHandlers = {
|
||||
onDragOver: (e: React.DragEvent) => { e.preventDefault(); setDragOver(true) },
|
||||
onDragEnter: (e: React.DragEvent) => { e.preventDefault(); setDragOver(true) },
|
||||
onDragLeave: (e: React.DragEvent) => { if (e.target === e.currentTarget) setDragOver(false) },
|
||||
onDrop,
|
||||
}
|
||||
|
||||
// The desktop opens it in the planner's dialog, like the costs editors; the phone keeps its own.
|
||||
if (!isPhone) return (
|
||||
<DialogShell
|
||||
onClose={scan.close}
|
||||
labelledBy={labelId}
|
||||
width="narrow"
|
||||
header={(
|
||||
<DialogHeader
|
||||
tile={<DialogTile><ScanLine size={20} strokeWidth={1.9} className="text-content-muted" /></DialogTile>}
|
||||
tint={NEUTRAL_TINT}
|
||||
labelId={labelId}
|
||||
onClose={scan.close}
|
||||
title={t('costs.scan.title')}
|
||||
sub={t('costs.scan.accepted')}
|
||||
subWraps
|
||||
/>
|
||||
)}
|
||||
footer={(
|
||||
<DialogFooter>
|
||||
<FooterSpacer />
|
||||
<DialogButton onClick={scan.close}>{t('common.cancel')}</DialogButton>
|
||||
<DialogButton variant="primary" onClick={scan.start} disabled={!scan.photo || scan.starting}>
|
||||
{scan.starting ? t('costs.scan.reading') : t('costs.scan.start')}
|
||||
</DialogButton>
|
||||
</DialogFooter>
|
||||
)}
|
||||
>
|
||||
{picker}
|
||||
<button type="button" onClick={() => inputRef.current?.click()} {...dropHandlers}
|
||||
className={`flex min-h-[132px] w-full flex-col items-center justify-center gap-2 rounded-2xl border-2 border-dashed px-4 py-5 text-center transition-colors ${dragOver ? 'border-content-muted bg-surface-tertiary' : 'border-edge bg-surface-secondary hover:border-content-faint'}`}>
|
||||
<span className="pointer-events-none grid h-10 w-10 place-items-center rounded-full bg-surface-card shadow-sm">
|
||||
<ScanLine size={18} strokeWidth={1.9} className={dragOver ? 'text-content' : 'text-content-muted'} />
|
||||
</span>
|
||||
<span className={`pointer-events-none break-all font-semibold ${scan.photo ? 'text-content' : 'text-content-muted'}`} style={fs(13, 'body')}>
|
||||
{dragOver ? t('costs.scan.dropActive') : scan.photo ? scan.photo.name : t('costs.scan.dropHere')}
|
||||
</span>
|
||||
</button>
|
||||
{scan.error && (
|
||||
<div role="alert" className="rounded-[12px] bg-danger-soft px-3 py-2.5 text-danger" style={fs(12, 'body')}>{scan.error}</div>
|
||||
)}
|
||||
</DialogShell>
|
||||
)
|
||||
|
||||
return createPortal(
|
||||
<div role="presentation" className="fixed inset-0 z-[99999] flex items-center justify-center bg-black/40 p-4" onClick={(e) => { if (e.target === e.currentTarget) scan.close() }}>
|
||||
<div role="dialog" aria-modal="true" aria-label={t('costs.scan.title')} className="flex max-h-[90vh] w-full max-w-[540px] flex-col rounded-2xl bg-surface-card p-6 shadow-2xl">
|
||||
|
||||
@@ -66,10 +66,10 @@ export function splitShareLabel(
|
||||
fx: ExpenseFx | null,
|
||||
participants: number,
|
||||
base: string,
|
||||
sym: (currency: string) => string,
|
||||
sym: ((currency: string) => string) | null,
|
||||
locale: string,
|
||||
): string {
|
||||
const entered = sym(currency) + each.toFixed(2)
|
||||
const entered = sym ? sym(currency) + each.toFixed(2) : formatMoney(each, currency, locale)
|
||||
const whole = fx ? (fx.shown ?? fx.inTrip) : null
|
||||
if (whole == null || participants <= 0) return entered
|
||||
return `${entered} → ${formatMoney(whole / participants, base, locale)}`
|
||||
|
||||
Reference in New Issue
Block a user