fix(planner): a place added from a collection keeps its category (#3074)

The place form guessed the category of a picked place from its kind, so a
place taken from a collection inside a trip lost the category it was saved
under, while adding it from the collection kept it. A picked place that
carries a category this server has now brings it along; a category chosen
in the form by hand still wins.
This commit is contained in:
Maurice
2026-11-12 23:06:35 +01:00
parent f13a0aa6ee
commit a39f3fe40c
3 changed files with 49 additions and 1 deletions
@@ -19,7 +19,7 @@ import { weekFromPeriods } from './placeHours'
import type { PlaceOpeningHours } from '@trek/shared'
import {
DEFAULT_FORM, endsBeforeStart, findDuplicatePlace, formPin, mergeResult, parseCoordinatePair, placeEditForm, placeFormPayload,
prefillForm, type PlaceFormData, type PlacePrefill,
prefillForm, savedCategoryId, type PlaceFormData, type PlacePrefill,
} from './PlaceFormModal.helpers'
import { useNewCategory, usePlaceForm } from './usePlaceForm'
import { usePlaceSearch } from './usePlaceSearch'
@@ -233,6 +233,12 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
setForm(prev => {
const merged = mergeResult(prev, result, autoFilledRef.current)
if (prev.category_id && !categoryGuessedRef.current) return merged
// A place from a collection brings the category it was saved under (#3074).
const saved = savedCategoryId(result, categories || [])
if (saved) {
categoryGuessedRef.current = false
return { ...merged, category_id: saved }
}
return { ...merged, category_id: guessedCategory(result) }
})
setPickedSource(label)