mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
feat(planner): edit the trip from its settings in the planner (#2811)
The trip form was mounted in the planner but nothing opened it, so title, dates, cover and currency could only be changed from My Trips. Trip settings now lists Edit Trip at the foot of its areas for anyone with trip_edit; it swaps the dialog for the trip form. The phone already has Edit Trip in the More sheet.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// FE-COMP-MEMBERS-001 to FE-COMP-MEMBERS-061
|
||||
// FE-COMP-MEMBERS-001 to FE-COMP-MEMBERS-063
|
||||
import type { Mock } from 'vitest';
|
||||
import { act, render, screen, fireEvent, waitFor } from '../../../tests/helpers/render';
|
||||
import { act, render, screen, fireEvent, waitFor, within } from '../../../tests/helpers/render';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { delay, http, HttpResponse } from 'msw';
|
||||
import { server } from '../../../tests/helpers/msw/server';
|
||||
@@ -1107,4 +1107,24 @@ describe('TripMembersModal', () => {
|
||||
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/join/inv9'));
|
||||
view.unmount();
|
||||
});
|
||||
|
||||
it('FE-COMP-MEMBERS-062: Edit Trip in the side column hands over to the trip form (#2811)', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onEditTrip = vi.fn();
|
||||
render(<TripMembersModal {...defaultProps} onEditTrip={onEditTrip} />);
|
||||
|
||||
// The column stands for it even where People is the only area.
|
||||
const nav = await screen.findByRole('navigation', { name: 'Trip settings' });
|
||||
await user.click(within(nav).getByRole('button', { name: 'Edit Trip' }));
|
||||
|
||||
expect(onEditTrip).toHaveBeenCalledTimes(1);
|
||||
expect(within(nav).getByText('Title, dates, cover, description and currency.')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-MEMBERS-063: without the right to edit the trip, the dialog offers no way to its form', async () => {
|
||||
render(<TripMembersModal {...defaultProps} />);
|
||||
|
||||
expect(await screen.findByText('owner')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Edit Trip' })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@ interface TripMembersModalProps {
|
||||
/** Called after the roster changes (guest/member added, renamed or removed) so the
|
||||
* planner can refresh its members for Costs participants, Collab, etc. */
|
||||
onMembersChanged?: () => void
|
||||
/** Opens the trip's form from the dialog, for someone who may edit the trip (#2811). */
|
||||
onEditTrip?: () => void
|
||||
}
|
||||
|
||||
/** Share: the trip's members, guests and links. The phone has its own sheet (MTripSettingsSheet) on the same hooks. */
|
||||
|
||||
@@ -18,6 +18,8 @@ interface TripShareDialogProps {
|
||||
tripId: number
|
||||
tripTitle: string
|
||||
onMembersChanged?: () => void
|
||||
/** Hands over to the trip's own form; left out for someone who may not edit the trip (#2811). */
|
||||
onEditTrip?: () => void
|
||||
}
|
||||
|
||||
/** A question the dialog asks before it acts, answered in a ConfirmDialog over it. */
|
||||
@@ -35,6 +37,8 @@ const BADGE = 'inline-flex flex-none items-center gap-1 rounded-full px-2 py-[2p
|
||||
/** A fixed height on a wide screen, so the dialog does not jump when another area is picked. */
|
||||
const BODY = 'flex min-h-0 flex-1 max-md:flex-col md:h-[min(640px,calc(100dvh-240px))]'
|
||||
const NAV = 'flex flex-none gap-1 border-edge-faint bg-surface-secondary p-3 md:w-[236px] md:flex-col md:border-e max-md:overflow-x-auto max-md:border-b'
|
||||
const NAV_ENTRY = 'flex flex-none items-center gap-2.5 rounded-[12px] px-2.5 py-2 text-start transition-colors'
|
||||
const NAV_ENTRY_OFF = 'text-content-muted hover:bg-surface-hover hover:text-content'
|
||||
const DANGER_BUTTON = 'inline-flex items-center gap-1.5 rounded-[10px] bg-surface-card px-3.5 py-2 font-medium text-danger shadow-sm ring-1 ring-edge-faint hover:bg-danger-soft disabled:cursor-default disabled:opacity-50'
|
||||
|
||||
/**
|
||||
@@ -54,7 +58,7 @@ const AREAS: { id: Area; icon: (on: boolean) => ReactNode; labelKey: string; hin
|
||||
{ id: 'journal', icon: () => <LinkedJournalIcon size={16} />, labelKey: 'trip.journal.title', hintKey: 'trip.journal.hint' },
|
||||
]
|
||||
|
||||
function OpenDialog({ onClose, tripId, tripTitle, onMembersChanged }: TripShareDialogProps) {
|
||||
function OpenDialog({ onClose, tripId, tripTitle, onMembersChanged, onEditTrip }: TripShareDialogProps) {
|
||||
const { t } = useTranslation()
|
||||
const labelId = useId()
|
||||
const m = useTripMembers({ isOpen: true, tripId, onClose, onMembersChanged })
|
||||
@@ -65,13 +69,15 @@ function OpenDialog({ onClose, tripId, tripTitle, onMembersChanged }: TripShareD
|
||||
const current = areas.find(a => a.id === area) ?? areas[0]
|
||||
const panelOf = (id: Area) => areas.find(a => a.id === id)
|
||||
const persons = `${m.realMembers.length} ${t('members.persons', { count: m.realMembers.length })}`
|
||||
// The way to the trip's form needs the side nav even where People is the only area.
|
||||
const withNav = areas.length > 1 || !!onEditTrip
|
||||
|
||||
return (
|
||||
<>
|
||||
<DialogShell
|
||||
onClose={onClose}
|
||||
labelledBy={labelId}
|
||||
width={areas.length > 1 ? 'wide' : 'detail'}
|
||||
width={withNav ? 'wide' : 'detail'}
|
||||
blocked={!!ask}
|
||||
bodyClassName={BODY}
|
||||
header={(
|
||||
@@ -91,10 +97,10 @@ function OpenDialog({ onClose, tripId, tripTitle, onMembersChanged }: TripShareD
|
||||
/>
|
||||
)}
|
||||
>
|
||||
{areas.length > 1 && <AreaNav areas={areas} current={current.id} onPick={setArea} />}
|
||||
{withNav && <AreaNav areas={areas} current={current.id} onPick={setArea} onEditTrip={onEditTrip} />}
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-7 pb-7 pt-6 max-sm:px-5">
|
||||
{/* Every area stays mounted, so its links and lists are loaded by the time it is picked. */}
|
||||
<AreaPanel area={panelOf('people')} shown={current.id === 'people'} titled={areas.length > 1}>
|
||||
<AreaPanel area={panelOf('people')} shown={current.id === 'people'} titled={withNav}>
|
||||
{m.canManageMembers && <InviteUser m={m} />}
|
||||
<MembersList m={m} onAsk={setAsk} />
|
||||
{(m.isCurrentOwner || m.guests.length > 0) && <GuestsList m={m} onAsk={setAsk} />}
|
||||
@@ -124,8 +130,11 @@ function OpenDialog({ onClose, tripId, tripTitle, onMembersChanged }: TripShareD
|
||||
)
|
||||
}
|
||||
|
||||
/** The areas down the side on a wide screen, a row of pills above the content on a narrow one. */
|
||||
function AreaNav({ areas, current, onPick }: { areas: typeof AREAS; current: Area; onPick: (area: Area) => void }) {
|
||||
/**
|
||||
* The areas down the side on a wide screen, a row of pills above the content on a narrow one.
|
||||
* Edit trip sits at the foot of the column: it opens the trip's form rather than an area of its own.
|
||||
*/
|
||||
function AreaNav({ areas, current, onPick, onEditTrip }: { areas: typeof AREAS; current: Area; onPick: (area: Area) => void; onEditTrip?: () => void }) {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<nav aria-label={t('trip.settings.title')} className={NAV}>
|
||||
@@ -133,19 +142,33 @@ function AreaNav({ areas, current, onPick }: { areas: typeof AREAS; current: Are
|
||||
const on = a.id === current
|
||||
return (
|
||||
<button key={a.id} type="button" aria-current={on ? 'page' : undefined} aria-label={t(a.labelKey)} onClick={() => onPick(a.id)}
|
||||
className={`flex flex-none items-center gap-2.5 rounded-[12px] px-2.5 py-2 text-start transition-colors ${on ? 'bg-surface-card text-content shadow-sm ring-1 ring-edge-faint' : 'text-content-muted hover:bg-surface-hover hover:text-content'}`}>
|
||||
<span className={`grid h-8 w-8 flex-none place-items-center rounded-[9px] ${on ? 'bg-accent text-accent-text' : 'bg-surface-tertiary'}`}>{a.icon(on)}</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate font-semibold" style={fs(13, 'body')}>{t(a.labelKey)}</span>
|
||||
<span className="block truncate text-content-faint max-md:hidden" style={fs(11)}>{t(a.hintKey)}</span>
|
||||
</span>
|
||||
className={`${NAV_ENTRY} ${on ? 'bg-surface-card text-content shadow-sm ring-1 ring-edge-faint' : NAV_ENTRY_OFF}`}>
|
||||
<NavEntryText icon={a.icon(on)} on={on} label={t(a.labelKey)} hint={t(a.hintKey)} />
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
{onEditTrip && (
|
||||
<button type="button" aria-label={t('dashboard.editTrip')} onClick={onEditTrip} className={`${NAV_ENTRY} ${NAV_ENTRY_OFF} md:mt-auto`}>
|
||||
<NavEntryText icon={<Pencil size={16} strokeWidth={2} />} on={false} label={t('dashboard.editTrip')} hint={t('trip.settings.editTripHint')} />
|
||||
</button>
|
||||
)}
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
|
||||
/** An entry's tile, its name and, on a wide screen, the line under the name. */
|
||||
function NavEntryText({ icon, on, label, hint }: { icon: ReactNode; on: boolean; label: string; hint: string }) {
|
||||
return (
|
||||
<>
|
||||
<span className={`grid h-8 w-8 flex-none place-items-center rounded-[9px] ${on ? 'bg-accent text-accent-text' : 'bg-surface-tertiary'}`}>{icon}</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate font-semibold" style={fs(13, 'body')}>{label}</span>
|
||||
<span className="block truncate text-content-faint max-md:hidden" style={fs(11)}>{hint}</span>
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** One area: its name and what it is for, then its parts. Hidden rather than unmounted while another one shows. */
|
||||
function AreaPanel({ area, shown, titled, children }: { area: (typeof AREAS)[number] | undefined; shown: boolean; titled: boolean; children: ReactNode }) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
@@ -92,7 +92,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
|
||||
highlightedAlternative, setHighlightedAlternative,
|
||||
moveRoadtripStopToDay,
|
||||
dropPoiOnRoute,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, editTripFromSettings,
|
||||
showReservationModal, setShowReservationModal, editingReservation, setEditingReservation,
|
||||
showBookingImport, setShowBookingImport, bookingImportKind, setBookingImportKind, bookingImportAvailable,
|
||||
airTrailAvailable, showAirTrailImport, setShowAirTrailImport,
|
||||
@@ -830,7 +830,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
|
||||
trip={trip}
|
||||
onCoverUpdate={applyTripCoverUpdate}
|
||||
/>
|
||||
<TripMembersModal isOpen={showMembersModal} onClose={() => setShowMembersModal(false)} tripId={tripId} tripTitle={trip?.title} onMembersChanged={refreshMembers} />
|
||||
<TripMembersModal isOpen={showMembersModal} onClose={() => setShowMembersModal(false)} tripId={tripId} tripTitle={trip?.title} onMembersChanged={refreshMembers} onEditTrip={can('trip_edit', trip) ? editTripFromSettings : undefined} />
|
||||
<ReservationModal isOpen={showReservationModal} onClose={() => { if (importReviewActive) { advanceImportReview() } else { setShowReservationModal(false); setEditingReservation(null); setBookingForAssignmentId(null) } }} onSave={async (data, steps) => { const r = await handleSaveReservation(data, steps); if (importReviewActive && r) advanceImportReview(); return r }} reservation={editingReservation} prefill={reservationPrefill} days={days} places={places} assignments={assignments} selectedDayId={selectedDayId} files={files} onFileUpload={canUploadFiles ? (fd) => tripActions.addFile(tripId, fd) : undefined} onFileDelete={(id) => tripActions.deleteFile(tripId, id)} accommodations={tripAccommodations} defaultAssignmentId={bookingForAssignmentId} onOpenExpense={openBookingExpense} tripMembers={tripMembers} />
|
||||
{showTransportModal && (
|
||||
<ErrorBoundary boundaryId="planner-panel:transport" fallback={null}>
|
||||
|
||||
@@ -206,6 +206,7 @@ function dialogState(): HookState {
|
||||
setShowTripForm: vi.fn(),
|
||||
showMembersModal: false,
|
||||
setShowMembersModal: vi.fn(),
|
||||
editTripFromSettings: vi.fn(),
|
||||
showReservationModal: false,
|
||||
setShowReservationModal: vi.fn(),
|
||||
editingReservation: null,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-PAGE-TPW-001 to FE-PAGE-TPW-074
|
||||
// FE-PAGE-TPW-001 to FE-PAGE-TPW-075
|
||||
//
|
||||
// The planner page is a wiring container: everything stateful lives in
|
||||
// useTripPlanner (covered in src/pages/tripPlanner/useTripPlanner.test.tsx).
|
||||
@@ -1552,6 +1552,14 @@ describe('TripPlannerPage — modals', () => {
|
||||
expect(hookState.setShowMembersModal).toHaveBeenCalledWith(false)
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-075: the members modal leads to the trip form only for someone who may edit the trip (#2811)', () => {
|
||||
renderPage()
|
||||
expect(props('membersModal').onEditTrip).toBe(hookState.editTripFromSettings)
|
||||
|
||||
renderPage({ can: vi.fn((action: string) => action !== 'trip_edit') })
|
||||
expect(props('membersModal').onEditTrip).toBeUndefined()
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-050: closing the booking modal outside a review resets the editor', async () => {
|
||||
renderPage()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-TP-DIALOGS-001 to FE-TP-DIALOGS-012
|
||||
// FE-TP-DIALOGS-001 to FE-TP-DIALOGS-013
|
||||
//
|
||||
// The planner's dialogs and the URL intents that open them, driven straight through
|
||||
// usePlannerDialogs. The search params come in as options, so each test owns the URL
|
||||
@@ -248,4 +248,14 @@ describe('usePlannerDialogs', () => {
|
||||
act(() => { result.current.changeTransitRoute(buildReservation({ id: 15, type: 'transit' })) })
|
||||
expect(result.current.transitPrefill).toEqual({ from: null, to: null })
|
||||
})
|
||||
|
||||
it('FE-TP-DIALOGS-013: editing the trip from its settings swaps the settings for the trip form (#2811)', () => {
|
||||
const { result } = renderDialogs()
|
||||
act(() => { result.current.setShowMembersModal(true) })
|
||||
|
||||
act(() => { result.current.editTripFromSettings() })
|
||||
|
||||
expect(result.current.showMembersModal).toBe(false)
|
||||
expect(result.current.showTripForm).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -104,6 +104,12 @@ export function usePlannerDialogs(options: PlannerDialogsOptions) {
|
||||
}, [searchParams])
|
||||
const [showTripForm, setShowTripForm] = useState<boolean>(false)
|
||||
const [showMembersModal, setShowMembersModal] = useState<boolean>(false)
|
||||
// The trip settings hand over to the trip's form rather than stack a second dialog
|
||||
// on their own: the planner's way to the title, dates, cover and currency (#2811).
|
||||
const editTripFromSettings = useCallback(() => {
|
||||
setShowMembersModal(false)
|
||||
setShowTripForm(true)
|
||||
}, [])
|
||||
const [showReservationModal, setShowReservationModal] = useState<boolean>(false)
|
||||
const [editingReservation, setEditingReservation] = useState<Reservation | null>(null)
|
||||
const [showBookingImport, setShowBookingImport] = useState<boolean>(false)
|
||||
@@ -167,7 +173,7 @@ export function usePlannerDialogs(options: PlannerDialogsOptions) {
|
||||
editingAssignmentId, setEditingAssignmentId, placeFormDayId, setPlaceFormDayId,
|
||||
placeFormPosition, setPlaceFormPosition, serviceStopForm, setServiceStopForm, serviceStopKind, setServiceStopKind,
|
||||
stopDraft, setStopDraft, stayRelease, setStayRelease, reservationModalDayId, setReservationModalDayId,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, editTripFromSettings,
|
||||
showReservationModal, setShowReservationModal, editingReservation, setEditingReservation,
|
||||
showBookingImport, setShowBookingImport, bookingImportKind, setBookingImportKind,
|
||||
bookingImportAvailable, setBookingImportAvailable, airTrailAvailable, showAirTrailImport, setShowAirTrailImport,
|
||||
|
||||
@@ -360,7 +360,7 @@ export function useTripPlanner() {
|
||||
// The dialog state that only passes through to the shells.
|
||||
const {
|
||||
showPlaceForm, prefillCoords, reservationModalDayId, setReservationModalDayId,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, showReservationModal,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, editTripFromSettings, showReservationModal,
|
||||
showBookingImport, setShowBookingImport, bookingImportKind, setBookingImportKind, bookingImportAvailable,
|
||||
airTrailAvailable, showAirTrailImport, setShowAirTrailImport, bookingForAssignmentId, setBookingForAssignmentId,
|
||||
showTransportModal, transportModalDayId, transportModalAutomated, setTransportModalAutomated,
|
||||
@@ -749,7 +749,7 @@ export function useTripPlanner() {
|
||||
highlightedAlternative, setHighlightedAlternative,
|
||||
moveRoadtripStopToDay,
|
||||
dropPoiOnRoute,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, editTripFromSettings,
|
||||
showReservationModal, setShowReservationModal, editingReservation, setEditingReservation,
|
||||
showBookingImport, setShowBookingImport, bookingImportKind, setBookingImportKind, bookingImportAvailable,
|
||||
airTrailAvailable, showAirTrailImport, setShowAirTrailImport,
|
||||
|
||||
Reference in New Issue
Block a user