fix: validation
This commit is contained in:
@@ -9,44 +9,26 @@ import Counter from "../Counter"
|
||||
|
||||
import styles from "./adult-selector.module.css"
|
||||
|
||||
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
||||
import {
|
||||
Child,
|
||||
SelectorProps,
|
||||
} from "@/types/components/bookingWidget/guestsRoomsPicker"
|
||||
import { SelectorProps } from "@/types/components/bookingWidget/guestsRoomsPicker"
|
||||
|
||||
export default function AdultSelector({
|
||||
roomIndex = 0,
|
||||
currentAdults,
|
||||
currentChildren,
|
||||
childrenInAdultsBed,
|
||||
}: SelectorProps) {
|
||||
const name = `rooms.${roomIndex}.adults`
|
||||
const intl = useIntl()
|
||||
const adultsLabel = intl.formatMessage({ id: "Adults" })
|
||||
const { setValue } = useFormContext()
|
||||
|
||||
function increaseAdultsCount(roomIndex: number) {
|
||||
function increaseAdultsCount() {
|
||||
if (currentAdults < 6) {
|
||||
setValue(`rooms.${roomIndex}.adults`, currentAdults + 1)
|
||||
setValue(name, currentAdults + 1)
|
||||
}
|
||||
}
|
||||
|
||||
function decreaseAdultsCount(roomIndex: number) {
|
||||
function decreaseAdultsCount() {
|
||||
if (currentAdults > 1) {
|
||||
setValue(`rooms.${roomIndex}.adults`, currentAdults - 1)
|
||||
if (childrenInAdultsBed > currentAdults) {
|
||||
const toUpdateIndex = currentChildren.findIndex(
|
||||
(child: Child) => child.bed == ChildBedMapEnum.IN_ADULTS_BED
|
||||
)
|
||||
if (toUpdateIndex != -1) {
|
||||
setValue(
|
||||
`rooms.${roomIndex}.children.${toUpdateIndex}.bed`,
|
||||
currentChildren[toUpdateIndex].age < 3
|
||||
? ChildBedMapEnum.IN_CRIB
|
||||
: ChildBedMapEnum.IN_EXTRA_BED
|
||||
)
|
||||
}
|
||||
}
|
||||
setValue(name, currentAdults - 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,12 +39,8 @@ export default function AdultSelector({
|
||||
</Caption>
|
||||
<Counter
|
||||
count={currentAdults}
|
||||
handleOnDecrease={() => {
|
||||
decreaseAdultsCount(roomIndex)
|
||||
}}
|
||||
handleOnIncrease={() => {
|
||||
increaseAdultsCount(roomIndex)
|
||||
}}
|
||||
handleOnDecrease={decreaseAdultsCount}
|
||||
handleOnIncrease={increaseAdultsCount}
|
||||
disableDecrease={currentAdults == 1}
|
||||
disableIncrease={currentAdults == 6}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user