feat(roadtrip): add a stop by hand in the form the rest of TREK adds places in

The dialog built for this last round was its own thing and showed it: the
suggestion list was barely legible, clipped at the bottom, and never more
than two rows tall. It also lacked most of what the ordinary add-place form
has had for years.

So it is gone, and "Add manually" opens that form instead, in a service-stop
mode. The category control becomes the kind of stop and the time spent
there, the costs section is dropped, and an "Add between" row says where on
the drive it goes. Everything else comes along rather than being rebuilt:
the typed-ahead search with its source marks, the coordinate fields for a
charger no index knows, address, website, phone, notes, times, files and the
duplicate check. With the mode absent the form is the same component it was,
which its own suites still pin.

Where the stop lands is worked out when it is saved rather than when the
form opens, because the coordinate only exists once a place has been chosen.
One function answers both what the select shows and where the stop goes, so
the two cannot disagree, and the write goes through the same assignment path
as every other insert, via re-anchoring included: a stop pushed into a day
shifts every via anchored at or after it, and without re-anchoring first the
drawn road runs forward, doubles back and runs out again.

The select recommends rather than merely offering. Every leg of every routed
day is measured against the place separately and they are listed nearest
first, each with its own distance, so the preselected one visibly is the
closest and overruling it is an informed choice. The word they all shared
moved into the caption.

A stop with no position at all is not filed on a drive by guesswork. It
keeps its kind and goes to the trip's places, and the form says so and says
how to change it.
This commit is contained in:
Maurice
2026-09-14 16:22:03 +02:00
parent 68ce177901
commit da679e6266
39 changed files with 1632 additions and 940 deletions
@@ -1,4 +1,4 @@
// FE-COMP-PLACEFORM-001 to FE-COMP-PLACEFORM-036, FE-PLANNER-PLACEFORM-016 to FE-PLANNER-PLACEFORM-067, plus FE-PLANNER-PLACEFORM-068 to -072
// FE-COMP-PLACEFORM-001 to FE-COMP-PLACEFORM-036, FE-PLANNER-PLACEFORM-016 to FE-PLANNER-PLACEFORM-067, plus FE-PLANNER-PLACEFORM-068 to -080
import { render, screen, waitFor, fireEvent, within } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
@@ -1695,3 +1695,251 @@ describe('PlaceFormModal remaining branches', () => {
});
});
});
// ── The road trip's own use of this form: a service stop added by hand ────────
/**
* FE-PLANNER-PLACEFORM-073 to -080.
*
* The corridor search reads OpenStreetMap and misses a good share of the chargers
* actually standing at a junction, so "add manually" opens THIS form rather than a
* bespoke one: its typed-ahead search is the one the rest of TREK uses. Three things
* change and nothing else does, which is what the first two tests here pin.
*
* Where the stop goes cannot be decided when the dialog opens, because nothing has been
* chosen yet. It is worked out at the save, from the coordinates being saved.
*/
describe('PlaceFormModal as a road trip service stop', () => {
type Mode = NonNullable<React.ComponentProps<typeof PlaceFormModal>['serviceStop']>;
const serviceStop = (over: Partial<Mode> = {}): Mode => ({
days: [
{ dayId: 5, dayNumber: 1, stops: ['Hamburg', 'Bremen', 'Berlin'] },
{ dayId: 6, dayNumber: 2, stops: ['Berlin', 'Dresden'] },
],
appendDay: { dayId: 5, dayNumber: 1, position: 3 },
// Everything east of the twelfth meridian falls on the second day's leg here; the
// real projection is the planner's and has its own suite.
targetFor: (_lat: number, lng: number) =>
lng > 12 ? { dayId: 6, position: 1, offRouteKm: 0.4 } : { dayId: 5, position: 1, offRouteKm: 0.2 },
...over,
});
const withBudgetAddon = () => seedStore(useAddonStore, {
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
loaded: true,
});
const typeCoords = (lat: string, lng: string) => {
fireEvent.change(screen.getByPlaceholderText(/Latitude/i), { target: { value: lat } });
fireEvent.change(screen.getByPlaceholderText(/Longitude/i), { target: { value: lng } });
};
const named = (name: string) => {
fireEvent.change(screen.getByPlaceholderText(/e\.g\. Eiffel Tower/i), { target: { value: name } });
};
it('FE-PLANNER-PLACEFORM-073: the ordinary add place keeps its category and its costs', () => {
withBudgetAddon();
render(<PlaceFormModal {...defaultProps} />);
expect(screen.getByText('Category')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /Create expense/i })).toBeInTheDocument();
expect(screen.queryByText('Kind of stop')).not.toBeInTheDocument();
});
it('FE-PLANNER-PLACEFORM-074: a service stop swaps the category for the kind and drops the costs', () => {
withBudgetAddon();
render(<PlaceFormModal {...defaultProps} serviceStop={serviceStop()} />);
expect(screen.getByText('Kind of stop')).toBeInTheDocument();
expect(screen.getByText('Time at this stop')).toBeInTheDocument();
// Nothing has been chosen yet, so the row that asks where on the drive it goes says
// what it needs first. It turns into the list of legs the moment a place arrives.
expect(screen.getByTestId('service-stop-needs-point')).toBeInTheDocument();
// A petrol stop is not an activity with a budget line, and it is not a taste either.
expect(screen.queryByText('Category')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: /Create expense/i })).not.toBeInTheDocument();
});
it('FE-PLANNER-PLACEFORM-075: it opens on a kind rather than on none, and says which dialog it is', () => {
render(<PlaceFormModal {...defaultProps} serviceStop={serviceStop()} />);
// A stop left without a kind is a numbered destination that counts in every total,
// which is the very thing this path exists to avoid.
expect(screen.getByRole('button', { name: 'Fuel' })).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByRole('button', { name: /10 min/ })).toHaveAttribute('aria-pressed', 'true');
expect(screen.getAllByText('Add as a stop').length).toBeGreaterThan(0);
});
it('FE-PLANNER-PLACEFORM-076: picking a kind also picks how long that kind takes', async () => {
const onSave = vi.fn().mockResolvedValue({ id: 9 });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={serviceStop()} />);
named('Supercharger');
fireEvent.click(screen.getByRole('button', { name: 'Charging' }));
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalled());
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
stop_type: 'charging',
duration_minutes: 30,
category_id: null,
}));
});
it('FE-PLANNER-PLACEFORM-077: where it goes is worked out from the coordinates that are saved', async () => {
const onSave = vi.fn().mockResolvedValue({ id: 9 });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={serviceStop()} />);
// The form opened on nothing at all. These coordinates arrive afterwards, and they
// are what the position has to follow.
named('Supercharger');
typeCoords('51.05', '13.73');
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalled());
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
_serviceStop: { dayId: 6, position: 1, offRouteKm: 0.4 },
}));
});
it('FE-PLANNER-PLACEFORM-078: the leg the traveller overrules is the one that lands', async () => {
const onSave = vi.fn().mockResolvedValue({ id: 9 });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={serviceStop()} />);
named('Supercharger');
typeCoords('51.05', '13.73');
fireEvent.click(screen.getByRole('button', { name: /Berlin · Dresden/ }));
fireEvent.click(screen.getByText(/Bremen · Berlin/));
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalled());
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
// Overruled onto another stretch, so the projection's distance does not come
// along: it was measured against the leg the drive guessed, not this one.
_serviceStop: { dayId: 5, position: 2, offRouteKm: null },
}));
});
it('FE-PLANNER-PLACEFORM-079: a place far off the drawn line is noted, never refused', async () => {
const onSave = vi.fn().mockResolvedValue({ id: 9 });
const far = serviceStop({ targetFor: () => ({ dayId: 5, position: 2, offRouteKm: 18.3 }) });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={far} />);
named('Supercharger');
typeCoords('41.9', '12.5');
expect(screen.getByText(/check which leg it belongs on/)).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalled());
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
_serviceStop: { dayId: 5, position: 2, offRouteKm: 18.3 },
}));
});
it('FE-PLANNER-PLACEFORM-081: a stop with no coordinates is not filed onto a leg by guesswork', async () => {
const onSave = vi.fn().mockResolvedValue({ id: 9 });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={serviceStop()} />);
// The premise case: the charger is in no index, so the traveller types the name. It
// cannot be measured onto a road, and picking a leg for it anyway used to file it as
// the first stop of the trip's first day without a word.
named('Supercharger Dammer Berge');
expect(screen.getByTestId('service-stop-needs-point')).toBeInTheDocument();
expect(screen.queryByText('Add between')).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalled());
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ _serviceStop: null }));
});
it('FE-PLANNER-PLACEFORM-082: a second stop of the same brand saves on the first press', async () => {
// Four hundred kilometres apart and both called Aral, which on a motorway is the
// normal case and is exactly what this path is for. The name check used to refuse
// the first press and demand a second.
seedStore(useTripStore, {
trip: buildTrip({ id: 1 }),
places: [buildPlace({ id: 3, name: 'Aral', lat: 53.1, lng: 8.8 })],
});
const onSave = vi.fn().mockResolvedValue({ id: 9 });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={serviceStop()} />);
named('Aral');
typeCoords('51.05', '13.73');
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
expect(screen.queryByRole('button', { name: /Add anyway/i })).not.toBeInTheDocument();
});
it('FE-PLANNER-PLACEFORM-083: the same pump twice over is noted beside the name, not refused', async () => {
seedStore(useTripStore, {
trip: buildTrip({ id: 1 }),
places: [buildPlace({ id: 3, name: 'Aral Dammer Berge', lat: 52.5, lng: 8.2 })],
});
const onSave = vi.fn().mockResolvedValue({ id: 9 });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={serviceStop()} />);
named('Tankstelle');
typeCoords('52.5', '8.2');
// The same place standing at the same coordinates is worth saying. It is a note
// while the form is being filled, and the press that saves still saves.
expect(screen.getByText(/is already on this trip/)).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
});
it('FE-PLANNER-PLACEFORM-084: an expense intent left over from a refused save never reaches this form', async () => {
withBudgetAddon();
const refused = vi.fn().mockRejectedValue(new Error('Server error'));
const onOpenExpense = vi.fn();
const { rerender } = render(
<PlaceFormModal {...defaultProps} onSave={refused} onOpenExpense={onOpenExpense} />,
);
// An ordinary add place, asked for an expense, that the server refuses.
named('Louvre');
fireEvent.click(screen.getByRole('button', { name: /Create expense/i }));
await waitFor(() => expect(refused).toHaveBeenCalled());
expect(onOpenExpense).not.toHaveBeenCalled();
const saved = vi.fn().mockResolvedValue({ id: 9 });
rerender(<PlaceFormModal {...defaultProps} isOpen={false} onSave={saved} onOpenExpense={onOpenExpense} />);
rerender(
<PlaceFormModal
{...defaultProps}
onSave={saved}
onOpenExpense={onOpenExpense}
serviceStop={serviceStop()}
/>,
);
named('Supercharger');
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
// The one mode whose contract is that costs are gone: an editor opening here would
// file a petrol stop as an activity nobody asked to pay for.
await waitFor(() => expect(saved).toHaveBeenCalled());
expect(onOpenExpense).not.toHaveBeenCalled();
});
it('FE-PLANNER-PLACEFORM-080: with nothing routed it appends to the day the panel is on', async () => {
const onSave = vi.fn().mockResolvedValue({ id: 9 });
const unrouted = serviceStop({ days: [], appendDay: { dayId: 5, dayNumber: 1, position: 2 } });
render(<PlaceFormModal {...defaultProps} onSave={onSave} serviceStop={unrouted} />);
named('Supercharger');
typeCoords('53.55', '9.99');
expect(screen.getByText(/it goes at the end of day 1/)).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
await waitFor(() => expect(onSave).toHaveBeenCalled());
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({
_serviceStop: { dayId: 5, position: 2, offRouteKm: 0 },
}));
});
});
+159 -10
View File
@@ -25,6 +25,9 @@ import type { BookingExpenseRequest } from './BookingCostsSection.types'
import type { Place, Category, Assignment, BudgetItem } from '../../types'
import { NumericInput } from '../shared/NumericInput'
import { PlacesSession } from '../../utils/placesSession'
import ServiceStopSection from '../Roadtrip/ServiceStopSection'
import { DEFAULT_SERVICE_KIND, serviceStopChoice, type ServiceStopMode } from '../Roadtrip/manualStop'
import { STOP_KIND_BY_KEY } from '../Roadtrip/stopKinds'
// The submit payload mirrors the form, but lat/lng are parsed to numbers and
// category_id is normalised, plus any files chosen before the place existed.
@@ -33,6 +36,12 @@ export interface PlaceSubmitData extends Omit<PlaceFormData, 'lat' | 'lng' | 'ca
lng: number | null
category_id: string | null
_pendingFiles?: File[]
/**
* Where a road-trip service stop belongs on the drive, worked out from the
* coordinates being saved. Travels the same way `_pendingFiles` does: the planner
* reads it, strips it, and assigns the new place at that position.
*/
_serviceStop?: { dayId: number; position: number; offRouteKm: number } | null
}
interface PlaceFormModalProps {
@@ -53,6 +62,12 @@ interface PlaceFormModalProps {
/** Opens the Costs editor for this place's linked expense (#1298) — the same
* seam the booking and transport modals use. */
onOpenExpense?: (req: BookingExpenseRequest) => void
/**
* Turns this into the form a road trip's service stop is added on: the category
* control becomes the kind of stop, the costs section goes, and a row asks which leg
* of the drive it belongs on. Absent, nothing about the form changes.
*/
serviceStop?: ServiceStopMode | null
}
@@ -90,17 +105,32 @@ function SourceBadge({ label }: { label: string | null }) {
// trip place if it shares the Google Place ID, the (case-insensitive) name, or
// near-identical coordinates (~11 m). Mirrors the server-side import dedup.
const DUP_COORD_TOLERANCE = 0.0001
/**
* Which resemblances count as evidence.
*
* The defaults are the ordinary add place and are not to be changed. A stop on a drive
* asks a different question: brand names repeat along a motorway and the map record does
* not, so it turns the name off and the OSM object on.
*/
interface DuplicateRules {
byName?: boolean
byOsmId?: boolean
}
function findDuplicatePlace(
form: PlaceFormData,
places: { name?: string | null; lat?: number | null; lng?: number | null; google_place_id?: string | null }[],
places: { name?: string | null; lat?: number | null; lng?: number | null; google_place_id?: string | null; osm_id?: string | null }[],
rules: DuplicateRules = {},
): { name?: string | null } | null {
const { byName = true, byOsmId = false } = rules
const name = (form.name || '').trim().toLowerCase()
const gid = (form.google_place_id || '').trim()
const osmId = (form.osm_id || '').trim()
const lat = form.lat ? Number.parseFloat(form.lat) : null
const lng = form.lng ? Number.parseFloat(form.lng) : null
for (const p of places || []) {
if (gid && p.google_place_id && p.google_place_id === gid) return p
if (name && p.name && p.name.trim().toLowerCase() === name) return p
if (byOsmId && osmId && p.osm_id && p.osm_id === osmId) return p
if (byName && name && p.name && p.name.trim().toLowerCase() === name) return p
if (
lat != null && lng != null && p.lat != null && p.lng != null &&
Math.abs(Number(p.lat) - lat) <= DUP_COORD_TOLERANCE &&
@@ -114,7 +144,7 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
const {
isOpen, onClose, onSave, place, prefillCoords, tripId, categories,
onCategoryCreated, assignmentId, dayAssignments = [], isMobile = false,
onOpenExpense,
onOpenExpense, serviceStop = null,
} = props
// Hidden while the addon is off, because the kinds only mean anything to the road trip
// rail: on an instance without it they would be six labels that change nothing.
@@ -143,6 +173,12 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
// user's and survives. See mergeResult.
const autoFilledRef = useRef<Set<ResultField>>(new Set())
const [pendingFiles, setPendingFiles] = useState([])
/**
* The leg of the drive the traveller picked, or empty while the projection's own
* answer stands. Empty rather than seeded, because there is nothing to project onto
* until a place has been chosen and the answer has to follow the coordinates.
*/
const [serviceStopLeg, setServiceStopLeg] = useState('')
const fileRef = useRef(null)
const searchInputRef = useRef<HTMLInputElement>(null)
const [acSuggestions, setAcSuggestions] = useState<Suggestion[]>([])
@@ -211,6 +247,18 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
stop_type: prefillCoords.stop_type ?? null,
duration_minutes: prefillCoords.duration_minutes,
})
} else if (serviceStop) {
// A stop on a drive is a kind and a dwell before it is anything else, so the form
// opens on one rather than on nothing: a service stop left without a kind is a
// numbered destination that counts in every total, which is the very thing this
// path exists to avoid. Read out of the closure rather than watched, because the
// mode is fixed for the life of one opening and a rebuilt drive must not reset a
// half-filled form.
setForm({
...DEFAULT_FORM,
stop_type: DEFAULT_SERVICE_KIND,
duration_minutes: STOP_KIND_BY_KEY[DEFAULT_SERVICE_KIND].defaultMinutes,
})
} else {
setForm(DEFAULT_FORM)
}
@@ -227,7 +275,14 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
: [],
)
setPendingFiles([])
setServiceStopLeg('')
setDuplicateWarning(null)
// A fresh dialog owns no intention either. The ref is armed by a click on the Costs
// section and spent by the save that follows it; a save that never happened leaves it
// armed, and the next opening would consume it for a place nobody linked an expense
// to. In service-stop mode that opening has no Costs section at all, so the editor
// would arrive out of nowhere, on a petrol stop, filed as an activity.
expenseIntentRef.current = null
// The column follows whatever the dialog was opened with, not only a search
// pick: a POI tapped on the map and a right-click place arrive as
// prefillCoords, and editing an existing place arrives as `place`. Without
@@ -272,6 +327,19 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
// search wants a point; useLocationBias derives both from the same places.
const { box: locationBias, point: locationBiasPoint } = useLocationBias()
/**
* What a stop on a drive might be a second copy of, said while the form is being filled.
*
* By the map record and by where it stands, never by its name: two Arals on one
* motorway are two petrol stations, and a check that called them one refused the save
* the first time it was pressed. This one refuses nothing: it is a note beside the
* name, and the reader decides.
*/
const serviceStopDuplicate = useMemo(() => {
if (!serviceStop || place) return null
return findDuplicatePlace(form, places, { byName: false, byOsmId: true })?.name ?? null
}, [serviceStop, place, form, places])
// Autocomplete fetch — aborts any in-flight request before starting a new one
const fetchSuggestions = useCallback(async (query: string) => {
if (query.length < 2 || isMapUrl(query)) {
@@ -494,6 +562,21 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
}
}
/**
* The kind of stop, and with it how long that kind usually takes.
*
* Picking a kind is also picking a dwell, until the user says otherwise: a charge is
* not a fuel stop. Only ever called for a kind that is not already on, so a dwell set
* by hand survives a second click on the same pill.
*/
const handleStopKind = useCallback((kind: RoadtripStopType) => {
setForm(prev => ({ ...prev, stop_type: kind, duration_minutes: STOP_KIND_BY_KEY[kind].defaultMinutes }))
}, [])
const handleStopMinutes = useCallback((minutes: number) => {
setForm(prev => ({ ...prev, duration_minutes: minutes }))
}, [])
const handleCreateCategory = async () => {
if (!newCategoryName.trim()) return
try {
@@ -544,21 +627,34 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
}
// #1152: only for new places, and only on the first attempt — a second click
// (with the warning already showing) is the explicit "add anyway" confirmation.
if (!place && !duplicateWarning) {
//
// Never for a stop on a drive. Most of what that check catches is a repeated name,
// and on a motorway a repeated name is the normal case: the second Aral is four
// hundred kilometres from the first and is a different petrol station. The popup this
// path replaced compared the OSM object for exactly that reason and never gated the
// save on it, only noted it. So the note is shown beside the name while the form is
// being filled (see serviceStopDuplicate), which is the earlier word anyway, and the
// press that saves is the press that saves.
if (!place && !serviceStop && !duplicateWarning) {
const dup = findDuplicatePlace(form, places)
if (dup) {
const dupName = dup.name || form.name
setDuplicateWarning(dupName)
toast.warning(t('places.duplicateExists', { name: dupName }))
// Nothing was saved, so an expense intent from a previous click is stale, and
// the next plain Save would otherwise open a Costs editor out of nowhere.
expenseIntentRef.current = null
return
}
}
setIsSaving(true)
try {
const lat = form.lat ? Number.parseFloat(form.lat) : null
const lng = form.lng ? Number.parseFloat(form.lng) : null
const payload = {
...form,
lat: form.lat ? Number.parseFloat(form.lat) : null,
lng: form.lng ? Number.parseFloat(form.lng) : null,
lat,
lng,
category_id: form.category_id || null,
// An explicit null is how a stop stops being a fuel stop; the service reads it
// that way rather than as "leave alone", which is what a missing key means.
@@ -569,6 +665,12 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
...(!place && form.stop_type && form.duration_minutes
? { duration_minutes: form.duration_minutes }
: {}),
// Where on the drive it goes, worked out HERE and not when the dialog opened: a
// stop added by hand has no coordinates at all until a place has been chosen in
// it, so the answer has to follow what is actually being saved.
...(serviceStop
? { _serviceStop: serviceStopChoice(serviceStop, lat, lng, serviceStopLeg).placement }
: {}),
_pendingFiles: pendingFiles.length > 0 ? pendingFiles : undefined,
}
// #2163: the per-assignment note only travels when an assignment is in
@@ -592,6 +694,10 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
}
onClose()
} catch (err: unknown) {
// The save did not happen, so the intent behind it cannot be honoured: the place
// the expense would point at does not exist. Left armed it would ride along to
// whatever the next press saves.
expenseIntentRef.current = null
toast.error(err instanceof Error ? err.message : t('places.saveError'))
} finally {
setIsSaving(false)
@@ -673,6 +779,12 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
handleCreateExpense,
handleEditExpense,
handleRemoveExpense,
serviceStop,
serviceStopDuplicate,
serviceStopLeg,
setServiceStopLeg,
handleStopKind,
handleStopMinutes,
}
}
@@ -745,6 +857,12 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
handleCreateExpense,
handleEditExpense,
handleRemoveExpense,
serviceStop,
serviceStopDuplicate,
serviceStopLeg,
setServiceStopLeg,
handleStopKind,
handleStopMinutes,
} = S
// Desktop + Collections addon → the saved-place picker on the right. Mobile
// always keeps the original single-column form untouched.
@@ -760,7 +878,9 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
<Modal
isOpen={isOpen}
onClose={onClose}
title={place ? t('places.editPlace') : t('places.addPlace')}
// A stop on a drive is not an activity, and the title is the first thing that says
// which of the two this dialog is asking about.
title={place ? t('places.editPlace') : serviceStop ? t('roadtrip.stop.addTitle') : t('places.addPlace')}
size={modalSize}
footer={
<div className="flex justify-end gap-3">
@@ -895,6 +1015,14 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
</div>
)}
</div>
{/* A stop on a drive that looks like one already on the trip. Said here, while
the form is being filled, and never as a condition of saving: the press that
saves is the press that saves. */}
{serviceStopDuplicate && (
<p className="mt-1 text-caption text-warning">
{t('roadtrip.stop.duplicate', { name: serviceStopDuplicate })}
</p>
)}
</div>
{/* Description */}
@@ -968,7 +1096,24 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
</div>
</div>
{/* Category */}
{/* Category, or for a stop on a drive the kind of stop and where it belongs.
One or the other, never both: refuelling is not a taste, it is a fact about
the place, so it lives in `places.stop_type` and not in the trip's own
editable category list. */}
{serviceStop ? (
<ServiceStopSection
mode={serviceStop}
stopType={form.stop_type ?? null}
onStopType={handleStopKind}
minutes={form.duration_minutes ?? 0}
onMinutes={handleStopMinutes}
leg={serviceStopLeg}
onLeg={setServiceStopLeg}
lat={form.lat ? Number.parseFloat(form.lat) : null}
lng={form.lng ? Number.parseFloat(form.lng) : null}
/>
) : (
<div>
<label className="block text-sm font-medium text-content-secondary mb-1">{t('places.formCategory')}</label>
{!showNewCategory ? (
@@ -1018,6 +1163,7 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
</div>
)}
</div>
)}
{/* Time is per day-assignment: only shown when a single assignment is in
context (itinerary edit, or a single-assignment pool edit). Hidden when
@@ -1089,8 +1235,11 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
)}
{/* Costs — create / view the expense linked to this place (#1298).
Same block, same flow as a booking: save first, then the editor. */}
{isBudgetEnabled && (
Same block, same flow as a booking: save first, then the editor.
Never for a stop on a drive: a petrol stop is not an activity with a budget
line, and the fuel it buys is an expense of the trip rather than of a place. */}
{isBudgetEnabled && !serviceStop && (
<BookingCostsSection
placeId={place?.id ?? null}
reservationId={null}