fix(planner): places put on a day, day names, day notes and trip details changed offline wait in the queue and sync once the connection is back

The day plan wrote straight to the API, so offline a place dropped on a day
snapped back with "Error assigning place", a renamed day or a new day note
failed, and a moved stop, a leg's travel mode or who joins a visit were lost.
Visits (put on a day, taken off, reordered, moved, travellers, leg mode), the
day's name, notes text and travel mode, and the day notes (add, edit, delete,
move) now go through assignmentRepo, dayRepo and dayNoteRepo and the mutation
queue: the cached day changes at once, a visit or note made offline gets a
temporary id that the edits after it wait for, and an online write held behind
an older queued one joins the queue, since none of these carry a version
token. A new order of a day that names a visit made offline is sent with its
real id, or without it when its create failed. Desktop, the phone timeline and
note sheet all write through the store, so both are covered.

The replay reads each answer for what it names: the day answer keeps the
cached notes and visits, the participants answer lands on its visit, and a
visit the server refuses with 409 (a Tour already on that day) fails instead
of waiting as a conflict no retry can solve.

The trip's name, description, reminder and the archive flag wait in the queue
too, from the planner, the phone and the dashboard. What only the server can
do says so instead of failing: new dates, a day count, a currency or a cover,
a new trip, a copy or a delete, members, guests, share and invite links, and
a new order of the days, which moves the dates of the bookings.

Refs #2601
This commit is contained in:
Maurice
2026-10-12 20:17:57 +02:00
parent 92c48fba22
commit bdd8c08dd4
85 changed files with 1557 additions and 88 deletions
@@ -4223,12 +4223,10 @@ describe('DayPlanSidebar', () => {
expect(useTripStore.getState().days[0].default_transport_mode).toBe('walking')
})
it('FE-PLANNER-DAYPLAN-170: a failing day-mode save is reported and the days are refetched', async () => {
it('FE-PLANNER-DAYPLAN-170: a failing day-mode save is reported and the day gets its old mode back', async () => {
const user = userEvent.setup()
const { daysApi } = await import('../../api/client')
vi.mocked(daysApi.updateTransport).mockRejectedValueOnce(new Error('offline'))
const refreshDays = vi.fn(async () => undefined)
stubTripActions({ refreshDays })
const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
const assignments = {
'10': [
@@ -4236,10 +4234,11 @@ describe('DayPlanSidebar', () => {
buildAssignment({ id: 12, day_id: 10, order_index: 1, place: buildPlace({ id: 2, name: 'B', lat: 48.86, lng: 2.36 }) }),
],
}
seedStore(useTripStore, { days: [day] })
render(<DayPlanSidebar {...makeDefaultProps({ days: [day], assignments, selectedDayId: 10 })} />)
await user.click(screen.getByRole('button', { name: 'Walking' }))
await waitFor(() => expect(mockToast.error).toHaveBeenCalledWith('offline'))
expect(refreshDays).toHaveBeenCalledWith(1)
expect(useTripStore.getState().days[0].default_transport_mode).toBeFalsy()
})
it('FE-PLANNER-DAYPLAN-171: a route connector opens the per-segment travel-mode menu', async () => {
@@ -10,7 +10,6 @@ import { safeHttpUrl } from '../../utils/safeUrl'
import { ChevronDown, ChevronRight, ChevronUp, Compass, RotateCcw, ExternalLink, Pencil, GripVertical, Ticket, Plus, FileText, Trash2, Car, Lock, Hotel, Eraser, Route as RouteIcon, RouteOff, Bookmark, StickyNote, TramFront, Zap, MapPin, Globe } from 'lucide-react'
import { type PickedPlace } from './TransitSearchPanel'
import { buildTransitLeg, buildTransitNameIndex } from './transitLeg'
import { daysApi } from '../../api/client'
import { optimizeRoute, generateGoogleMapsUrl, generateCoMapsUrl } from '../Map/RouteCalculator'
import { dayViaLookup, routeLeg, type LegEnd, type ViasByDay } from '../Map/dayRouteVias'
import GoogleMapsIcon from '../shared/GoogleMapsIcon'
@@ -1392,11 +1391,9 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
// and mirrored into routeProfile so the live map redraws at once. Legs that carry
// their own mode are left untouched.
const setDayDefaultMode = (dayId: number, mode: string) => {
useTripStore.setState(state => ({ days: state.days.map(d => (d.id === dayId ? { ...d, default_transport_mode: mode } : d)) }))
onSetRouteProfile?.(mode)
daysApi.updateTransport(tripId, dayId, mode).catch((err: unknown) => {
tripActions.setDayTransportMode(tripId, dayId, mode).catch((err: unknown) => {
toast.error(err instanceof Error ? err.message : t('common.unknownError'))
void tripActions.refreshDays(tripId)
})
}
@@ -56,10 +56,13 @@ describe('useLegModeActions', () => {
result.current.persistLegMode(11, 'walking');
result.current.persistLegMode(12, null, 'incoming');
});
expect(vi.mocked(assignmentsApi.updateTransport).mock.calls).toEqual([
[3, 11, 'walking'],
[3, 12, null, 'incoming'],
]);
// The repo first asks the queue whether an older write to the leg waits.
await waitFor(() =>
expect(vi.mocked(assignmentsApi.updateTransport).mock.calls).toEqual([
[3, 11, 'walking'],
[3, 12, null, 'incoming'],
])
);
expect(d.toast.error).not.toHaveBeenCalled();
expect(d.tripActions.refreshDays).not.toHaveBeenCalled();
});
@@ -1,7 +1,7 @@
import { type LucideIcon, RotateCcw, TramFront } from 'lucide-react';
import { useCallback } from 'react';
import { assignmentsApi } from '../../api/client';
import { assignmentRepo } from '../../repo/assignmentRepo';
import type { TripStoreState } from '../../store/tripStore';
import { type RouteModeOption, routeModeIcon, useRouteModeOptions } from './routeModes';
@@ -52,10 +52,7 @@ export function useLegModeActions({ tripId, toast, t, tripActions }: LegModeDeps
const persistLegMode = useCallback(
(assignmentId: number, mode: string | null, direction?: 'incoming') => {
const write = direction
? assignmentsApi.updateTransport(tripId, assignmentId, mode, direction)
: assignmentsApi.updateTransport(tripId, assignmentId, mode);
write.catch((err: unknown) => {
assignmentRepo.setLegMode(tripId, assignmentId, mode, direction).catch((err: unknown) => {
toast.error(err instanceof Error ? err.message : t('common.unknownError'));
void tripActions.refreshDays(tripId);
});
@@ -1,6 +1,5 @@
import { type ChangeEvent, useCallback, useRef, useState } from 'react';
import { assignmentsApi } from '../../api/client';
import { translateApiError, useTranslation } from '../../i18n';
import type { TripStoreState } from '../../store/tripStore';
import { useTripStore } from '../../store/tripStore';
@@ -66,15 +65,7 @@ export function placeActions({ tripId, tripActions, toast, t }: PlaceActionDeps)
/** Who joins the assignment; the answer is written back into that day's list. */
const setParticipants = async (assignmentId: number, dayId: number, userIds: number[]) => {
try {
const data = await assignmentsApi.setParticipants(tripId, assignmentId, userIds);
useTripStore.setState((state) => ({
assignments: {
...state.assignments,
[String(dayId)]: (state.assignments[String(dayId)] || []).map((a) =>
a.id === assignmentId ? { ...a, participants: data.participants } : a
),
},
}));
await useTripStore.getState().setAssignmentParticipants(tripId, dayId, assignmentId, userIds);
} catch (err: unknown) {
report(err);
}