fix(ci): repair trip assistant checks

Fix the mobile dashboard import and align the assistant UI with client layer and lint rules. Document the OpenRouter setting, share the reservation status schema, and update coverage for external POI identifiers and the empty costs view.
This commit is contained in:
Maurice
2026-12-02 22:56:54 +01:00
parent 62a3e63f3f
commit 86e98fde65
18 changed files with 635 additions and 514 deletions
+389 -330
View File
@@ -64,42 +64,18 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
isOpen,
onClose,
place,
prefillCoords,
categories,
isMobile,
collectionsEnabled,
form,
mapsSearch,
setMapsSearch,
mapsResults,
isSearchingMaps,
acSuggestions,
setAcSuggestions,
acSource,
searchSource,
acHighlight,
setAcHighlight,
t,
language,
googleAnswers,
placesEnrichEnabled,
canUploadFiles,
fetchSuggestions,
sourceLabel,
handleChange,
handleMapsSearch,
handleSelectMapsResult,
handleNearby,
pin,
nearbyList,
distanceUnit,
handleSelectSuggestion,
handleSearchKeyDown,
hasTimeError,
handleSubmit,
isSaving,
duplicateWarning,
detailsSelection,
serviceStop,
serviceStopDuplicate,
} = S;
@@ -278,313 +254,396 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
{assignmentOnly ? (
schedule
) : (
<div className={inRow ? ROW : STACK}>
{showDetails && (
<PlaceDetailsColumn
selection={detailsSelection}
selectedImageUrl={form.image_url}
onPickImage={S.pickImage}
image={S.image}
onAdoptDescription={S.adoptDescription}
onHours={(hours) => S.setDetailsHours(weekFromPeriods(hours.periods))}
hasDescription={!!form.description.trim()}
language={language}
timeFormat={S.timeFormat}
locale={S.locale}
variant="dialog"
// Stacked above the form in a narrow window, it takes the form's width.
fluid={isMobile}
t={t}
/>
)}
<form onSubmit={handleSubmit} className={FORM_COLUMN}>
{/* Place search: typed-ahead suggestions, a full search, and a pasted map link. */}
<div className={PANEL}>
<EditorField label={t('common.search')} htmlFor={`${fieldId}-search`}>
<div className="relative">
<div className="flex items-stretch gap-2">
<input
id={`${fieldId}-search`}
type="text"
// A new place starts at the search; an edit or a place brought
// in from the map already has what the search would give.
ref={!place && !prefillCoords ? focusRevealedEditor : undefined}
value={mapsSearch}
onChange={(e) => {
setMapsSearch(e.target.value);
S.setEmptySearch(null);
}}
onKeyDown={handleSearchKeyDown}
onBlur={() => setTimeout(() => setAcSuggestions([]), 150)}
onFocus={() => {
if (mapsSearch.trim().length >= 2 && acSuggestions.length === 0 && mapsResults.length === 0) {
fetchSuggestions(mapsSearch.trim());
}
}}
placeholder={t('places.mapsSearchPlaceholder')}
className={`${INPUT} flex-1`}
/>
<Tooltip label={t('common.search')}>
<button
type="button"
onClick={() => {
setAcSuggestions([]);
void handleMapsSearch();
}}
disabled={isSearchingMaps}
aria-label={t('common.search')}
className={`${SIDE_BUTTON} bg-accent text-accent-text hover:opacity-90`}
style={fs(13, 'body')}
>
{isSearchingMaps ? '...' : <Search size={15} strokeWidth={2.2} aria-hidden="true" />}
</button>
</Tooltip>
{pin && (
<Tooltip label={t('places.nearby')}>
<button
type="button"
onClick={handleNearby}
disabled={isSearchingMaps}
aria-label={t('places.nearby')}
className={`${SIDE_BUTTON} border border-edge bg-surface-card text-content-secondary hover:bg-surface-hover`}
>
<LocateFixed size={15} strokeWidth={2.2} aria-hidden="true" />
</button>
</Tooltip>
)}
</div>
{/* Autocomplete dropdown. Capped and scrolling, because plugin rows can
follow the core ones (#2221) and the list must stay inside the dialog;
the row the arrow keys land on is scrolled into view. */}
{acSuggestions.length > 0 && (
<div className="absolute inset-x-0 z-20 mt-1 max-h-96 overflow-y-auto rounded-[12px] border border-edge-faint bg-surface-card p-1 shadow-dropdown">
{acSuggestions.map((s, idx) => (
<button
key={s.placeId}
ref={idx === acHighlight ? (el) => el?.scrollIntoView?.({ block: 'nearest' }) : undefined}
type="button"
onMouseDown={() => handleSelectSuggestion(s)}
onMouseEnter={() => setAcHighlight(idx)}
className={`${PICK_ROW} ${idx === acHighlight ? 'bg-surface-tertiary' : 'hover:bg-surface-hover'}`}
>
<span className="min-w-0 flex-1">
<span className="block truncate font-medium text-content" style={fs(13, 'body')}>
{s.mainText}
</span>
{s.secondaryText && (
<span className="block truncate text-content-muted" style={fs(11.5)}>
{s.secondaryText}
</span>
)}
</span>
<SourceBadge label={sourceLabel(s, acSource)} />
</button>
))}
</div>
)}
</div>
</EditorField>
{/* Nothing found (#2472): say so, and offer the hand-made way in, taking
the query as the name when there is none yet. */}
{S.emptySearch && mapsResults.length === 0 && !isSearchingMaps && (
<div className="flex items-center gap-3 rounded-[12px] border border-dashed border-edge bg-surface-card px-3 py-2.5">
<span className="grid h-8 w-8 flex-none place-items-center rounded-full bg-surface-tertiary text-content-muted">
<PencilLine size={15} strokeWidth={2} />
</span>
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(12.5, 'body')}>
{t('places.searchNothing', { query: S.emptySearch })}
</span>
<span className="block text-content-muted" style={fs(11.5)}>
{t('places.searchNothingHint')}
</span>
</span>
<button
type="button"
onClick={() => {
if (!form.name.trim()) handleChange('name', S.emptySearch!);
S.setEmptySearch(null);
document
.getElementById(`${fieldId}-contact`)
?.scrollIntoView?.({ behavior: 'smooth', block: 'center' });
}}
className="flex-none rounded-full bg-accent px-3 py-1.5 font-semibold text-accent-text hover:opacity-90"
style={fs(12, 'body')}
>
{t('places.addByHand')}
</button>
</div>
)}
{/* Search results (populated after full search) */}
{mapsResults.length > 0 && (
<div className="max-h-40 overflow-y-auto rounded-[10px] border border-edge-faint bg-surface-card p-1">
{mapsResults.map((result, idx) => (
<button
key={idx}
type="button"
onClick={() =>
handleSelectMapsResult(result, { mode: 'search', rank: idx, count: mapsResults.length })
}
className={`${PICK_ROW} hover:bg-surface-hover`}
>
<span className="min-w-0 flex-1">
<span className="block truncate font-medium text-content" style={fs(13, 'body')}>
{result.name}
</span>
{result.address && (
<span className="block truncate text-content-muted" style={fs(11.5)}>
{result.address}
</span>
)}
</span>
{nearbyList && typeof result.distance_m === 'number' && (
<SoftPill>{formatDistance(result.distance_m / 1000, distanceUnit)}</SoftPill>
)}
<SourceBadge label={sourceLabel(result, searchSource)} />
</button>
))}
</div>
)}
{/* The index answers first and Google only when it finds nothing, so a
list with the wrong place on it never reaches Google by itself. One
quiet line under the list sends the same query there, on an instance
where Google holds the key slot and for a list Google did not
already produce. */}
{mapsResults.length > 0 && !nearbyList && offersGoogleRetry(searchSource, googleAnswers) && (
<button
type="button"
onClick={() => handleMapsSearch('google')}
disabled={isSearchingMaps}
className="inline-flex items-center gap-1 self-start text-content-faint transition-colors hover:text-content disabled:opacity-50"
style={fs(12)}
>
<RotateCcw size={11} strokeWidth={2} aria-hidden="true" />
{t('places.searchGoogleInstead')}
</button>
)}
</div>
<PlaceFormLocation
fieldId={fieldId}
form={form}
onChange={handleChange}
warnWithoutCoordinates={!serviceStop}
/>
{/* For a stop on a drive: the kind of stop, how long, and where it belongs.
The category it replaces is gone from the head band too: 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 && (
<div className={`${PANEL} ${SERVICE_STOP_LABELS}`}>
<ServiceStopSection
mode={serviceStop}
stopType={form.stop_type ?? null}
onStopType={S.handleStopKind}
minutes={form.duration_minutes ?? 0}
onMinutes={S.handleStopMinutes}
leg={S.serviceStopLeg}
onLeg={S.setServiceStopLeg}
lat={form.lat ? Number.parseFloat(form.lat) : null}
lng={form.lng ? Number.parseFloat(form.lng) : null}
/>
</div>
)}
{/* Extra labels next to the one category, to filter the places by. Not for a
stop on a drive, which is not an activity anyone looks up by its tags. */}
{!serviceStop && <PlaceFormTags tags={S.tagField} t={t} manage={!proposal} />}
{/* The day in context: its times. They live on the day-assignment, not on
the pool place (#2163), so they are only shown when a single assignment
is in context (itinerary edit, or a single-assignment pool edit). Hidden
when creating, and for unassigned or multi-day pool edits where a single
time is ambiguous and would not persist. */}
{schedule}
{/* Description, notes and the note for this day, one at a time. The day
note follows the times: only with a single assignment in context. */}
<PlaceFormTexts
fieldId={fieldId}
description={form.description}
notes={form.notes}
dayNotes={proposal || (place && S.assignmentId) ? (form.assignment_notes ?? '') : null}
dayNumber={S.dayNumber}
initialTab={proposal ? 'assignment_notes' : undefined}
onChange={(field, value) => handleChange(field, value)}
t={t}
/>
{!showDetails && (
<div className={PANEL}>
<PlaceImageSection image={S.image} onPickUrl={S.pickImage} t={t} />
</div>
)}
{/* Link, files and how to reach the place, in one card. */}
<div className={PANEL}>
{/* The link and the files side by side, as on a booking. */}
<div className={canUploadFiles ? GRID_2 : ''}>
<EditorField label={t('places.formWebsite')} htmlFor={`${fieldId}-website`}>
<input
id={`${fieldId}-website`}
type="url"
value={form.website}
onChange={(e) => handleChange('website', e.target.value)}
placeholder="https://..."
className={INPUT}
/>
</EditorField>
{canUploadFiles && (
<PendingFiles
files={S.pendingFiles}
fileRef={S.fileRef}
onAdd={S.handleFileAdd}
onRemove={S.handleRemoveFile}
t={t}
/>
)}
</div>
{/* Phone, e-mail and the place's own hours, for what the search did not
know or a place nobody has listed (#2472). */}
<PlaceContactFields
id={`${fieldId}-contact`}
phone={form.phone ?? ''}
email={form.email ?? ''}
openingHours={form.opening_hours ?? ''}
suggestedHours={S.detailsHours}
onChange={(field, value, origin) => handleChange(field, value, origin)}
/>
</div>
{/* Costs — create / view the expense linked to this place (#1298).
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. */}
{S.isBudgetEnabled && !serviceStop && !proposal && (
<div className={PANEL}>
<BookingCostsSection
placeId={place?.id ?? null}
reservationId={null}
hintKey="places.createExpenseHint"
onCreate={S.handleCreateExpense}
onEdit={S.handleEditExpense}
onRemove={S.handleRemoveExpense}
labelClassName={LABEL}
customTooltips
whiteButtons
/>
</div>
)}
</form>
{twoColumn && <CollectionPicker bias={S.locationBias} onSelect={handleSelectMapsResult} t={t} />}
</div>
<PlaceFormColumns
state={S}
fieldId={fieldId}
proposal={!!proposal}
schedule={schedule}
className={inRow ? ROW : STACK}
showDetails={showDetails}
twoColumn={twoColumn}
/>
)}
</DialogShell>
);
}
type PlaceFormState = ReturnType<typeof usePlaceFormModal>;
function PlaceFormColumns({
state: S,
fieldId,
proposal,
schedule,
className,
showDetails,
twoColumn,
}: {
state: PlaceFormState;
fieldId: string;
proposal: boolean;
schedule: ReactNode;
className: string;
showDetails: boolean;
twoColumn: boolean;
}) {
const {
form,
place,
isMobile,
detailsSelection,
language,
t,
handleSubmit,
handleChange,
serviceStop,
handleSelectMapsResult,
} = S;
return (
<div className={className}>
{showDetails && (
<PlaceDetailsColumn
selection={detailsSelection}
selectedImageUrl={form.image_url}
onPickImage={S.pickImage}
image={S.image}
onAdoptDescription={S.adoptDescription}
onHours={(hours) => S.setDetailsHours(weekFromPeriods(hours.periods))}
hasDescription={!!form.description.trim()}
language={language}
timeFormat={S.timeFormat}
locale={S.locale}
variant="dialog"
// Stacked above the form in a narrow window, it takes the form's width.
fluid={isMobile}
t={t}
/>
)}
<form onSubmit={handleSubmit} className={FORM_COLUMN}>
<PlaceSearchFields state={S} fieldId={fieldId} />
<PlaceFormLocation
fieldId={fieldId}
form={form}
onChange={handleChange}
warnWithoutCoordinates={!serviceStop}
/>
{/* For a stop on a drive: the kind of stop, how long, and where it belongs.
The category it replaces is gone from the head band too: 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 && (
<div className={`${PANEL} ${SERVICE_STOP_LABELS}`}>
<ServiceStopSection
mode={serviceStop}
stopType={form.stop_type ?? null}
onStopType={S.handleStopKind}
minutes={form.duration_minutes ?? 0}
onMinutes={S.handleStopMinutes}
leg={S.serviceStopLeg}
onLeg={S.setServiceStopLeg}
lat={form.lat ? Number.parseFloat(form.lat) : null}
lng={form.lng ? Number.parseFloat(form.lng) : null}
/>
</div>
)}
{/* Extra labels next to the one category, to filter the places by. Not for a
stop on a drive, which is not an activity anyone looks up by its tags. */}
{!serviceStop && <PlaceFormTags tags={S.tagField} t={t} manage={!proposal} />}
{/* The day in context: its times. They live on the day-assignment, not on
the pool place (#2163), so they are only shown when a single assignment
is in context (itinerary edit, or a single-assignment pool edit). Hidden
when creating, and for unassigned or multi-day pool edits where a single
time is ambiguous and would not persist. */}
{schedule}
{/* Description, notes and the note for this day, one at a time. The day
note follows the times: only with a single assignment in context. */}
<PlaceFormTexts
fieldId={fieldId}
description={form.description}
notes={form.notes}
dayNotes={proposal || (place && S.assignmentId) ? (form.assignment_notes ?? '') : null}
dayNumber={S.dayNumber}
initialTab={proposal ? 'assignment_notes' : undefined}
onChange={(field, value) => handleChange(field, value)}
t={t}
/>
{!showDetails && (
<div className={PANEL}>
<PlaceImageSection image={S.image} onPickUrl={S.pickImage} t={t} />
</div>
)}
<PlaceContactAndFiles state={S} fieldId={fieldId} />
{/* Costs — create / view the expense linked to this place (#1298).
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. */}
{S.isBudgetEnabled && !serviceStop && !proposal && (
<div className={PANEL}>
<BookingCostsSection
placeId={place?.id ?? null}
reservationId={null}
hintKey="places.createExpenseHint"
onCreate={S.handleCreateExpense}
onEdit={S.handleEditExpense}
onRemove={S.handleRemoveExpense}
labelClassName={LABEL}
customTooltips
whiteButtons
/>
</div>
)}
</form>
{twoColumn && <CollectionPicker bias={S.locationBias} onSelect={handleSelectMapsResult} t={t} />}
</div>
);
}
function PlaceSearchFields({ state: S, fieldId }: { state: PlaceFormState; fieldId: string }) {
const {
t,
place,
prefillCoords,
form,
mapsSearch,
setMapsSearch,
isSearchingMaps,
mapsResults,
acSuggestions,
setAcSuggestions,
acHighlight,
setAcHighlight,
acSource,
searchSource,
googleAnswers,
pin,
nearbyList,
distanceUnit,
fetchSuggestions,
sourceLabel,
handleChange,
handleMapsSearch,
handleNearby,
handleSelectMapsResult,
handleSelectSuggestion,
handleSearchKeyDown,
} = S;
return (
<div className={PANEL}>
<EditorField label={t('common.search')} htmlFor={`${fieldId}-search`}>
<div className="relative">
<div className="flex items-stretch gap-2">
<input
id={`${fieldId}-search`}
type="text"
// A new place starts at the search; an edit or a place brought
// in from the map already has what the search would give.
ref={!place && !prefillCoords ? focusRevealedEditor : undefined}
value={mapsSearch}
onChange={(e) => {
setMapsSearch(e.target.value);
S.setEmptySearch(null);
}}
onKeyDown={handleSearchKeyDown}
onBlur={() => setTimeout(() => setAcSuggestions([]), 150)}
onFocus={() => {
if (mapsSearch.trim().length >= 2 && acSuggestions.length === 0 && mapsResults.length === 0) {
fetchSuggestions(mapsSearch.trim());
}
}}
placeholder={t('places.mapsSearchPlaceholder')}
className={`${INPUT} flex-1`}
/>
<Tooltip label={t('common.search')}>
<button
type="button"
onClick={() => {
setAcSuggestions([]);
void handleMapsSearch();
}}
disabled={isSearchingMaps}
aria-label={t('common.search')}
className={`${SIDE_BUTTON} bg-accent text-accent-text hover:opacity-90`}
style={fs(13, 'body')}
>
{isSearchingMaps ? '...' : <Search size={15} strokeWidth={2.2} aria-hidden="true" />}
</button>
</Tooltip>
{pin && (
<Tooltip label={t('places.nearby')}>
<button
type="button"
onClick={handleNearby}
disabled={isSearchingMaps}
aria-label={t('places.nearby')}
className={`${SIDE_BUTTON} border border-edge bg-surface-card text-content-secondary hover:bg-surface-hover`}
>
<LocateFixed size={15} strokeWidth={2.2} aria-hidden="true" />
</button>
</Tooltip>
)}
</div>
{/* Autocomplete dropdown. Capped and scrolling, because plugin rows can
follow the core ones (#2221) and the list must stay inside the dialog;
the row the arrow keys land on is scrolled into view. */}
{acSuggestions.length > 0 && (
<div className="absolute inset-x-0 z-20 mt-1 max-h-96 overflow-y-auto rounded-[12px] border border-edge-faint bg-surface-card p-1 shadow-dropdown">
{acSuggestions.map((s, idx) => (
<button
key={s.placeId}
ref={idx === acHighlight ? (el) => el?.scrollIntoView?.({ block: 'nearest' }) : undefined}
type="button"
onMouseDown={() => handleSelectSuggestion(s)}
onMouseEnter={() => setAcHighlight(idx)}
className={`${PICK_ROW} ${idx === acHighlight ? 'bg-surface-tertiary' : 'hover:bg-surface-hover'}`}
>
<span className="min-w-0 flex-1">
<span className="block truncate font-medium text-content" style={fs(13, 'body')}>
{s.mainText}
</span>
{s.secondaryText && (
<span className="block truncate text-content-muted" style={fs(11.5)}>
{s.secondaryText}
</span>
)}
</span>
<SourceBadge label={sourceLabel(s, acSource)} />
</button>
))}
</div>
)}
</div>
</EditorField>
{/* Nothing found (#2472): say so, and offer the hand-made way in, taking
the query as the name when there is none yet. */}
{S.emptySearch && mapsResults.length === 0 && !isSearchingMaps && (
<div className="flex items-center gap-3 rounded-[12px] border border-dashed border-edge bg-surface-card px-3 py-2.5">
<span className="grid h-8 w-8 flex-none place-items-center rounded-full bg-surface-tertiary text-content-muted">
<PencilLine size={15} strokeWidth={2} />
</span>
<span className="min-w-0 flex-1">
<span className="block truncate font-semibold text-content" style={fs(12.5, 'body')}>
{t('places.searchNothing', { query: S.emptySearch })}
</span>
<span className="block text-content-muted" style={fs(11.5)}>
{t('places.searchNothingHint')}
</span>
</span>
<button
type="button"
onClick={() => {
if (!form.name.trim()) handleChange('name', S.emptySearch!);
S.setEmptySearch(null);
document
.getElementById(`${fieldId}-contact`)
?.scrollIntoView?.({ behavior: 'smooth', block: 'center' });
}}
className="flex-none rounded-full bg-accent px-3 py-1.5 font-semibold text-accent-text hover:opacity-90"
style={fs(12, 'body')}
>
{t('places.addByHand')}
</button>
</div>
)}
{/* Search results (populated after full search) */}
{mapsResults.length > 0 && (
<div className="max-h-40 overflow-y-auto rounded-[10px] border border-edge-faint bg-surface-card p-1">
{mapsResults.map((result, idx) => (
<button
key={idx}
type="button"
onClick={() =>
handleSelectMapsResult(result, { mode: 'search', rank: idx, count: mapsResults.length })
}
className={`${PICK_ROW} hover:bg-surface-hover`}
>
<span className="min-w-0 flex-1">
<span className="block truncate font-medium text-content" style={fs(13, 'body')}>
{result.name}
</span>
{result.address && (
<span className="block truncate text-content-muted" style={fs(11.5)}>
{result.address}
</span>
)}
</span>
{nearbyList && typeof result.distance_m === 'number' && (
<SoftPill>{formatDistance(result.distance_m / 1000, distanceUnit)}</SoftPill>
)}
<SourceBadge label={sourceLabel(result, searchSource)} />
</button>
))}
</div>
)}
{/* The index answers first and Google only when it finds nothing, so a
list with the wrong place on it never reaches Google by itself. One
quiet line under the list sends the same query there, on an instance
where Google holds the key slot and for a list Google did not
already produce. */}
{mapsResults.length > 0 && !nearbyList && offersGoogleRetry(searchSource, googleAnswers) && (
<button
type="button"
onClick={() => handleMapsSearch('google')}
disabled={isSearchingMaps}
className="inline-flex items-center gap-1 self-start text-content-faint transition-colors hover:text-content disabled:opacity-50"
style={fs(12)}
>
<RotateCcw size={11} strokeWidth={2} aria-hidden="true" />
{t('places.searchGoogleInstead')}
</button>
)}
</div>
);
}
function PlaceContactAndFiles({ state: S, fieldId }: { state: PlaceFormState; fieldId: string }) {
const { canUploadFiles, form, handleChange, t } = S;
return (
<div className={PANEL}>
{/* The link and the files side by side, as on a booking. */}
<div className={canUploadFiles ? GRID_2 : ''}>
<EditorField label={t('places.formWebsite')} htmlFor={`${fieldId}-website`}>
<input
id={`${fieldId}-website`}
type="url"
value={form.website}
onChange={(e) => handleChange('website', e.target.value)}
placeholder="https://..."
className={INPUT}
/>
</EditorField>
{canUploadFiles && (
<PendingFiles
files={S.pendingFiles}
fileRef={S.fileRef}
onAdd={S.handleFileAdd}
onRemove={S.handleRemoveFile}
t={t}
/>
)}
</div>
{/* Phone, e-mail and the place's own hours, for what the search did not
know or a place nobody has listed (#2472). */}
<PlaceContactFields
id={`${fieldId}-contact`}
phone={form.phone ?? ''}
email={form.email ?? ''}
openingHours={form.opening_hours ?? ''}
suggestedHours={S.detailsHours}
onChange={(field, value, origin) => handleChange(field, value, origin)}
/>
</div>
);
}