diff --git a/components/Forms/BookingWidget/FormContent/index.tsx b/components/Forms/BookingWidget/FormContent/index.tsx index 4c50474bd..40c7533b4 100644 --- a/components/Forms/BookingWidget/FormContent/index.tsx +++ b/components/Forms/BookingWidget/FormContent/index.tsx @@ -5,12 +5,11 @@ import { useIntl } from "react-intl" import { dt } from "@/lib/dt" import DatePicker from "@/components/DatePicker" +import GuestsRoomsPickerForm from "@/components/GuestsRoomsPicker" import { SearchIcon } from "@/components/Icons" import Button from "@/components/TempDesignSystem/Button" -import GuestsRoomsPickerForm from "@/components/GuestsRoomsPicker" import Caption from "@/components/TempDesignSystem/Text/Caption" -import Input from "./Input" import Search from "./Search" import Voucher from "./Voucher" diff --git a/components/GuestsRoomsPicker/AdultSelector/index.tsx b/components/GuestsRoomsPicker/AdultSelector/index.tsx index ef00e9332..579794ca8 100644 --- a/components/GuestsRoomsPicker/AdultSelector/index.tsx +++ b/components/GuestsRoomsPicker/AdultSelector/index.tsx @@ -3,7 +3,7 @@ import { useFormContext } from "react-hook-form" import { useIntl } from "react-intl" -import { guestsRoomsStore } from "@/stores/guests-rooms" +import { useGuestsRoomsStore } from "@/stores/guests-rooms" import { MinusIcon, PlusIcon } from "@/components/Icons" import Button from "@/components/TempDesignSystem/Button" @@ -13,15 +13,19 @@ import Caption from "@/components/TempDesignSystem/Text/Caption" import styles from "./adult-selector.module.css" import { BedTypeEnum } from "@/types/components/bookingWidget/enums" -import { AdultSelectorProps } from "@/types/components/bookingWidget/guestsRoomsPicker" +import { + AdultSelectorProps, + Child, +} from "@/types/components/bookingWidget/guestsRoomsPicker" export default function AdultSelector({ roomIndex = 0 }: AdultSelectorProps) { const intl = useIntl() const adultsLabel = intl.formatMessage({ id: "Adults" }) - const { setValue } = useFormContext() - const { adults, children, childrenInAdultsBed } = - guestsRoomsStore().rooms[roomIndex] - const { increaseAdults, decreaseAdults } = guestsRoomsStore() + const { register, setValue } = useFormContext() + const { adults, children, childrenInAdultsBed } = useGuestsRoomsStore( + (state) => state.rooms[roomIndex] + ) + const { increaseAdults, decreaseAdults } = useGuestsRoomsStore() function increaseAdultsCount(roomIndex: number) { if (adults < 6) { @@ -36,7 +40,7 @@ export default function AdultSelector({ roomIndex = 0 }: AdultSelectorProps) { setValue(`rooms.${roomIndex}.adults`, adults - 1) if (childrenInAdultsBed > adults) { const toUpdateIndex = children.findIndex( - (child, index) => child.bed == BedTypeEnum["In adults bed"] + (child: Child) => child.bed == BedTypeEnum.IN_ADULTS_BED ) if (toUpdateIndex != -1) { setValue( diff --git a/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx b/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx index bf64e7dd7..332a29a89 100644 --- a/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx +++ b/components/GuestsRoomsPicker/ChildSelector/ChildInfoSelector.tsx @@ -3,7 +3,7 @@ import { useFormContext } from "react-hook-form" import { useIntl } from "react-intl" -import { guestsRoomsStore } from "@/stores/guests-rooms" +import { useGuestsRoomsStore } from "@/stores/guests-rooms" import { ErrorCircleIcon } from "@/components/Icons" import Select from "@/components/TempDesignSystem/Select" @@ -27,30 +27,21 @@ export default function ChildInfoSelector({ const ageReqdErrMsg = intl.formatMessage({ id: "Child age is required" }) const bedLabel = intl.formatMessage({ id: "Bed" }) const { setValue } = useFormContext() - const { adults, childrenInAdultsBed } = guestsRoomsStore().rooms[roomIndex] + const { adults, childrenInAdultsBed } = useGuestsRoomsStore( + (state) => state.rooms[roomIndex] + ) const { isValidated, updateChildAge, updateChildBed, increaseChildInAdultsBed, decreaseChildInAdultsBed, - } = guestsRoomsStore() + } = useGuestsRoomsStore() - const ageList = [ - { label: "0", value: 0 }, - { label: "1", value: 1 }, - { label: "2", value: 2 }, - { label: "3", value: 3 }, - { label: "4", value: 4 }, - { label: "5", value: 5 }, - { label: "6", value: 6 }, - { label: "7", value: 7 }, - { label: "8", value: 8 }, - { label: "9", value: 9 }, - { label: "10", value: 10 }, - { label: "11", value: 11 }, - { label: "12", value: 12 }, - ] + const ageList = Array.from(Array(13).keys()).map((age) => ({ + label: `${age}`, + value: age, + })) function updateSelectedAge(age: number) { updateChildAge(age, roomIndex, index) @@ -62,9 +53,9 @@ export default function ChildInfoSelector({ } function updateSelectedBed(bed: number) { - if (bed == BedTypeEnum["In adults bed"]) { + if (bed == BedTypeEnum.IN_ADULTS_BED) { increaseChildInAdultsBed(roomIndex) - } else if (child.bed == BedTypeEnum["In adults bed"]) { + } else if (child.bed == BedTypeEnum.IN_ADULTS_BED) { decreaseChildInAdultsBed(roomIndex) } updateChildBed(bed, roomIndex, index) @@ -74,15 +65,15 @@ export default function ChildInfoSelector({ const allBedTypes: ChildBed[] = [ { label: intl.formatMessage({ id: "In adults bed" }), - value: BedTypeEnum["In adults bed"], + value: BedTypeEnum.IN_ADULTS_BED, }, { label: intl.formatMessage({ id: "In crib" }), - value: BedTypeEnum["In crib"], + value: BedTypeEnum.IN_CRIB, }, { label: intl.formatMessage({ id: "In extra bed" }), - value: BedTypeEnum["In extra bed"], + value: BedTypeEnum.IN_EXTRA_BED, }, ] @@ -136,7 +127,7 @@ export default function ChildInfoSelector({ {isValidated && child.age < 0 ? (