mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 02:56:10 +00:00
fix(mobile): a stay can be added to a trip that has no place yet
A stay belongs to one of the trip's places, so on a new trip the accommodation sheet only said "Add places to your trip first", and the booking could not be saved without leaving the sheet (TestFlight feedback, 5.1.3). The hint now carries the "Add place/activity" button for anyone allowed to add places: the place form opens over the sheet, and the place is listed to pick once it is saved.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ArrowRight, Check, Hotel, MapPin, X } from 'lucide-react'
|
||||
import { ArrowRight, Check, Hotel, MapPin, Plus, X } from 'lucide-react'
|
||||
import MSheet from '../../../components/MSheet'
|
||||
import MIconBtn from '../../../components/MIconBtn'
|
||||
import CustomSelect from '../../../../components/shared/CustomSelect'
|
||||
@@ -88,6 +88,15 @@ export default function MAccommodationSheet({ planner, shell }: MTripSheetsProps
|
||||
|
||||
const filteredPlaces = stayPlaceChoices(places, form.place_id, categoryFilter)
|
||||
|
||||
// Same opener as the places tab's add button: a blank form, no prefilled position.
|
||||
const canAddPlace = planner.can('place_edit', planner.trip)
|
||||
const openAddPlace = () => {
|
||||
planner.setEditingPlace(null)
|
||||
planner.setEditingAssignmentId(null)
|
||||
planner.setPrefillCoords(null)
|
||||
planner.setShowPlaceForm(true)
|
||||
}
|
||||
|
||||
const save = async () => {
|
||||
setSaving(true)
|
||||
const body = stayRequestBody(form, range)
|
||||
@@ -204,9 +213,21 @@ export default function MAccommodationSheet({ planner, shell }: MTripSheetsProps
|
||||
{/* Place picker */}
|
||||
<Eyebrow className="mb-[6px] mt-3">{t('reservations.meta.pickHotel')}</Eyebrow>
|
||||
{filteredPlaces.length === 0 ? (
|
||||
<p className="rounded-[14px] bg-[color:var(--m-ic)] px-3 py-6 text-center font-geist text-[0.75rem] text-m-faint">
|
||||
{t('day.noPlacesForHotel')}
|
||||
</p>
|
||||
<div className="flex flex-col items-center gap-2.5 rounded-[14px] bg-[color:var(--m-ic)] px-3 py-5 text-center">
|
||||
<p className="font-geist text-[0.75rem] text-m-faint">{t('day.noPlacesForHotel')}</p>
|
||||
{/* A new trip has no place yet, and the stay needs one: the place form
|
||||
opens over this sheet and its place is listed here once saved. */}
|
||||
{canAddPlace && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={openAddPlace}
|
||||
className="flex items-center gap-1.5 rounded-full bg-m-act px-3.5 py-[7px] text-[0.75rem] font-semibold text-m-actfg"
|
||||
>
|
||||
<Plus size={13} strokeWidth={2.4} />
|
||||
{t('planner.addPlace')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
{filteredPlaces.map(p => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useSettingsStore } from '../../../../src/store/settingsStore'
|
||||
import { isBlurred } from '../../../helpers/bookingCodeBlur'
|
||||
import { act, fireEvent, render, screen, waitFor } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-ACCSH-001 to FE-MOB-ACCSH-031
|
||||
// FE-MOB-ACCSH-001 to FE-MOB-ACCSH-033
|
||||
|
||||
// The pickers have their own suites; here they only need to be addressable, so
|
||||
// they render as plain controls. data-value keeps the requested value readable
|
||||
@@ -256,6 +256,22 @@ describe('MAccommodationSheet', () => {
|
||||
expect(screen.getByText('Add places to your trip first')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-ACCSH-032: a trip without places offers to add one instead of a dead end', () => {
|
||||
const { planner } = setup(makePlanner({ places: [] }))
|
||||
expect(screen.getByText('Add places to your trip first')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Add place/activity' }))
|
||||
|
||||
expect(planner.setEditingPlace).toHaveBeenCalledWith(null)
|
||||
expect(planner.setShowPlaceForm).toHaveBeenCalledWith(true)
|
||||
})
|
||||
|
||||
it('FE-MOB-ACCSH-033: without the right to add places the hint stays a hint', () => {
|
||||
setup(makePlanner({ places: [], can: vi.fn(() => false) }))
|
||||
expect(screen.getByText('Add places to your trip first')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Add place/activity' })).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-MOB-ACCSH-018: without categories there are no filter chips', () => {
|
||||
setup(makePlanner({ categories: [] }))
|
||||
expect(screen.queryByRole('button', { name: 'Hotels' })).not.toBeInTheDocument()
|
||||
|
||||
Reference in New Issue
Block a user