feat: SW-276 Optimized code
This commit is contained in:
@@ -14,12 +14,13 @@ import ChildInfoSelector from "./ChildInfoSelector"
|
||||
|
||||
import styles from "./child-selector.module.css"
|
||||
|
||||
import { BookingWidgetSchema } from "@/types/components/bookingWidget"
|
||||
import { ChildSelectorProps } from "@/types/components/bookingWidget/guestsRoomsPicker"
|
||||
|
||||
export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
||||
const intl = useIntl()
|
||||
const childrenLabel = intl.formatMessage({ id: "Children" })
|
||||
const { setValue } = useFormContext()
|
||||
const { setValue, trigger } = useFormContext<BookingWidgetSchema>()
|
||||
const { children } = useGuestsRoomsStore((state) => state.rooms[roomIndex])
|
||||
const { increaseChildren, decreaseChildren } = useGuestsRoomsStore()
|
||||
|
||||
@@ -30,6 +31,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
||||
age: -1,
|
||||
bed: -1,
|
||||
})
|
||||
trigger()
|
||||
}
|
||||
}
|
||||
function decreaseChildrenCount(roomIndex: number) {
|
||||
@@ -38,6 +40,7 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
||||
let newChildrenList = JSON.parse(JSON.stringify(children))
|
||||
newChildrenList.pop()
|
||||
setValue(`rooms.${roomIndex}.children`, newChildrenList)
|
||||
trigger()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user