mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
feat(dayplan): a day can be added with the next date, which extends the trip by one
On a trip with dates the reorder dialog and the days sheet on a phone now offer two ways to add a day: a day without a date at the end as before, or the calendar day after the last date, named on its button, which extends the trip by one day. The new day goes right behind the last dated day, so the days without a date move one place back with their plans, and no existing day or booking changes its date. The server does it in one transaction behind a new dated flag on the day create contract, used by REST, the create_day tool and the plugin RPC alike. It moves the road trip boundaries of the days behind the new one, and announces the day with day:reordered and the grown trip with trip:updated; an insert at a position announces its trip now as well. The next date and the day limit come from one shared rule, so the button never promises a date the server would not give. On the client the add is online only and runs one at a time, so a double click cannot grow the trip by two days. A wiring test that picked the stay question by its position now finds it by its handler, since the delete question sits in front of it.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// FE-UTIL-DAYADD-001 to FE-UTIL-DAYADD-003
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { addIsoDays, MAX_TRIP_DAYS } from '@trek/shared'
|
||||
import { datedDayOption } from './dayAdd'
|
||||
|
||||
const t = (key: string, params?: Record<string, string | number>) =>
|
||||
params ? `${key}|${Object.values(params).join('|')}` : key
|
||||
|
||||
describe('datedDayOption', () => {
|
||||
it('FE-UTIL-DAYADD-001: offers the day after the end date, or after a day dated past it', () => {
|
||||
const trip = { start_date: '2026-10-10', end_date: '2026-10-12' }
|
||||
expect(datedDayOption(trip, [{ date: '2026-10-10' }, { date: '2026-10-12' }, { date: null }], t))
|
||||
.toEqual({ nextDate: '2026-10-13', datedBlocked: null })
|
||||
expect(datedDayOption(trip, [{ date: '2026-10-14' }], t))
|
||||
.toEqual({ nextDate: '2026-10-15', datedBlocked: null })
|
||||
})
|
||||
|
||||
it('FE-UTIL-DAYADD-002: a trip without dates has no dated day to offer', () => {
|
||||
expect(datedDayOption({ start_date: null, end_date: null }, [{ date: null }], t))
|
||||
.toEqual({ nextDate: null, datedBlocked: null })
|
||||
expect(datedDayOption({ start_date: '2026-10-10', end_date: null }, [], t))
|
||||
.toEqual({ nextDate: null, datedBlocked: null })
|
||||
expect(datedDayOption(null, [], t)).toEqual({ nextDate: null, datedBlocked: null })
|
||||
})
|
||||
|
||||
it('FE-UTIL-DAYADD-003: a trip at the day limit names its date but says why it cannot grow', () => {
|
||||
const start = '2026-01-01'
|
||||
const end = addIsoDays(start, MAX_TRIP_DAYS - 1)
|
||||
expect(datedDayOption({ start_date: start, end_date: end }, [], t)).toEqual({
|
||||
nextDate: addIsoDays(end, 1),
|
||||
datedBlocked: `dashboard.tripTooLong|${MAX_TRIP_DAYS}`,
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import { MAX_TRIP_DAYS, planDatedAppend } from '@trek/shared'
|
||||
import type { Day, Trip } from '../types'
|
||||
|
||||
type Translate = (key: string, params?: Record<string, string | number>) => string
|
||||
|
||||
/**
|
||||
* What the reorder dialog and the phone's day sheet need to offer adding a day:
|
||||
* one button for a day without a date, and on a trip with dates a second one for
|
||||
* the next calendar day. The planner computes it once for both shells.
|
||||
*/
|
||||
export interface DayAddControls {
|
||||
/** The date "Add with date" gives the new day (ISO), or null on a trip without dates, which keeps the single button. */
|
||||
nextDate: string | null
|
||||
/** Why no day can be added right now (no connection), or null. */
|
||||
blocked: string | null
|
||||
/** Why the dated day in particular cannot be added (the trip is at the day limit), or null. */
|
||||
datedBlocked: string | null
|
||||
/** A day is on its way; both buttons wait for it, so a double click adds one day, not two. */
|
||||
busy: boolean
|
||||
onAddDated: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* The dated half of adding a day: the date the new day would get, and the reason
|
||||
* it cannot be added when the trip is already at the day limit. The rule is the
|
||||
* server's own (planDatedAppend), so the button never promises a date the server
|
||||
* would not give, and never offers a day the server would refuse.
|
||||
*/
|
||||
export function datedDayOption(
|
||||
trip: Pick<Trip, 'start_date' | 'end_date'> | null | undefined,
|
||||
days: readonly Pick<Day, 'date'>[],
|
||||
t: Translate,
|
||||
): Pick<DayAddControls, 'nextDate' | 'datedBlocked'> {
|
||||
const plan = trip ? planDatedAppend(trip, days.map(d => d.date)) : null
|
||||
if (!plan) return { nextDate: null, datedBlocked: null }
|
||||
return { nextDate: plan.date, datedBlocked: plan.fits ? null : t('dashboard.tripTooLong', { days: MAX_TRIP_DAYS }) }
|
||||
}
|
||||
Reference in New Issue
Block a user