mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
feat(costs): let a trip keep its costs as totals only (#1714)
Travellers who track what a trip costs but never split it saw an Unfinished warning on every expense and a settle-up they had no use for. A trip now has a costs mode (appended migration, trips.costs_mode, split by default); totals leaves payers, shares and settling up out of Costs on desktop and phone through the same gate as a trip of one, and saves new expenses without a payer. PUT /api/trips/:id and update_trip take it on budget_edit. The split chips move into their own component.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { useId } from 'react';
|
||||
|
||||
import { useTranslation } from '../../i18n';
|
||||
import type { Trip } from '../../types';
|
||||
import ToggleSwitch from '../Settings/ToggleSwitch';
|
||||
import { fs } from '../shared/DialogShell';
|
||||
import { useCostsMode } from './useCostsMode';
|
||||
|
||||
/**
|
||||
* The switch between splitting a trip's costs and keeping the totals only
|
||||
* (#1714), at the foot of the Costs sidebar. Nothing is shown to someone who may
|
||||
* not change it, or on a trip of one.
|
||||
*/
|
||||
export function CostsModeCard({
|
||||
trip,
|
||||
memberCount,
|
||||
canEdit,
|
||||
className,
|
||||
}: {
|
||||
trip: Trip | null | undefined;
|
||||
memberCount: number;
|
||||
canEdit: boolean;
|
||||
className: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const hintId = useId();
|
||||
const { splitting, setSplitting, saving, offered } = useCostsMode(trip, memberCount, canEdit);
|
||||
if (!offered) return null;
|
||||
|
||||
return (
|
||||
<section aria-label={t('costs.mode.label')} className={className}>
|
||||
<div className="flex items-start gap-3 px-4 py-4">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="font-semibold text-content" style={fs(13, 'body')}>
|
||||
{t('costs.mode.label')}
|
||||
</div>
|
||||
<p id={hintId} className="m-0 mt-1 text-content-faint" style={fs(12, 'body')}>
|
||||
{splitting ? t('costs.mode.hintSplit') : t('costs.mode.hintTotals')}
|
||||
</p>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
on={splitting}
|
||||
onToggle={() => void setSplitting(!splitting)}
|
||||
label={t('costs.mode.label')}
|
||||
describedBy={hintId}
|
||||
disabled={saving}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user