From a3f6635633e2bdfe0db1f129f5e88eeca4e67b11 Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 17 Nov 2026 08:44:05 +0100 Subject: [PATCH] feat(places): colour tags, tabs for the texts and opening hours on the phone Tags on the place form are pills in their own colour, with a palette under the dot that recolours a tag for the whole trip (PUT /trips/:id/tags/:id was there already, the client now reaches it through repo and store) and a custom colour field of its own instead of the system picker. A new tag is made in a colour picked the same way. Description, notes and the note for one day's visit sit in one card under a switch, each with a line on where the text shows up; the day tab is named after its day and is only there with one visit in context. Nothing about the three fields changes underneath. Opening hours get a switch for open around the clock next to closed. Google writes a place open all week as one period on Sunday that never closes; it read as Sunday open and every other day closed, and now opens every day. The phone form follows the desktop: category as one field with a list, tags in one field, the texts switch, and phone, e-mail and opening hours, which it did not have. The hours and the text tabs are shared hooks (usePlaceHours, usePlaceTextTabs). Files and costs on the phone sheets are drawn as fields like the rest, and the paste hint, a keyboard shortcut a phone has no use for, is gone with its key. --- client/scripts/feature-pairs.json | 12 ++ client/src/api/tripTags.ts | 5 +- .../Planner/PlaceContactFields.test.tsx | 32 ++- .../components/Planner/PlaceContactFields.tsx | 103 +++++----- .../components/Planner/PlaceDetailsColumn.tsx | 17 +- .../Planner/PlaceFormModal.test.tsx | 12 +- .../src/components/Planner/PlaceFormModal.tsx | 95 +++------ .../components/Planner/PlaceFormTags.test.tsx | 51 ++++- .../src/components/Planner/PlaceFormTags.tsx | 188 +++++++++++++----- .../Planner/PlaceFormTexts.test.tsx | 66 ++++++ .../src/components/Planner/PlaceFormTexts.tsx | 122 ++++++++++++ .../components/Planner/PlaceImagePicker.tsx | 18 +- .../src/components/Planner/PlaceInspector.tsx | 2 +- .../components/Planner/PlaceRefreshPill.tsx | 3 +- .../components/Planner/TagColorField.test.tsx | 73 +++++++ .../src/components/Planner/TagColorField.tsx | 162 +++++++++++++++ .../components/Planner/TagColorPopover.tsx | 131 ++++++++++++ .../src/components/Planner/placeHours.test.ts | 28 ++- client/src/components/Planner/placeHours.ts | 24 ++- .../src/components/Planner/usePlaceHours.ts | 86 ++++++++ client/src/components/Planner/usePlaceTags.ts | 30 ++- .../components/Planner/usePlaceTextTabs.ts | 71 +++++++ client/src/components/shared/dialogParts.tsx | 20 +- .../trip/sheets/MBookingFilesCosts.tsx | 1 - .../screens/trip/sheets/MLinkedCosts.tsx | 18 +- .../screens/trip/sheets/MPlaceEditSheet.tsx | 110 +++++----- .../screens/trip/sheets/PlCategoryPicker.tsx | 161 ++++++++------- .../trip/sheets/PlContactFields.test.tsx | 65 ++++++ .../screens/trip/sheets/PlContactFields.tsx | 186 +++++++++++++++++ .../screens/trip/sheets/PlFileAttach.tsx | 41 +--- .../screens/trip/sheets/PlPlaceTexts.test.tsx | 48 +++++ .../screens/trip/sheets/PlPlaceTexts.tsx | 65 ++++++ .../screens/trip/sheets/PlSheetChrome.tsx | 31 ++- .../screens/trip/sheets/PlTags.test.tsx | 28 ++- .../src/mobile/screens/trip/sheets/PlTags.tsx | 185 +++++++++++++---- client/src/repo/tripTagRepo.ts | 11 +- client/src/store/slices/tripTagsSlice.ts | 10 +- client/src/utils/colorSpace.test.ts | 32 +++ client/src/utils/colorSpace.ts | 52 +++++ client/src/utils/placeTags.test.ts | 12 +- client/src/utils/placeTags.ts | 15 +- .../unit/mobile/trip/MPlaceEditSheet.test.tsx | 52 ++--- .../mobile/trip/PlCategoryPicker.test.tsx | 52 +++-- .../unit/mobile/trip/PlFileAttach.test.tsx | 7 +- shared/src/i18n/ar/files.ts | 1 - shared/src/i18n/ar/places.ts | 17 ++ shared/src/i18n/az/files.ts | 1 - shared/src/i18n/az/places.ts | 17 ++ shared/src/i18n/br/files.ts | 1 - shared/src/i18n/br/places.ts | 17 ++ shared/src/i18n/ca/files.ts | 1 - shared/src/i18n/ca/places.ts | 18 ++ shared/src/i18n/cs/files.ts | 1 - shared/src/i18n/cs/places.ts | 17 ++ shared/src/i18n/de/files.ts | 1 - shared/src/i18n/de/places.ts | 18 ++ shared/src/i18n/en/files.ts | 1 - shared/src/i18n/en/places.ts | 17 ++ shared/src/i18n/es/files.ts | 1 - shared/src/i18n/es/places.ts | 18 ++ shared/src/i18n/et/files.ts | 1 - shared/src/i18n/et/places.ts | 18 ++ shared/src/i18n/fr/files.ts | 1 - shared/src/i18n/fr/places.ts | 18 ++ shared/src/i18n/gr/files.ts | 1 - shared/src/i18n/gr/places.ts | 18 ++ shared/src/i18n/he/files.ts | 1 - shared/src/i18n/he/places.ts | 17 ++ shared/src/i18n/hu/files.ts | 1 - shared/src/i18n/hu/places.ts | 18 ++ shared/src/i18n/id/files.ts | 1 - shared/src/i18n/id/places.ts | 18 ++ shared/src/i18n/it/files.ts | 1 - shared/src/i18n/it/places.ts | 18 ++ shared/src/i18n/ja/files.ts | 1 - shared/src/i18n/ja/places.ts | 17 ++ shared/src/i18n/ko/files.ts | 1 - shared/src/i18n/ko/places.ts | 17 ++ shared/src/i18n/nl/files.ts | 1 - shared/src/i18n/nl/places.ts | 18 ++ shared/src/i18n/pl/files.ts | 1 - shared/src/i18n/pl/places.ts | 17 ++ shared/src/i18n/ru/files.ts | 1 - shared/src/i18n/ru/places.ts | 18 ++ shared/src/i18n/sk/files.ts | 1 - shared/src/i18n/sk/places.ts | 17 ++ shared/src/i18n/sv/files.ts | 1 - shared/src/i18n/sv/places.ts | 17 ++ shared/src/i18n/th/files.ts | 1 - shared/src/i18n/th/places.ts | 16 ++ shared/src/i18n/tr/files.ts | 1 - shared/src/i18n/tr/places.ts | 17 ++ shared/src/i18n/uk/files.ts | 1 - shared/src/i18n/uk/places.ts | 17 ++ shared/src/i18n/vi/files.ts | 1 - shared/src/i18n/vi/places.ts | 18 ++ shared/src/i18n/zh-TW/files.ts | 1 - shared/src/i18n/zh-TW/places.ts | 17 ++ shared/src/i18n/zh/files.ts | 1 - shared/src/i18n/zh/places.ts | 17 ++ 100 files changed, 2538 insertions(+), 510 deletions(-) create mode 100644 client/src/components/Planner/PlaceFormTexts.test.tsx create mode 100644 client/src/components/Planner/PlaceFormTexts.tsx create mode 100644 client/src/components/Planner/TagColorField.test.tsx create mode 100644 client/src/components/Planner/TagColorField.tsx create mode 100644 client/src/components/Planner/TagColorPopover.tsx create mode 100644 client/src/components/Planner/usePlaceHours.ts create mode 100644 client/src/components/Planner/usePlaceTextTabs.ts create mode 100644 client/src/mobile/screens/trip/sheets/PlContactFields.test.tsx create mode 100644 client/src/mobile/screens/trip/sheets/PlContactFields.tsx create mode 100644 client/src/mobile/screens/trip/sheets/PlPlaceTexts.test.tsx create mode 100644 client/src/mobile/screens/trip/sheets/PlPlaceTexts.tsx create mode 100644 client/src/utils/colorSpace.test.ts create mode 100644 client/src/utils/colorSpace.ts 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. -