mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user