fix: validation

This commit is contained in:
Christel Westerberg
2024-11-14 11:41:56 +01:00
parent 7a3194f978
commit 9189d588d1
6 changed files with 120 additions and 94 deletions

View File

@@ -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)
}
}