refactor: url management in hotel reservation flow

This commit is contained in:
Christel Westerberg
2025-01-13 14:26:38 +01:00
parent 23ff0970e9
commit b2935114e3
48 changed files with 407 additions and 418 deletions

View File

@@ -29,8 +29,8 @@ export default function ChildInfoSelector({
index = 0,
roomIndex = 0,
}: ChildInfoSelectorProps) {
const ageFieldName = `rooms.${roomIndex}.child.${index}.age`
const bedFieldName = `rooms.${roomIndex}.child.${index}.bed`
const ageFieldName = `rooms.${roomIndex}.children.${index}.age`
const bedFieldName = `rooms.${roomIndex}.children.${index}.bed`
const intl = useIntl()
const ageLabel = intl.formatMessage({ id: "Age" })
const bedLabel = intl.formatMessage({ id: "Bed" })
@@ -38,11 +38,11 @@ export default function ChildInfoSelector({
const { setValue, formState } = useFormContext()
function updateSelectedBed(bed: number) {
setValue(`rooms.${roomIndex}.child.${index}.bed`, bed)
setValue(`rooms.${roomIndex}.children.${index}.bed`, bed)
}
function updateSelectedAge(age: number) {
setValue(`rooms.${roomIndex}.child.${index}.age`, age)
setValue(`rooms.${roomIndex}.children.${index}.age`, age)
const availableBedTypes = getAvailableBeds(age)
updateSelectedBed(availableBedTypes[0].value)
}
@@ -77,7 +77,7 @@ export default function ChildInfoSelector({
}
//@ts-expect-error: formState is typed with FormValues
const roomErrors = formState.errors.rooms?.[roomIndex]?.child?.[index]
const roomErrors = formState.errors.rooms?.[roomIndex]?.children?.[index]
const ageError = roomErrors?.age
const bedError = roomErrors?.bed

View File

@@ -24,7 +24,7 @@ export default function ChildSelector({
function increaseChildrenCount(roomIndex: number) {
if (currentChildren.length < 5) {
setValue(`rooms.${roomIndex}.child.${currentChildren.length}`, {
setValue(`rooms.${roomIndex}.children.${currentChildren.length}`, {
age: undefined,
bed: undefined,
})
@@ -33,7 +33,7 @@ export default function ChildSelector({
function decreaseChildrenCount(roomIndex: number) {
if (currentChildren.length > 0) {
currentChildren.pop()
setValue(`rooms.${roomIndex}.child`, currentChildren)
setValue(`rooms.${roomIndex}.children`, currentChildren)
}
}