diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index 905e8a2cf..58f062177 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -704,6 +704,18 @@ "desktop": ["src/components/Planner/PlaceFormModal.tsx"], "mobile": ["src/mobile/screens/trip/sheets/MPlaceEditSheet.tsx"] }, + { + "feature": "Place add/edit form: description, notes and the day note as tabs", + "hooks": ["src/components/Planner/usePlaceTextTabs.ts"], + "desktop": ["src/components/Planner/PlaceFormTexts.tsx"], + "mobile": ["src/mobile/screens/trip/sheets/PlPlaceTexts.tsx"] + }, + { + "feature": "Place add/edit form: phone, e-mail and opening hours", + "hooks": ["src/components/Planner/usePlaceHours.ts"], + "desktop": ["src/components/Planner/PlaceContactFields.tsx"], + "mobile": ["src/mobile/screens/trip/sheets/PlContactFields.tsx"] + }, { "feature": "Place detail actions", "hooks": ["src/components/Planner/usePlaceActions.ts"], diff --git a/client/src/api/tripTags.ts b/client/src/api/tripTags.ts index 786176e25..faa01d698 100644 --- a/client/src/api/tripTags.ts +++ b/client/src/api/tripTags.ts @@ -1,4 +1,4 @@ -import type { TripTagCreateRequest, TripTagListResponse, TripTagResponse } from '@trek/shared'; +import type { TripTagCreateRequest, TripTagListResponse, TripTagResponse, TripTagUpdateRequest } from '@trek/shared'; import apiClient from './client'; /** The tags a trip owns: every member reads them, and whoever may edit its places adds one. */ @@ -8,4 +8,7 @@ export const tripTagsApi = { /** Answers the trip's existing tag when it already has one of that name. */ create: (tripId: number | string, body: TripTagCreateRequest): Promise => apiClient.post(`/trips/${tripId}/tags`, body).then((r) => r.data), + /** A new name or colour for one of the trip's tags; every place carrying it shows the change. */ + update: (tripId: number | string, tagId: number, body: TripTagUpdateRequest): Promise => + apiClient.put(`/trips/${tripId}/tags/${tagId}`, body).then((r) => r.data), }; diff --git a/client/src/components/Planner/PlaceContactFields.test.tsx b/client/src/components/Planner/PlaceContactFields.test.tsx index 7e1213873..82ea80228 100644 --- a/client/src/components/Planner/PlaceContactFields.test.tsx +++ b/client/src/components/Planner/PlaceContactFields.test.tsx @@ -1,4 +1,4 @@ -// FE-PLANNER-CONTACT-001 to FE-PLANNER-CONTACT-002 +// FE-PLANNER-CONTACT-001 to FE-PLANNER-CONTACT-004 import { describe, expect, it, vi } from 'vitest' import { useState } from 'react' import userEvent from '@testing-library/user-event' @@ -87,5 +87,33 @@ describe('PlaceContactFields (#2472)', () => { // Still an e-mail field, so the keyboard and the browser's check stay. expect(screen.getByLabelText('E-mail')).toHaveAttribute('type', 'email') }) -}) + it('FE-PLANNER-CONTACT-003: a day opens around the clock with one switch, and an all-day lookup shows it on', async () => { + const user = userEvent.setup() + const onChange = vi.fn() + render() + await user.click(screen.getByRole('button', { name: 'Add opening hours' })) + + const allDay = screen.getByRole('switch', { name: 'Monday: Open 24 hours' }) + expect(allDay).toHaveAttribute('aria-checked', 'false') + await user.click(allDay) + expect(JSON.parse(onChange.mock.lastCall![1])[0]).toEqual({ closed: false, open: '00:00', close: '23:59' }) + expect(allDay).toHaveAttribute('aria-checked', 'true') + // The two time fields give way to the word. + expect(screen.queryByRole('textbox', { name: /Monday opens/ })).not.toBeInTheDocument() + expect(screen.getByText('Open 24 hours', { selector: 'span' })).toBeInTheDocument() + + // Closing the day turns the all-day switch off. + await user.click(screen.getByRole('switch', { name: 'Monday: Closed' })) + expect(JSON.parse(onChange.mock.lastCall![1])[0]).toEqual({ closed: true }) + expect(allDay).toHaveAttribute('aria-checked', 'false') + }) + + it('FE-PLANNER-CONTACT-004: looked-up hours open around the clock arrive with the all-day switch on', () => { + const suggested = Array.from({ length: 7 }, () => ({ closed: false, open: '00:00', close: '23:59' })) + render() + for (const day of ['Monday', 'Sunday']) { + expect(screen.getByRole('switch', { name: `${day}: Open 24 hours` })).toHaveAttribute('aria-checked', 'true') + } + }) +}) diff --git a/client/src/components/Planner/PlaceContactFields.tsx b/client/src/components/Planner/PlaceContactFields.tsx index c3a0ab34a..c23c6641f 100644 --- a/client/src/components/Planner/PlaceContactFields.tsx +++ b/client/src/components/Planner/PlaceContactFields.tsx @@ -1,14 +1,22 @@ -import { useEffect, useId, useRef, useState } from 'react' -import { Copy, Mail, Phone, RotateCcw, X } from 'lucide-react' +import { useId } from 'react' +import { Copy, DoorClosed, Mail, Phone, RotateCcw, X } from 'lucide-react' import type { PlaceClientOrigin, PlaceOpeningHours } from '@trek/shared' import CustomTimePicker from '../shared/CustomTimePicker' import { Tooltip } from '../shared/Tooltip' import { DialogSection, fs } from '../shared/DialogShell' import { AddRowButton, EditorField, GRID_2, INPUT } from '../shared/dialogParts' -import { cleanWeek, readWeek, weekdayNames, writeWeek } from './placeHours' +import { isAllDay, weekdayNames } from './placeHours' +import { usePlaceHours } from './usePlaceHours' import { useTranslation } from '../../i18n' import { NO_AUTOFILL } from '../../utils/noAutofill' +/** A closed or all-day row says so in place of the two times, in a box of their height. */ +const DAY_STATE = 'flex h-[38px] min-w-0 items-center rounded-[10px] border border-edge-faint bg-surface-tertiary px-3.5 font-medium text-content-muted' +/** The two switches after the times: square, as tall as a time field. */ +const DAY_BUTTON = 'grid h-[38px] w-[38px] flex-none place-items-center rounded-[10px] border font-semibold transition-colors' +const DAY_BUTTON_OFF = 'border-edge bg-surface-input text-content-faint hover:border-content-faint hover:text-content' +const DAY_BUTTON_ON = 'border-transparent bg-accent text-accent-text shadow-sm' + interface Props { /** Anchor for the "add by hand" jump from an empty search. */ id?: string @@ -36,45 +44,11 @@ interface Props { export function PlaceContactFields({ id: anchorId, phone, email, openingHours, onChange, suggestedHours }: Props) { const { t, locale } = useTranslation() const id = useId() - // The editor's own draft, so a half-typed time ("09:3") stays on screen while - // only finished times reach the place. - const [week, setDraft] = useState(() => readWeek(openingHours)) - const written = useRef(openingHours) - const [editing, setEditing] = useState(() => openingHours !== '') + const hours = usePlaceHours({ openingHours, suggestedHours, onChange: (value, origin) => onChange('opening_hours', value, origin) }) + const { week, editing } = hours const names = weekdayNames(locale, 'short') const longNames = weekdayNames(locale, 'long') - // A value from outside (a picked search result, a reopened place) replaces the draft. - useEffect(() => { - if (openingHours === written.current) return - written.current = openingHours - setDraft(readWeek(openingHours)) - if (openingHours) setEditing(true) - }, [openingHours]) - - const setWeek = (next: PlaceOpeningHours, origin?: PlaceClientOrigin) => { - setDraft(next) - const text = writeWeek(cleanWeek(next)) - written.current = text - onChange('opening_hours', text, origin) - } - const setDay = (i: number, patch: Partial) => - setWeek(week.map((day, d) => (d === i ? { ...day, ...patch } : day))) - const copyFirstToAll = () => setWeek(week.map(() => ({ ...week[0] }))) - const clearHours = () => { setWeek(readWeek('')); setEditing(false) } - - // Looked-up hours are taken over by a place that has none yet, once per lookup. - const adopted = useRef(null) - useEffect(() => { - if (!suggestedHours || adopted.current === suggestedHours) return - adopted.current = suggestedHours - if (written.current) return - setWeek(suggestedHours, 'enrichment') - setEditing(true) - // setWeek only reads refs and setters; the lookup is the trigger. - }, [suggestedHours]) - const canTakeOver = !!suggestedHours && writeWeek(suggestedHours) !== writeWeek(cleanWeek(week)) - return (
@@ -98,22 +72,22 @@ export function PlaceContactFields({ id: anchorId, phone, email, openingHours, o label={t('inspector.openingHours')} action={editing ? (
- {canTakeOver && ( + {hours.canTakeOver && ( - )} - - @@ -126,32 +100,45 @@ export function PlaceContactFields({ id: anchorId, phone, email, openingHours, o {week.map((day, i) => (
{names[i]} - {day.closed ? ( - {t('places.hoursClosed')} + {day.closed || isAllDay(day) ? ( + + {day.closed ? t('places.hoursClosed') : t('places.hoursAllDay')} + ) : ( -
-
- setDay(i, { open: v || undefined })} +
+
+ hours.setDay(i, { open: v || undefined })} aria-label={`${longNames[i]} ${t('places.hoursOpens')}`} />
- – -
- setDay(i, { close: v || undefined })} + – +
+ hours.setDay(i, { close: v || undefined })} aria-label={`${longNames[i]} ${t('places.hoursCloses')}`} />
)} - +
+ + + + + + +
))}
) : ( - setEditing(true)}>{t('places.hoursAdd')} + hours.setEditing(true)}>{t('places.hoursAdd')} )}
diff --git a/client/src/components/Planner/PlaceDetailsColumn.tsx b/client/src/components/Planner/PlaceDetailsColumn.tsx index 520504377..b2155ba30 100644 --- a/client/src/components/Planner/PlaceDetailsColumn.tsx +++ b/client/src/components/Planner/PlaceDetailsColumn.tsx @@ -238,7 +238,7 @@ export default function PlaceDetailsColumn({ // tiles, which is too small to tell a facade from a foyer. The column is // stretched to the form's height by the row it sits in, so the extra room // costs nothing that was being used. -