feat: SW-276 Optimized code

This commit is contained in:
Hrishikesh Vaipurkar
2024-10-11 18:32:56 +02:00
parent d52a347904
commit b8f7f91fb4
7 changed files with 58 additions and 31 deletions

View File

@@ -30,13 +30,13 @@ export default function ChildInfoSelector({
const { adults, childrenInAdultsBed } = useGuestsRoomsStore(
(state) => state.rooms[roomIndex]
)
const {
isValidated,
updateChildAge,
updateChildBed,
increaseChildInAdultsBed,
decreaseChildInAdultsBed,
} = useGuestsRoomsStore()
const isValidated = useGuestsRoomsStore.use.isValidated()
const updateChildAge = useGuestsRoomsStore.use.updateChildAge()
const updateChildBed = useGuestsRoomsStore.use.updateChildBed()
const increaseChildInAdultsBed =
useGuestsRoomsStore.use.increaseChildInAdultsBed()
const decreaseChildInAdultsBed =
useGuestsRoomsStore.use.decreaseChildInAdultsBed()
const ageList = Array.from(Array(13).keys()).map((age) => ({
label: `${age}`,
@@ -48,6 +48,7 @@ export default function ChildInfoSelector({
setValue(`rooms.${roomIndex}.children.${index}.age`, age)
const availableBedTypes = getAvailableBeds(age)
updateSelectedBed(availableBedTypes[0].value)
trigger("rooms")
}
function updateSelectedBed(bed: number) {
@@ -58,7 +59,6 @@ export default function ChildInfoSelector({
}
updateChildBed(bed, roomIndex, index)
setValue(`rooms.${roomIndex}.children.${index}.bed`, bed)
trigger()
}
const allBedTypes: ChildBed[] = [
@@ -101,7 +101,7 @@ export default function ChildInfoSelector({
aria-label={ageLabel}
value={child.age}
onSelect={(key) => {
updateSelectedAge(parseInt(key.toString()))
updateSelectedAge(key as number)
}}
name={`rooms.${roomIndex}.children.${index}.age`}
placeholder={ageLabel}
@@ -115,7 +115,7 @@ export default function ChildInfoSelector({
aria-label={bedLabel}
value={child.bed}
onSelect={(key) => {
updateSelectedBed(parseInt(key.toString()))
updateSelectedBed(key as number)
}}
name={`rooms.${roomIndex}.children.${index}.age`}
placeholder={bedLabel}