feat: SW-276 Optimized code

This commit is contained in:
Hrishikesh Vaipurkar
2024-09-24 13:38:19 +02:00
parent 510880d697
commit 8a04f840a2
8 changed files with 21 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
.container { .container {
display: grid; display: grid;
grid-template-columns: auto auto auto auto; grid-template-columns: repeat(4, auto);
align-items: center; align-items: center;
} }

View File

@@ -15,18 +15,14 @@ export default function AdultSelector({
const adultsLabel = intl.formatMessage({ id: "Adults" }) const adultsLabel = intl.formatMessage({ id: "Adults" })
function decreaseAdults() { function decreaseAdults() {
if (adults <= 1) { if (adults > 1) {
return updateAdults(adults - 1)
} }
adults = adults - 1
updateAdults(adults)
} }
function increaseAdults() { function increaseAdults() {
if (adults > 5) { if (adults < 6) {
return updateAdults(adults + 1)
} }
adults = adults + 1
updateAdults(adults)
} }
return ( return (

View File

@@ -39,7 +39,7 @@ export default function ChildInfoSelector({
{ label: "12", value: 12 }, { label: "12", value: 12 },
] ]
function handleOnSelect(selectedKey: any, childInfo: string) { function handleOnSelect(selectedKey: number, childInfo: string) {
if (childInfo == "age") { if (childInfo == "age") {
child.age = selectedKey child.age = selectedKey
} else if (childInfo == "bed") { } else if (childInfo == "bed") {
@@ -58,7 +58,7 @@ export default function ChildInfoSelector({
aria-label={ageLabel} aria-label={ageLabel}
value={child.age} value={child.age}
onSelect={(key) => { onSelect={(key) => {
handleOnSelect(key, "age") handleOnSelect(parseInt(key.toString()), "age")
}} }}
name="age" name="age"
placeholder={ageLabel} placeholder={ageLabel}
@@ -73,7 +73,7 @@ export default function ChildInfoSelector({
aria-label={bedLabel} aria-label={bedLabel}
value={child.bed} value={child.bed}
onSelect={(key) => { onSelect={(key) => {
handleOnSelect(key, "bed") handleOnSelect(parseInt(key.toString()), "bed")
}} }}
name="bed" name="bed"
placeholder={bedLabel} placeholder={bedLabel}

View File

@@ -1,6 +1,6 @@
.container { .container {
display: grid; display: grid;
grid-template-columns: auto auto auto auto; grid-template-columns: repeat(4, auto);
align-items: center; align-items: center;
} }

View File

@@ -23,19 +23,17 @@ export default function ChildSelector({
const childrenLabel = intl.formatMessage({ id: "Children" }) const childrenLabel = intl.formatMessage({ id: "Children" })
function decreaseChildren() { function decreaseChildren() {
if (roomChildren.length < 1) { if (roomChildren.length > 0) {
return roomChildren.pop()
updateChildren(roomChildren)
} }
roomChildren.pop()
updateChildren(roomChildren)
} }
function increaseChildren() { function increaseChildren() {
if (roomChildren.length > 5) { if (roomChildren.length < 5) {
return roomChildren.push({ age: -1, bed: -1 })
updateChildren(roomChildren)
} }
roomChildren.push({ age: -1, bed: -1 })
updateChildren(roomChildren)
} }
function updateChildInfo(child: Child, index: number) { function updateChildInfo(child: Child, index: number) {

View File

@@ -1,3 +1,5 @@
"use client"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"

View File

@@ -81,10 +81,10 @@ export default function GuestsRoomsPicker({
Remove Room Remove Room
</Button> </Button>
) : null} */} ) : null} */}
<Divider></Divider> <Divider />
</section> </section>
))} ))}
<div className={styles.footer}> <footer className={styles.footer}>
{/* Not in MVP {/* Not in MVP
{selectedGuests.length < 4 ? ( {selectedGuests.length < 4 ? (
<Button intent="text" onClick={addRoom}> <Button intent="text" onClick={addRoom}>
@@ -94,7 +94,7 @@ export default function GuestsRoomsPicker({
<Button onClick={closePicker} disabled={!isValid}> <Button onClick={closePicker} disabled={!isValid}>
{doneLabel} {doneLabel}
</Button> </Button>
</div> </footer>
</> </>
) )
} }

View File

@@ -36,5 +36,5 @@
display: grid; display: grid;
gap: var(--Spacing-x1); gap: var(--Spacing-x1);
grid-template-columns: auto; grid-template-columns: auto;
margin: 10px 0 0; margin-top: 10px;
} }