feat: SW-276 Optimized code
This commit is contained in:
@@ -21,8 +21,11 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
||||
const intl = useIntl()
|
||||
const childrenLabel = intl.formatMessage({ id: "Children" })
|
||||
const { setValue, trigger } = useFormContext<BookingWidgetSchema>()
|
||||
const { children } = useGuestsRoomsStore((state) => state.rooms[roomIndex])
|
||||
const { increaseChildren, decreaseChildren } = useGuestsRoomsStore()
|
||||
const children = useGuestsRoomsStore(
|
||||
(state) => state.rooms[roomIndex].children
|
||||
)
|
||||
const increaseChildren = useGuestsRoomsStore.use.increaseChildren()
|
||||
const decreaseChildren = useGuestsRoomsStore.use.decreaseChildren()
|
||||
|
||||
function increaseChildrenCount(roomIndex: number) {
|
||||
if (children.length < 5) {
|
||||
@@ -36,11 +39,9 @@ export default function ChildSelector({ roomIndex = 0 }: ChildSelectorProps) {
|
||||
}
|
||||
function decreaseChildrenCount(roomIndex: number) {
|
||||
if (children.length > 0) {
|
||||
decreaseChildren(roomIndex)
|
||||
let newChildrenList = JSON.parse(JSON.stringify(children))
|
||||
newChildrenList.pop()
|
||||
const newChildrenList = decreaseChildren(roomIndex)
|
||||
setValue(`rooms.${roomIndex}.children`, newChildrenList)
|
||||
trigger()
|
||||
trigger("rooms")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user