mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
feat(ui): Costs bar like the other tabs, desktop packing list in the phone's look
The Costs tab opens with the same bar as Transports, Bookings, Lists and Files: the tab's name, the trip's dates and days in one pill, the travelers, and Settle up and Add expense on the right. The desktop packing list takes the phone's look without losing anything it shows. Category cards get a tinted head band, rows get hairlines and filled checkboxes, owner, quantity and weight read as small badges, and the bin and a menu with Move to List, Sharing, Rename and Delete replace the row of icons. What a row does not use stays dimmed until hover or focus, so nothing leaves a gap. A click on the name renames, ticked items too. Add item opens a composer shaped like the next row, Add list moved into the Lists bar, Add list and Save as template ask for the name in a dialog, and Remove checked sits beside the progress bar. The Bags panel becomes a card, and the item menu, the bag picker, the list menu and the bag member picker share one popover look and close on a click beside them. Help center pictures for Costs and Lists are re-rendered, the Lists guide texts follow the new controls in all 27 languages, and the wiki pages are updated. The phone screens are unchanged.
This commit is contained in:
@@ -27,6 +27,7 @@ import type { TripMember } from './BudgetPanelMemberChips'
|
||||
import GuestBadge from '../shared/GuestBadge'
|
||||
import { NumericInput } from '../shared/NumericInput'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
import CostsToolbar from './CostsToolbar'
|
||||
|
||||
interface CostsPanelProps {
|
||||
tripId: number
|
||||
@@ -355,44 +356,12 @@ export default function CostsPanel({ tripId, tripMembers = [] }: CostsPanelProps
|
||||
) : null
|
||||
|
||||
return (
|
||||
<div className="costs-root" style={{ minHeight: '100%', background: 'var(--c-bg)', padding: isMobile ? '6px 14px 28px' : '40px 24px 48px' }}>
|
||||
<div className="costs-root" style={{ minHeight: '100%', background: 'var(--c-bg)', padding: isMobile ? '6px 14px 28px' : '24px 28px 48px' }}>
|
||||
{isMobile ? MobileBody() : (
|
||||
<div style={{ maxWidth: '100%', margin: '0 auto' }}>
|
||||
{/* ── Header bar ── */}
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 24, marginBottom: 28, flexWrap: 'wrap' }}>
|
||||
<div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
|
||||
{dateMeta && (
|
||||
<span className="bg-surface-card border border-edge text-content-muted" style={{ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '8px 14px', borderRadius: 999, fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 500, whiteSpace: 'nowrap' }}>
|
||||
{dateMeta.range} · <b className="text-content">{t('costs.daysCount', { count: dateMeta.days })}</b>
|
||||
</span>
|
||||
)}
|
||||
<span className="bg-surface-card border border-edge text-content-muted" style={{ display: 'inline-flex', alignItems: 'center', gap: 8, padding: '8px 14px 8px 10px', borderRadius: 999, fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 500 }}>
|
||||
<span style={{ display: 'inline-flex' }}>
|
||||
{people.slice(0, 4).map((p, i) => {
|
||||
const common = { width: 22, height: 22, borderRadius: '50%', border: '2px solid var(--bg-card)', marginLeft: i ? -8 : 0, flexShrink: 0 } as const
|
||||
return p.avatar_url
|
||||
? <img key={p.id} src={p.avatar_url} alt="" style={{ ...common, objectFit: 'cover', display: 'block' }} />
|
||||
: <span key={p.id} style={{ ...common, background: colorFor(p.id), color: '#fff', display: 'grid', placeItems: 'center', fontSize: 'calc(9px * var(--fs-scale-caption, 1))', fontWeight: 700 }}>{(p.id === me ? t('costs.youShort') : p.username.charAt(0)).toUpperCase()}</span>
|
||||
})}
|
||||
</span>
|
||||
<b className="text-content">{t('costs.travelers', { count: people.length })}</b>
|
||||
</span>
|
||||
</div>
|
||||
{canEdit && (
|
||||
<div style={{ display: 'flex', gap: 10 }}>
|
||||
<button type="button" onClick={settleAll} disabled={!(settlement?.flows || []).length}
|
||||
className="bg-surface-card border border-edge text-content disabled:opacity-40"
|
||||
style={{ display: 'inline-flex', alignItems: 'center', gap: 7, padding: '10px 16px', borderRadius: 12, fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit' }}>
|
||||
<Check size={16} /> {t('costs.settleUp')}
|
||||
</button>
|
||||
<button type="button" onClick={() => { setEditing(null); setModalOpen(true) }}
|
||||
className="bg-[var(--text-primary)] text-[var(--bg-primary)]"
|
||||
style={{ display: 'inline-flex', alignItems: 'center', gap: 7, padding: '10px 18px', borderRadius: 12, fontSize: 'calc(14px * var(--fs-scale-body, 1))', fontWeight: 600, border: 0, cursor: 'pointer', fontFamily: 'inherit' }}>
|
||||
<Plus size={16} /> {t('costs.addExpense')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<CostsToolbar dateMeta={dateMeta} people={people} me={me} colorFor={colorFor}
|
||||
canEdit={canEdit} canSettle={(settlement?.flows || []).length > 0}
|
||||
onSettleAll={settleAll} onAddExpense={() => { setEditing(null); setModalOpen(true) }} />
|
||||
|
||||
{/* ── Summary cards ── */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 36 }} className="costs-summary">
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// FE-COSTSBAR-001 to FE-COSTSBAR-007
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '../../../tests/helpers/render'
|
||||
import CostsToolbar from './CostsToolbar'
|
||||
import type { TripMember } from './BudgetPanelMemberChips'
|
||||
|
||||
const PEOPLE: TripMember[] = [
|
||||
{ id: 1, username: 'ada', avatar_url: '/uploads/avatars/ada.png' },
|
||||
{ id: 2, username: 'bob', avatar_url: null },
|
||||
]
|
||||
|
||||
function setup(props: Partial<Parameters<typeof CostsToolbar>[0]> = {}) {
|
||||
const onSettleAll = vi.fn()
|
||||
const onAddExpense = vi.fn()
|
||||
render(
|
||||
<CostsToolbar dateMeta={{ range: 'Oct 9 – Oct 16', days: 8 }} people={PEOPLE} me={1} colorFor={() => 'linear-gradient(#000,#111)'}
|
||||
canEdit canSettle onSettleAll={onSettleAll} onAddExpense={onAddExpense} {...props} />,
|
||||
)
|
||||
return { onSettleAll, onAddExpense }
|
||||
}
|
||||
|
||||
describe('CostsToolbar', () => {
|
||||
it('FE-COSTSBAR-001: names the tab like the other planner bars', () => {
|
||||
setup()
|
||||
expect(screen.getByRole('heading', { level: 2, name: 'Costs' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-COSTSBAR-002: splits the trip span and its days with a rule instead of a dot', () => {
|
||||
setup()
|
||||
const days = screen.getByText('8 days')
|
||||
const pill = days.parentElement!
|
||||
expect(pill).toHaveTextContent('Oct 9 – Oct 16')
|
||||
expect(pill.textContent).not.toContain('·')
|
||||
expect(pill.querySelector('[aria-hidden]')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('FE-COSTSBAR-003: leaves the span out for a trip without dates', () => {
|
||||
setup({ dateMeta: null })
|
||||
expect(screen.queryByText(/^\d+ days$/)).toBeNull()
|
||||
expect(screen.getByText('2 travelers')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-COSTSBAR-004: shows each traveler by avatar, or by initial with "you" for the viewer', () => {
|
||||
setup({ people: [{ id: 1, username: 'ada', avatar_url: null }, ...PEOPLE.slice(1), { id: 3, username: 'cy', avatar_url: '/uploads/avatars/cy.png' }] })
|
||||
expect(screen.getByText('Y')).toBeInTheDocument()
|
||||
expect(screen.getByText('B')).toBeInTheDocument()
|
||||
expect(document.querySelector('img[src="/uploads/avatars/cy.png"]')).not.toBeNull()
|
||||
expect(screen.getByText('3 travelers')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-COSTSBAR-005: runs settle up and add expense from the right of the bar', () => {
|
||||
const { onSettleAll, onAddExpense } = setup()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Settle up' }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add expense' }))
|
||||
expect(onSettleAll).toHaveBeenCalledTimes(1)
|
||||
expect(onAddExpense).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('FE-COSTSBAR-006: disables settle up while there is nothing to settle', () => {
|
||||
setup({ canSettle: false })
|
||||
expect(screen.getByRole('button', { name: 'Settle up' })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('FE-COSTSBAR-007: a viewer without edit rights gets the bar without actions', () => {
|
||||
setup({ canEdit: false })
|
||||
expect(screen.queryByRole('button')).toBeNull()
|
||||
expect(screen.getByText('8 days')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Check, Plus } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import type { TripMember } from './BudgetPanelMemberChips'
|
||||
|
||||
interface CostsToolbarProps {
|
||||
/** The trip's span as a formatted range and its length in days; null for a trip without dates. */
|
||||
dateMeta: { range: string; days: number } | null
|
||||
people: TripMember[]
|
||||
me: number
|
||||
colorFor: (userId: number) => string
|
||||
canEdit: boolean
|
||||
/** Whether there is any suggested transfer left to settle. */
|
||||
canSettle: boolean
|
||||
onSettleAll: () => void
|
||||
onAddExpense: () => void
|
||||
}
|
||||
|
||||
const BODY_SIZE = 'calc(13px * var(--fs-scale-body, 1))'
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export default function CostsToolbar({ dateMeta, people, me, colorFor, canEdit, canSettle, onSettleAll, onAddExpense }: CostsToolbarProps) {
|
||||
const { t } = useTranslation()
|
||||
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]'
|
||||
|
||||
return (
|
||||
<div className="mb-4 flex flex-wrap items-center gap-4 rounded-[18px] bg-surface-tertiary py-3.5 pl-[22px] pr-4">
|
||||
<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="flex min-w-0 flex-1 flex-wrap items-center gap-1.5" style={{ fontSize: BODY_SIZE }}>
|
||||
{dateMeta && (
|
||||
<span className={`${chip} gap-3`}>
|
||||
{dateMeta.range}
|
||||
{/* One pill in two fields, cut straight through in the bar's colour rather than two rounded halves. */}
|
||||
<span aria-hidden className="-my-1.5 w-[3px] self-stretch bg-surface-tertiary" />
|
||||
<b className="text-content">{t('costs.daysCount', { count: dateMeta.days })}</b>
|
||||
</span>
|
||||
)}
|
||||
<span className={`${chip} gap-2 pl-1.5`}>
|
||||
<span className="inline-flex">
|
||||
{people.slice(0, 4).map((p, i) => {
|
||||
const ring = { width: 22, height: 22, marginLeft: i ? -8 : 0 }
|
||||
return p.avatar_url
|
||||
? <img key={p.id} src={p.avatar_url} alt="" className="block shrink-0 rounded-full border-2 border-surface-card object-cover" style={ring} />
|
||||
: (
|
||||
<span key={p.id} className="grid shrink-0 place-items-center rounded-full border-2 border-surface-card font-bold" style={{
|
||||
...ring, background: colorFor(p.id), fontSize: 'calc(9px * var(--fs-scale-caption, 1))',
|
||||
color: '#fff', // theme-lint-disable: an initial on the member's own colour
|
||||
}}>{(p.id === me ? t('costs.youShort') : p.username.charAt(0)).toUpperCase()}</span>
|
||||
)
|
||||
})}
|
||||
</span>
|
||||
<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>
|
||||
<button type="button" onClick={onAddExpense} className={`${button} bg-accent text-accent-text`}>
|
||||
<Plus size={14} strokeWidth={2.5} />
|
||||
{t('costs.addExpense')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user