fix: validation
This commit is contained in:
@@ -10,7 +10,6 @@ import ChildInfoSelector from "./ChildInfoSelector"
|
||||
|
||||
import styles from "./child-selector.module.css"
|
||||
|
||||
import { BookingWidgetSchema } from "@/types/components/bookingWidget"
|
||||
import { SelectorProps } from "@/types/components/bookingWidget/guestsRoomsPicker"
|
||||
|
||||
export default function ChildSelector({
|
||||
@@ -21,26 +20,20 @@ export default function ChildSelector({
|
||||
}: SelectorProps) {
|
||||
const intl = useIntl()
|
||||
const childrenLabel = intl.formatMessage({ id: "Children" })
|
||||
const { setValue } = useFormContext<BookingWidgetSchema>()
|
||||
const { setValue } = useFormContext()
|
||||
|
||||
function increaseChildrenCount(roomIndex: number) {
|
||||
if (currentChildren.length < 5) {
|
||||
setValue(
|
||||
`rooms.${roomIndex}.child.${currentChildren.length}`,
|
||||
{
|
||||
age: -1,
|
||||
bed: -1,
|
||||
},
|
||||
{ shouldValidate: true }
|
||||
)
|
||||
setValue(`rooms.${roomIndex}.child.${currentChildren.length}`, {
|
||||
age: undefined,
|
||||
bed: undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
function decreaseChildrenCount(roomIndex: number) {
|
||||
if (currentChildren.length > 0) {
|
||||
currentChildren.pop()
|
||||
setValue(`rooms.${roomIndex}.child`, currentChildren, {
|
||||
shouldValidate: true,
|
||||
})
|
||||
setValue(`rooms.${roomIndex}.child`, currentChildren)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user