refactor: url management in hotel reservation flow
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user