mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
feat(trips): shortening a trip says first which days go and what is on them
The trip dialog on the desktop and the trip sheet on a phone now ask before a save whose new dates remove days with something on them. The question names those days the way the day list does and lists what goes with them in the same rows the delete day question uses: planned places stay in the place list, notes and day texts are deleted, bookings stay under Bookings, and a stay that checks in or out on a removed day goes as a whole while its booking and expense remain, shown in the danger tone. A moved start gets both questions in one step, with the booking hint following the chosen shift mode, and a save that only drops empty days asks nothing. The rule that lays the days out moved into shared as planDayGrid, with resolveDayGridRange deciding whether the rows are rebuilt at all. generateDays on the server now carries that plan out in one transaction, so the warning names exactly the days the save takes, and a seeded fuzz test holds the new rebuild to the old one over 300 random day grids. The update_trip tool says in its description what shortening takes and lists removed_days in its answer. Alongside, the dialog sends a day count only when it changed, so a stale count no longer trims a day just added, stays are reloaded after every date change including the one made on a phone, and the date shift tip now points to adding a day under Reorder days.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { AlertTriangle } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import DayImpactList from '../shared/DayImpactList'
|
||||
import { dayChips, shrinkTripLines, type ShiftMode } from '../../utils/dayImpactLines'
|
||||
import type { RangeCheck } from '../../hooks/useTripRangeGuard'
|
||||
|
||||
interface TripDateReviewProps {
|
||||
/** The start of a dated trip moved: ask how bookings follow (#1288). */
|
||||
askShift: boolean
|
||||
shiftMode: ShiftMode
|
||||
onShiftMode: (mode: ShiftMode) => void
|
||||
/** What the new dates remove, if anything worth a word. */
|
||||
removal: RangeCheck
|
||||
error?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The step the trip dialog puts between a change of dates and the save: how
|
||||
* bookings follow a moved start, and which days the new range removes with what
|
||||
* is on them. Either part can stand alone. The list's booking hint follows the
|
||||
* shift mode picked above it, because the two modes leave those bookings in
|
||||
* different places.
|
||||
*/
|
||||
export default function TripDateReview({ askShift, shiftMode, onShiftMode, removal, error }: TripDateReviewProps) {
|
||||
const { t } = useTranslation()
|
||||
const modes: { mode: ShiftMode; label: string; desc: string }[] = [
|
||||
{ mode: 'keep_bookings', label: t('dashboard.dateShiftKeepBookings'), desc: t('dashboard.dateShiftKeepBookingsDesc') },
|
||||
{ mode: 'shift_all', label: t('dashboard.dateShiftAll'), desc: t('dashboard.dateShiftAllDesc') },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{error && (
|
||||
<div className="p-3 bg-danger-soft border border-danger/30 rounded-xl text-body text-danger">{error}</div>
|
||||
)}
|
||||
{askShift && (
|
||||
<>
|
||||
<p className="text-body text-content-secondary">{t('dashboard.dateShiftIntro')}</p>
|
||||
{modes.map(({ mode, label, desc }) => (
|
||||
<label key={mode}
|
||||
className={`flex items-start gap-3 p-3 border rounded-xl cursor-pointer transition-colors ${shiftMode === mode ? 'border-accent bg-surface-selected' : 'border-edge hover:bg-surface-hover'}`}>
|
||||
<input type="radio" name="date_shift_mode" value={mode} checked={shiftMode === mode}
|
||||
onChange={() => onShiftMode(mode)} className="mt-1 accent-[var(--accent)]" />
|
||||
<span className="block text-body font-medium text-content">
|
||||
{label}
|
||||
<span className="block text-body font-normal text-content-muted mt-0.5">{desc}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
{removal === 'unknown' && (
|
||||
<div role="alert" className="flex items-start gap-3 rounded-xl border border-edge-faint bg-surface-secondary p-3">
|
||||
<span className="mt-0.5 flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-danger-soft text-danger">
|
||||
<AlertTriangle size={15} strokeWidth={2} aria-hidden="true" />
|
||||
</span>
|
||||
<p className="text-body text-content">{t('dashboard.shrinkUnknown')}</p>
|
||||
</div>
|
||||
)}
|
||||
{removal && removal !== 'unknown' && (
|
||||
<div className={askShift ? 'border-t border-edge-faint pt-3' : ''}>
|
||||
<p className="text-body text-content-secondary">{t('dashboard.shrinkIntro')}</p>
|
||||
<DayImpactList
|
||||
lines={shrinkTripLines(removal, t, shiftMode)}
|
||||
days={dayChips(removal.dayLabels, t)}
|
||||
label={t('dashboard.shrinkTitle')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{askShift && <p className="text-caption text-content-faint">{t('dashboard.dateShiftHint')}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-COMP-TRIPFORM-001 to FE-COMP-TRIPFORM-084
|
||||
// FE-COMP-TRIPFORM-001 to FE-COMP-TRIPFORM-095
|
||||
import type { Mock } from 'vitest';
|
||||
import { render, screen, waitFor, fireEvent, within } from '../../../tests/helpers/render';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
@@ -8,9 +8,9 @@ import { useTripStore } from '../../store/tripStore';
|
||||
import { useSettingsStore } from '../../store/settingsStore';
|
||||
import { usePermissionsStore } from '../../store/permissionsStore';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import { buildUser, buildTrip } from '../../../tests/helpers/factories';
|
||||
import { buildUser, buildTrip, buildDay, buildAssignment, buildPlace, buildReservation } from '../../../tests/helpers/factories';
|
||||
import { server } from '../../../tests/helpers/msw/server';
|
||||
import type { Trip } from '../../types';
|
||||
import type { Accommodation, Reservation, Trip } from '../../types';
|
||||
import { MAX_TRIP_DAYS } from '@trek/shared';
|
||||
import TripFormModal from './TripFormModal';
|
||||
|
||||
@@ -1290,4 +1290,169 @@ describe('TripFormModal', () => {
|
||||
expect.objectContaining({ title: 'Renamed', start_date: '2020-01-01', end_date: '2030-01-01' })
|
||||
));
|
||||
});
|
||||
|
||||
// ── Shortening: the warning before days go ────────────────────────────────
|
||||
|
||||
/** A week in October with a place on its last two days, and the trip's bookings and stays. */
|
||||
const shrinkableTrip = () => buildTrip({ id: 1, title: 'Coast week', start_date: '2026-10-01', end_date: '2026-10-07' });
|
||||
const seedTripDays = (extras: { reservations?: Reservation[]; accommodations?: Accommodation[]; empty?: boolean } = {}) => {
|
||||
const days = Array.from({ length: 7 }, (_, i) => buildDay({
|
||||
id: 300 + i,
|
||||
trip_id: 1,
|
||||
day_number: i + 1,
|
||||
date: `2026-10-0${i + 1}`,
|
||||
assignments: !extras.empty && i >= 5 ? [buildAssignment({ day_id: 300 + i, place: buildPlace({ id: 400 + i }) })] : [],
|
||||
}));
|
||||
server.use(
|
||||
http.get('/api/trips/:id/days', () => HttpResponse.json({ days })),
|
||||
http.get('/api/trips/:id/reservations', () => HttpResponse.json({ reservations: extras.reservations ?? [] })),
|
||||
http.get('/api/trips/:id/accommodations', () => HttpResponse.json({ accommodations: extras.accommodations ?? [] })),
|
||||
);
|
||||
};
|
||||
const changeEndDate = async (user: ReturnType<typeof userEvent.setup>, iso: string) => {
|
||||
await user.click(screen.getAllByRole('button', { name: 'Enter date manually' })[1]);
|
||||
const input = screen.getByPlaceholderText('DD.MM.YYYY');
|
||||
fireEvent.change(input, { target: { value: iso } });
|
||||
fireEvent.keyDown(input, { key: 'Enter' });
|
||||
};
|
||||
|
||||
it('FE-COMP-TRIPFORM-088: an earlier end asks first and names the days it takes, with what is on them', async () => {
|
||||
seedTripDays({
|
||||
accommodations: [{ id: 9, trip_id: 1, start_day_id: 304, end_day_id: 306, place_name: 'Harbour Hotel' } as Accommodation],
|
||||
reservations: [buildReservation({ id: 70, day_id: 304, type: 'hotel', title: 'Harbour, 2 nights', accommodation_id: 9 })],
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
const onSave = vi.fn().mockResolvedValue({});
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={onSave} />);
|
||||
|
||||
await changeEndDate(user, '2026-10-05');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
|
||||
const list = await screen.findByRole('list', { name: 'Remove days?' });
|
||||
expect(screen.getAllByText('Remove days?').length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('Saving the new dates removes these days:')).toBeInTheDocument();
|
||||
expect(within(list).getByText('Tue, Oct 6')).toBeInTheDocument();
|
||||
expect(within(list).getByText('Wed, Oct 7')).toBeInTheDocument();
|
||||
expect(within(list).getByText('Stay at Harbour Hotel').closest('li')).toHaveAttribute('data-tone', 'danger');
|
||||
expect(within(list).getByText(/Its booking "Harbour, 2 nights" and its expense stay under Bookings/)).toBeInTheDocument();
|
||||
expect(within(list).getByText('Planned places: 2')).toBeInTheDocument();
|
||||
// No start moved, so no shift question.
|
||||
expect(screen.queryByText('Keep bookings on their dates')).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Remove days and save' })).toHaveClass('bg-danger');
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-089: a later start that also shortens asks both in one step', async () => {
|
||||
seedTripDays();
|
||||
const user = userEvent.setup();
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={vi.fn()} />);
|
||||
|
||||
// Moving the start keeps the length, so the end is pulled back afterwards.
|
||||
await changeStartDate(user, '2026-10-03');
|
||||
await changeEndDate(user, '2026-10-07');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
|
||||
await screen.findByText('Keep bookings on their dates');
|
||||
expect(screen.getByText('New start date')).toBeInTheDocument();
|
||||
const list = screen.getByRole('list', { name: 'Remove days?' });
|
||||
expect(within(list).getByText('The last days go, not the first')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Remove days and save' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-090: a longer trip, or a shorter one that loses only empty days, saves without asking', async () => {
|
||||
seedTripDays({ empty: true });
|
||||
const user = userEvent.setup();
|
||||
const onSave = vi.fn().mockResolvedValue({});
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={onSave} />);
|
||||
|
||||
await changeEndDate(user, '2026-10-05');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ end_date: '2026-10-05' })));
|
||||
expect(onSave).toHaveBeenCalledWith(expect.not.objectContaining({ date_shift_mode: expect.anything() }));
|
||||
expect(screen.queryByRole('list', { name: 'Remove days?' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-091: confirming saves the held payload, with the shift mode only when it was asked', async () => {
|
||||
seedTripDays();
|
||||
const user = userEvent.setup();
|
||||
const onSave = vi.fn().mockResolvedValue({});
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={onSave} />);
|
||||
|
||||
await changeEndDate(user, '2026-10-05');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
await user.click(await screen.findByRole('button', { name: 'Remove days and save' }));
|
||||
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
|
||||
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ start_date: '2026-10-01', end_date: '2026-10-05' }));
|
||||
expect(onSave).toHaveBeenCalledWith(expect.not.objectContaining({ date_shift_mode: expect.anything() }));
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-092: the booking hint follows the shift mode picked above the list', async () => {
|
||||
seedTripDays({ reservations: [buildReservation({ id: 71, day_id: 306, title: 'Ferry' })] });
|
||||
const user = userEvent.setup();
|
||||
const onSave = vi.fn().mockResolvedValue({});
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={onSave} />);
|
||||
|
||||
await changeStartDate(user, '2026-10-02');
|
||||
await changeEndDate(user, '2026-10-06');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
|
||||
const list = await screen.findByRole('list', { name: 'Remove days?' });
|
||||
expect(within(list).getByText(/One whose date is still part of the trip goes back onto that day/)).toBeInTheDocument();
|
||||
await user.click(screen.getByRole('radio', { name: /Shift everything/i }));
|
||||
expect(within(list).getByText('They stay under Bookings, without a day.')).toBeInTheDocument();
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Remove days and save' }));
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ date_shift_mode: 'shift_all' })));
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-093: Back from the warning returns to the form and saves nothing', async () => {
|
||||
seedTripDays();
|
||||
const user = userEvent.setup();
|
||||
const onSave = vi.fn();
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={onSave} />);
|
||||
|
||||
await changeEndDate(user, '2026-10-05');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
await screen.findByRole('list', { name: 'Remove days?' });
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /Back/i }));
|
||||
await waitFor(() => expect(screen.queryByRole('list', { name: 'Remove days?' })).not.toBeInTheDocument());
|
||||
expect(screen.getByDisplayValue('Coast week')).toBeInTheDocument();
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-094: when the days cannot be read it still warns, in general terms', async () => {
|
||||
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
server.use(http.get('/api/trips/:id/days', () => HttpResponse.json({ error: 'boom' }, { status: 500 })));
|
||||
const user = userEvent.setup();
|
||||
render(<TripFormModal {...defaultProps} trip={shrinkableTrip()} onSave={vi.fn()} />);
|
||||
|
||||
await changeEndDate(user, '2026-10-05');
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('The days of this trip could not be checked.');
|
||||
expect(screen.queryByRole('list', { name: 'Remove days?' })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Remove days and save' })).toBeInTheDocument();
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('FE-COMP-TRIPFORM-095: a trip without dates sends its day count only when it changed', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onSave = vi.fn().mockResolvedValue({});
|
||||
const undated = buildTrip({ id: 1, title: 'Someday', start_date: null, end_date: null, day_count: 4 });
|
||||
const { unmount } = render(<TripFormModal {...defaultProps} trip={undated} onSave={onSave} />);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
|
||||
expect(onSave.mock.calls[0][0]).not.toHaveProperty('day_count');
|
||||
unmount();
|
||||
|
||||
render(<TripFormModal {...defaultProps} trip={undated} onSave={onSave} />);
|
||||
const dayInput = document.querySelector(`input[max="${MAX_TRIP_DAYS}"]`) as HTMLInputElement;
|
||||
fireEvent.change(dayInput, { target: { value: '6' } });
|
||||
await user.click(screen.getByRole('button', { name: /Update/i }));
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(2));
|
||||
expect(onSave.mock.calls[1][0]).toMatchObject({ day_count: 6 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,8 +14,23 @@ import { getApiErrorMessage, type Trip } from '../../types'
|
||||
import { MAX_TRIP_DAYS, tripSpanDays, type TripCreateRequest } from '@trek/shared'
|
||||
import { NumericInput } from '../shared/NumericInput'
|
||||
import { currenciesWith, SYMBOLS } from '../Budget/BudgetPanel.constants'
|
||||
import TripDateReview from './TripDateReview'
|
||||
import { useTripRangeGuard, type RangeCheck } from '../../hooks/useTripRangeGuard'
|
||||
import type { ShiftMode } from '../../utils/dayImpactLines'
|
||||
|
||||
type DateShiftMode = 'keep_bookings' | 'shift_all'
|
||||
type DateShiftMode = ShiftMode
|
||||
type TripPayload = TripCreateRequest & { date_shift_mode?: DateShiftMode }
|
||||
|
||||
/**
|
||||
* A save held back for a look first: the start of a dated trip moved and the
|
||||
* bookings need a direction (#1288), or the new range removes days with
|
||||
* something on them. The payload waits here until the traveller confirms.
|
||||
*/
|
||||
interface PendingReview {
|
||||
payload: TripPayload
|
||||
askShift: boolean
|
||||
removal: RangeCheck
|
||||
}
|
||||
|
||||
interface TripFormModalProps {
|
||||
isOpen: boolean
|
||||
@@ -80,10 +95,10 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
const [selectedMembers, setSelectedMembers] = useState<number[]>([])
|
||||
const [existingMembers, setExistingMembers] = useState<{ id: number; username: string }[]>([])
|
||||
const [memberSelectValue, setMemberSelectValue] = useState('')
|
||||
// Set when a start-date change on a dated trip needs the user to pick how the
|
||||
// itinerary follows the new dates (#1288); holds the payload awaiting that choice.
|
||||
const [pendingDateShift, setPendingDateShift] = useState<(TripCreateRequest & { date_shift_mode?: DateShiftMode }) | null>(null)
|
||||
const [pendingReview, setPendingReview] = useState<PendingReview | null>(null)
|
||||
const [dateShiftMode, setDateShiftMode] = useState<DateShiftMode>('keep_bookings')
|
||||
const rangeGuard = useTripRangeGuard()
|
||||
const busy = isLoading || rangeGuard.checking
|
||||
|
||||
useEffect(() => {
|
||||
if (trip) {
|
||||
@@ -115,7 +130,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
setCoverSearchResults([])
|
||||
setCoverSearchError('')
|
||||
setSelectedMembers([])
|
||||
setPendingDateShift(null)
|
||||
setPendingReview(null)
|
||||
setDateShiftMode('keep_bookings')
|
||||
setError('')
|
||||
setExistingMembers([])
|
||||
@@ -162,28 +177,38 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
setError(t('dashboard.dayCountRequired')); return
|
||||
}
|
||||
}
|
||||
const payload: TripCreateRequest & { date_shift_mode?: DateShiftMode } = {
|
||||
// The day count goes along only when it says something new. The trip's own
|
||||
// count goes stale in the planner (adding a day does not reload the trip),
|
||||
// and sending the stale number trims the day just added off a trip that was
|
||||
// only renamed. On a trip left without dates the server keeps its days anyway.
|
||||
const dayCount = Number(formData.day_count)
|
||||
const sendDayCount = !formData.start_date && !formData.end_date && (!isEditing || dayCount !== trip?.day_count)
|
||||
const payload: TripPayload = {
|
||||
title: formData.title.trim(),
|
||||
description: formData.description.trim() || null,
|
||||
start_date: formData.start_date || null,
|
||||
end_date: formData.end_date || null,
|
||||
currency: formData.currency,
|
||||
reminder_days: formData.reminder_days,
|
||||
...(!formData.start_date && !formData.end_date ? { day_count: Number(formData.day_count) } : {}),
|
||||
...(sendDayCount ? { day_count: dayCount } : {}),
|
||||
}
|
||||
// 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 (isEditing && trip?.start_date && trip?.end_date
|
||||
&& payload.start_date && payload.end_date && payload.start_date !== trip.start_date) {
|
||||
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
|
||||
// they are gone: the server takes the last days by position.
|
||||
const removal = isEditing && trip ? await rangeGuard.check(trip, payload) : null
|
||||
if (askShift || removal) {
|
||||
setDateShiftMode('keep_bookings')
|
||||
setPendingDateShift(payload)
|
||||
setPendingReview({ payload, askShift, removal })
|
||||
return
|
||||
}
|
||||
await performSave(payload)
|
||||
}
|
||||
|
||||
const performSave = async (payload: TripCreateRequest & { date_shift_mode?: DateShiftMode }) => {
|
||||
const performSave = async (payload: TripPayload) => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const result = await onSave(payload)
|
||||
@@ -368,6 +393,7 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
const labelCls = "flex items-center gap-1 text-caption font-semibold uppercase tracking-[0.14em] text-content-faint mb-2"
|
||||
const ghostBtnCls = "px-4 py-2.5 text-body font-medium text-content-secondary hover:text-content border border-edge rounded-xl hover:bg-surface-hover transition-colors"
|
||||
const primaryBtnCls = "px-5 py-2.5 text-body font-medium bg-accent hover:bg-accent-hover disabled:opacity-50 text-accent-text rounded-xl shadow-card transition-colors flex items-center gap-2"
|
||||
const dangerBtnCls = "px-5 py-2.5 text-body font-medium bg-danger hover:opacity-90 disabled:opacity-50 text-white rounded-xl shadow-card transition-opacity flex items-center gap-2"
|
||||
/* Two columns once there is room for them: the form had grown to eight stacked
|
||||
blocks and the create button sat a full screen below the title. Left is what
|
||||
the trip looks like, right is when and with whom. One column below md. */
|
||||
@@ -378,22 +404,26 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
title={pendingDateShift ? t('dashboard.dateShiftTitle') : isEditing ? t('dashboard.editTrip') : t('dashboard.createTrip')}
|
||||
/* The date-shift step is two radio buttons and a sentence — it would look
|
||||
title={pendingReview
|
||||
? t(pendingReview.askShift ? 'dashboard.dateShiftTitle' : 'dashboard.shrinkTitle')
|
||||
: isEditing ? t('dashboard.editTrip') : t('dashboard.createTrip')}
|
||||
/* The review step is a few radio buttons and a short list; it would look
|
||||
lost across the width the form itself needs. */
|
||||
size={pendingDateShift ? 'md' : '2xl'}
|
||||
size={pendingReview ? 'md' : '2xl'}
|
||||
footer={
|
||||
<div className="flex gap-3 justify-end">
|
||||
{pendingDateShift ? (
|
||||
{pendingReview ? (
|
||||
<>
|
||||
<button type="button" onClick={() => setPendingDateShift(null)} disabled={isLoading} className={ghostBtnCls}>
|
||||
<button type="button" onClick={() => setPendingReview(null)} disabled={busy} className={ghostBtnCls}>
|
||||
{t('common.back')}
|
||||
</button>
|
||||
<button type="button" onClick={() => performSave({ ...pendingDateShift, date_shift_mode: dateShiftMode })} disabled={isLoading}
|
||||
className={primaryBtnCls}>
|
||||
{/* Removing days with something on them is the one save here that
|
||||
loses work, so it asks in the danger tone and says so. */}
|
||||
<button type="button" onClick={() => performSave(pendingReview.askShift ? { ...pendingReview.payload, date_shift_mode: dateShiftMode } : pendingReview.payload)} disabled={busy}
|
||||
className={pendingReview.removal ? dangerBtnCls : primaryBtnCls}>
|
||||
{isLoading
|
||||
? <><div className="w-4 h-4 border-2 border-accent-text/30 border-t-accent-text rounded-full animate-spin" />{t('common.saving')}</>
|
||||
: t('common.update')}
|
||||
? <><div className={`w-4 h-4 border-2 rounded-full animate-spin ${pendingReview.removal ? 'border-white/30 border-t-white' : 'border-accent-text/30 border-t-accent-text'}`} />{t('common.saving')}</>
|
||||
: t(pendingReview.removal ? 'dashboard.shrinkConfirm' : 'common.update')}
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
@@ -401,8 +431,8 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
<button type="button" onClick={onClose} className={ghostBtnCls}>
|
||||
{t('common.cancel')}
|
||||
</button>
|
||||
<button type="button" onClick={handleSubmit} disabled={isLoading} className={primaryBtnCls}>
|
||||
{isLoading
|
||||
<button type="button" onClick={handleSubmit} disabled={busy} className={primaryBtnCls}>
|
||||
{busy
|
||||
? <><div className="w-4 h-4 border-2 border-accent-text/30 border-t-accent-text rounded-full animate-spin" />{t('common.saving')}</>
|
||||
: isEditing ? t('common.update') : t('dashboard.createTrip')}
|
||||
</button>
|
||||
@@ -411,30 +441,16 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{pendingDateShift && (
|
||||
<div className="space-y-3">
|
||||
{error && (
|
||||
<div className="p-3 bg-danger-soft border border-danger/30 rounded-xl text-body text-danger">{error}</div>
|
||||
)}
|
||||
<p className="text-body text-content-secondary">{t('dashboard.dateShiftIntro')}</p>
|
||||
{([
|
||||
{ mode: 'keep_bookings' as DateShiftMode, label: t('dashboard.dateShiftKeepBookings'), desc: t('dashboard.dateShiftKeepBookingsDesc') },
|
||||
{ mode: 'shift_all' as DateShiftMode, label: t('dashboard.dateShiftAll'), desc: t('dashboard.dateShiftAllDesc') },
|
||||
]).map(({ mode, label, desc }) => (
|
||||
<label key={mode}
|
||||
className={`flex items-start gap-3 p-3 border rounded-xl cursor-pointer transition-colors ${dateShiftMode === mode ? 'border-accent bg-surface-selected' : 'border-edge hover:bg-surface-hover'}`}>
|
||||
<input type="radio" name="date_shift_mode" value={mode} checked={dateShiftMode === mode}
|
||||
onChange={() => setDateShiftMode(mode)} className="mt-1 accent-[var(--accent)]" />
|
||||
<span className="block text-body font-medium text-content">
|
||||
{label}
|
||||
<span className="block text-body font-normal text-content-muted mt-0.5">{desc}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
<p className="text-caption text-content-faint">{t('dashboard.dateShiftHint')}</p>
|
||||
</div>
|
||||
{pendingReview && (
|
||||
<TripDateReview
|
||||
askShift={pendingReview.askShift}
|
||||
shiftMode={dateShiftMode}
|
||||
onShiftMode={setDateShiftMode}
|
||||
removal={pendingReview.removal}
|
||||
error={error}
|
||||
/>
|
||||
)}
|
||||
<form onSubmit={handleSubmit} className={pendingDateShift ? 'hidden' : 'space-y-4'} onPaste={handlePaste}>
|
||||
<form onSubmit={handleSubmit} className={pendingReview ? 'hidden' : 'space-y-4'} onPaste={handlePaste}>
|
||||
{error && (
|
||||
<div className="p-3 bg-danger-soft border border-danger/30 rounded-xl text-body text-danger">{error}</div>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-COMP-DAYIMPACT-001 to FE-COMP-DAYIMPACT-003
|
||||
// FE-COMP-DAYIMPACT-001 to FE-COMP-DAYIMPACT-004
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { BedDouble, MapPin } from 'lucide-react'
|
||||
import { render, screen } from '../../../tests/helpers/render'
|
||||
@@ -46,4 +46,21 @@ describe('DayImpactList', () => {
|
||||
expect(rows[0].className).not.toContain('border-t')
|
||||
expect(rows[1].className).toContain('border-t')
|
||||
})
|
||||
|
||||
it('FE-COMP-DAYIMPACT-004: the days themselves lead the list as chips, in both skins', () => {
|
||||
render(<DayImpactList lines={lines} days={['Fri, Oct 9', 'Sat, Oct 10', '+2 more']} label="desk" />)
|
||||
const desk = screen.getByRole('list', { name: 'desk' })
|
||||
const [daysRow, stay] = Array.from(desk.querySelectorAll('li'))
|
||||
expect(daysRow).toHaveAttribute('data-kind', 'days')
|
||||
expect(Array.from(daysRow.querySelectorAll('div > span')).map(s => s.textContent)).toEqual(['Fri, Oct 9', 'Sat, Oct 10', '+2 more'])
|
||||
expect(daysRow.querySelector('span')).toHaveClass('bg-warning-soft')
|
||||
expect(stay).toHaveTextContent('Stay at Harbour Hotel')
|
||||
|
||||
render(<MDayImpactList lines={lines} days={['Fri, Oct 9']} label="phone" />)
|
||||
const phoneRows = screen.getByRole('list', { name: 'phone' }).querySelectorAll('li')
|
||||
expect(phoneRows).toHaveLength(3)
|
||||
expect(phoneRows[0].className).not.toContain('border-t')
|
||||
// The first content row sits under the day chips, so it gets the hairline.
|
||||
expect(phoneRows[1].className).toContain('border-t')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CalendarMinus } from 'lucide-react'
|
||||
import type { ImpactLine, ImpactTone } from '../../utils/dayImpactLines'
|
||||
|
||||
/** The class names one shell draws the list with. */
|
||||
@@ -7,6 +8,8 @@ export interface ImpactListSkin {
|
||||
/** Between two rows; the desktop card divides them itself. */
|
||||
divider: string
|
||||
chip: string
|
||||
/** One removed day, named in the row above the content rows. */
|
||||
dayChip: string
|
||||
iconSize: number
|
||||
text: string
|
||||
hint: string
|
||||
@@ -19,6 +22,7 @@ const DESKTOP: ImpactListSkin = {
|
||||
row: 'flex items-start gap-3 px-3 py-2.5',
|
||||
divider: '',
|
||||
chip: 'mt-0.5 flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg',
|
||||
dayChip: 'rounded-full border border-edge-faint bg-surface px-2.5 py-0.5 text-caption font-medium text-content-secondary',
|
||||
iconSize: 15,
|
||||
text: 'text-body font-medium leading-snug',
|
||||
hint: 'mt-0.5 text-caption text-content-muted',
|
||||
@@ -33,6 +37,11 @@ const DESKTOP: ImpactListSkin = {
|
||||
|
||||
interface DayImpactListProps {
|
||||
lines: ImpactLine[]
|
||||
/**
|
||||
* The days themselves, as chips in a first row: when several days go at
|
||||
* once, the list names them before it says what is on them.
|
||||
*/
|
||||
days?: string[]
|
||||
/** Names the list for assistive tech; the dialog title usually says it already. */
|
||||
label?: string
|
||||
/** The phone passes its own; the default is the desktop card. */
|
||||
@@ -46,12 +55,23 @@ interface DayImpactListProps {
|
||||
* skin, so the desktop dialog and the phone sheet share this markup and differ
|
||||
* only in their tokens.
|
||||
*/
|
||||
export default function DayImpactList({ lines, label, skin = DESKTOP }: DayImpactListProps) {
|
||||
export default function DayImpactList({ lines, days = [], label, skin = DESKTOP }: DayImpactListProps) {
|
||||
if (lines.length === 0) return null
|
||||
const offset = days.length > 0 ? 1 : 0
|
||||
return (
|
||||
<ul aria-label={label} className={skin.list}>
|
||||
{offset > 0 && (
|
||||
<li data-kind="days" className={skin.row}>
|
||||
<span className={`${skin.chip} ${skin.chipTone.warning}`}>
|
||||
<CalendarMinus size={skin.iconSize} strokeWidth={2} aria-hidden="true" />
|
||||
</span>
|
||||
<div className="flex min-w-0 flex-1 flex-wrap gap-1.5 pt-1">
|
||||
{days.map((name, i) => <span key={`${i}-${name}`} className={skin.dayChip}>{name}</span>)}
|
||||
</div>
|
||||
</li>
|
||||
)}
|
||||
{lines.map(({ key, icon: Icon, text, hint, tone }, i) => (
|
||||
<li key={key} data-tone={tone} className={`${skin.row} ${i > 0 ? skin.divider : ''}`.trim()}>
|
||||
<li key={key} data-tone={tone} className={`${skin.row} ${i + offset > 0 ? skin.divider : ''}`.trim()}>
|
||||
<span className={`${skin.chip} ${skin.chipTone[tone]}`}>
|
||||
<Icon size={skin.iconSize} strokeWidth={2} aria-hidden="true" />
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user