sub-task/ SW-695 Prefill Guests data in booking widget

This commit is contained in:
Hrishikesh Vaipurkar
2024-10-25 08:50:23 +02:00
parent 31da31b72d
commit 05d353e224
18 changed files with 342 additions and 182 deletions

View File

@@ -26,7 +26,7 @@ export default function ChildInfoSelector({
const ageLabel = intl.formatMessage({ id: "Age" })
const ageReqdErrMsg = intl.formatMessage({ id: "Child age is required" })
const bedLabel = intl.formatMessage({ id: "Bed" })
const { setValue, trigger } = useFormContext()
const { setValue } = useFormContext()
const { adults, childrenInAdultsBed } = useGuestsRoomsStore(
(state) => state.rooms[roomIndex]
)
@@ -51,10 +51,11 @@ export default function ChildInfoSelector({
function updateSelectedAge(age: number) {
updateChildAge(age, roomIndex, index)
setValue(`rooms.${roomIndex}.children.${index}.age`, age)
setValue(`rooms.${roomIndex}.child.${index}.age`, age, {
shouldValidate: true,
})
const availableBedTypes = getAvailableBeds(age)
updateSelectedBed(availableBedTypes[0].value)
trigger("rooms")
}
function updateSelectedBed(bed: number) {
@@ -64,7 +65,7 @@ export default function ChildInfoSelector({
decreaseChildInAdultsBed(roomIndex)
}
updateChildBed(bed, roomIndex, index)
setValue(`rooms.${roomIndex}.children.${index}.bed`, bed)
setValue(`rooms.${roomIndex}.child.${index}.bed`, bed)
}
const allBedTypes: ChildBed[] = [
@@ -109,8 +110,9 @@ export default function ChildInfoSelector({
onSelect={(key) => {
updateSelectedAge(key as number)
}}
name={`rooms.${roomIndex}.children.${index}.age`}
name={`rooms.${roomIndex}.child.${index}.age`}
placeholder={ageLabel}
maxHeight={150}
/>
</div>
<div>
@@ -123,7 +125,7 @@ export default function ChildInfoSelector({
onSelect={(key) => {
updateSelectedBed(key as number)
}}
name={`rooms.${roomIndex}.children.${index}.age`}
name={`rooms.${roomIndex}.child.${index}.age`}
placeholder={bedLabel}
/>
) : null}

View File

@@ -19,9 +19,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
const intl = useIntl()
const childrenLabel = intl.formatMessage({ id: "Children" })
const { setValue, trigger } = useFormContext<BookingWidgetSchema>()
const children = useGuestsRoomsStore(
(state) => state.rooms[roomIndex].children
)
const children = useGuestsRoomsStore((state) => state.rooms[roomIndex].child)
const increaseChildren = useGuestsRoomsStore(
(state) => state.increaseChildren
)
@@ -32,18 +30,22 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
function increaseChildrenCount(roomIndex: number) {
if (children.length < 5) {
increaseChildren(roomIndex)
setValue(`rooms.${roomIndex}.children.${children.length}`, {
age: -1,
bed: -1,
})
trigger("rooms")
setValue(
`rooms.${roomIndex}.child.${children.length}`,
{
age: -1,
bed: -1,
},
{ shouldValidate: true }
)
}
}
function decreaseChildrenCount(roomIndex: number) {
if (children.length > 0) {
const newChildrenList = decreaseChildren(roomIndex)
setValue(`rooms.${roomIndex}.children`, newChildrenList)
trigger("rooms")
setValue(`rooms.${roomIndex}.child`, newChildrenList, {
shouldValidate: true,
})
}
}