feat(budget): link existing expenses to bookings and places, several per booking

Discussion #2084: a cost bought later (the seat upgrade for a flight) could
not be tied to the booking it belongs to, and a booking held one expense.

- The Costs block of the booking, transport and place forms lists every
  linked expense with edit, unlink (the expense stays in Costs) and delete,
  and offers the expenses that belong nowhere yet under Link existing
  expense. The phone sheets get the same block in their own design, and
  their Files row lists the attached files and links an existing one.
- PUT /budget/:id, update_budget_item (MCP) and costs.update (plugin RPC)
  take reservation_id / place_id; create and update refuse an id from
  another trip on all three paths.
- The booking's mirrored price is the sum of its expenses when they share
  one currency (none counts as the trip's), else the first one, with that
  currency, and follows every change to a linked expense. The booking
  form's price field leaves a booking with several expenses alone.
- Deleting a booking deletes all of its linked expenses and broadcasts each
  one, also from the MCP delete tools.
- Cards show the price with its currency.
- Booking and transport dialogs: Booking Type and Travelers as dropdowns at
  the top, the URL beside Files (transports gain the URL field). The row is
  one shared component; linking and unlinking files go through the store.

Help center pictures and texts for the booking, transport and expense
guides are redone in all 27 languages, five Costs labels that were still
English in 16 languages are translated, and the wiki follows.
This commit is contained in:
Maurice
2026-09-25 15:34:32 +02:00
parent 1f79776070
commit 8864edda18
188 changed files with 4800 additions and 1124 deletions
@@ -0,0 +1,79 @@
import { useEffect, useRef, useState } from 'react'
import { Paperclip, Link2, FileText } from 'lucide-react'
import { useTranslation } from '../../i18n'
import type { TripFile } from '../../types'
/**
* The file actions of a booking or transport dialog: attach a new file, and
* once the record exists link a file the trip already has. Two equal buttons
* side by side, the same row the Costs block uses below them.
*/
export function BookingFileButtons({ canAttach, uploading, onAttach, linkable, onLink }: {
canAttach: boolean
uploading: boolean
onAttach: () => void
/** Files of the trip this record could take; empty (or before the first save) hides the link button. */
linkable: TripFile[]
/** Links one; resolves true when it worked, which closes the list. */
onLink: (file: TripFile) => Promise<boolean>
}) {
const { t } = useTranslation()
const [open, setOpen] = useState(false)
const pickerRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!open) return
const closeOnOutsidePointer = (event: PointerEvent) => {
if (!pickerRef.current?.contains(event.target as Node)) setOpen(false)
}
document.addEventListener('pointerdown', closeOnOutsidePointer)
return () => document.removeEventListener('pointerdown', closeOnOutsidePointer)
}, [open])
const canLink = linkable.length > 0
if (!canAttach && !canLink) return null
const buttonClass = 'bg-surface-secondary border border-edge text-content transition-colors hover:bg-surface-tertiary disabled:cursor-default disabled:opacity-60'
const buttonStyle = {
width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, padding: '8px 13px',
borderRadius: 10, fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
} as const
return (
<div style={{ display: 'grid', gridTemplateColumns: canAttach && canLink ? '1fr 1fr' : '1fr', gap: 8 }}>
{canAttach && (
<button type="button" onClick={onAttach} disabled={uploading} className={buttonClass} style={buttonStyle}>
<Paperclip size={14} />
{uploading ? t('reservations.uploading') : t('reservations.attachFile')}
</button>
)}
{canLink && (
<div ref={pickerRef} style={{ position: 'relative' }}>
<button type="button" onClick={() => setOpen(v => !v)} aria-expanded={open} className={buttonClass} style={buttonStyle}>
<Link2 size={14} /> {t('reservations.linkExisting')}
</button>
{open && (
<div className="bg-surface-card" style={{
position: 'absolute', bottom: '100%', left: 0, right: 0, marginBottom: 6, zIndex: 50,
border: '1px solid var(--border-secondary)', borderRadius: 12,
boxShadow: '0 12px 32px -8px rgba(0,0,0,0.25), 0 2px 6px rgba(0,0,0,0.06)', padding: 6, maxHeight: 220, overflowY: 'auto',
}}>
{linkable.map(f => (
<button key={f.id} type="button" onClick={async () => { if (await onLink(f)) setOpen(false) }}
className="text-content transition-colors hover:bg-surface-tertiary"
style={{
display: 'flex', alignItems: 'center', gap: 8, width: '100%', padding: '8px 10px',
border: 'none', cursor: 'pointer', fontSize: 'calc(12.5px * var(--fs-scale-body, 1))', fontFamily: 'inherit',
borderRadius: 8, textAlign: 'left',
}}>
<FileText size={13} className="text-content-faint" style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{f.original_name}</span>
</button>
))}
</div>
)}
</div>
)}
</div>
)
}