mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
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:
@@ -18,6 +18,8 @@ import { useTripRangeGuard, type RangeCheck } from '../../hooks/useTripRangeGuar
|
||||
import type { ShiftMode } from '../../utils/dayImpactLines'
|
||||
import { useTripCoverPicker } from './useTripCoverPicker'
|
||||
import { tripFormError } from './tripFormModel'
|
||||
import { isEffectivelyOffline } from '../../sync/networkMode'
|
||||
import { tripChangeNeedsConnection } from '../../repo/tripRepo'
|
||||
|
||||
type DateShiftMode = ShiftMode
|
||||
type TripPayload = TripCreateRequest & { date_shift_mode?: DateShiftMode }
|
||||
@@ -158,6 +160,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
// Moving the start of a dated trip shifts the whole day grid, so let the user
|
||||
// choose how bookings follow before anything is saved (#1288). End-date-only
|
||||
// changes don't shift days and dateless transitions have nothing to shift.
|
||||
if (refusedOffline(payload)) return
|
||||
const askShift = !!(isEditing && trip?.start_date && trip?.end_date
|
||||
&& payload.start_date && payload.end_date && payload.start_date !== trip.start_date)
|
||||
// And say which days the new range removes, with what is on them, before
|
||||
@@ -171,7 +174,16 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
await performSave(payload)
|
||||
}
|
||||
|
||||
// A new trip, new dates or a new currency are made by the server; a new name
|
||||
// or description waits in the queue offline like any other change.
|
||||
const refusedOffline = (payload: TripPayload): boolean => {
|
||||
if (!isEffectivelyOffline() || (isEditing && !tripChangeNeedsConnection(trip ?? undefined, payload))) return false
|
||||
setError(t(isEditing ? 'dashboard.tripChangeNeedsConnection' : 'common.needsConnection'))
|
||||
return true
|
||||
}
|
||||
|
||||
const performSave = async (payload: TripPayload) => {
|
||||
if (refusedOffline(payload)) return
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const result = await onSave(payload)
|
||||
@@ -526,6 +538,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
className="flex items-center gap-1.5 px-2.5 py-1 rounded-full text-body font-medium bg-surface text-content border border-edge"
|
||||
onClick={async () => {
|
||||
if (m.id === currentUser?.id) return
|
||||
if (isEffectivelyOffline()) { toast.error(t('common.needsConnection')); return }
|
||||
try {
|
||||
await tripsApi.removeMember(trip!.id, m.id)
|
||||
setExistingMembers(prev => prev.filter(x => x.id !== m.id))
|
||||
@@ -560,7 +573,9 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
onChange={async value => {
|
||||
if (isEditing && trip?.id) {
|
||||
const user = allUsers.find(u => u.id === Number(value))
|
||||
if (user) {
|
||||
if (user && isEffectivelyOffline()) {
|
||||
toast.error(t('common.needsConnection'))
|
||||
} else if (user) {
|
||||
try {
|
||||
await tripsApi.addMember(trip.id, user.username)
|
||||
setExistingMembers(prev => [...prev, { id: user.id, username: user.username }])
|
||||
|
||||
Reference in New Issue
Block a user