Skip to content

Commit

Permalink
Merge pull request #2780 from beckn/issue-open-spark
Browse files Browse the repository at this point in the history
feat(OPEN-SPARK): fixed prefix value of buying preference input and l…
  • Loading branch information
aniketceminds authored Dec 17, 2024
2 parents 77f9116 + bfc3844 commit 37129b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
36 changes: 22 additions & 14 deletions apps/open-spark/components/energyPurchaseForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor
setTradeId(tradeId as string)
setEnergyUnits(Number(quantity))
setPricePerUnit(Number(price))
setPreferences(JSON.parse(preferencesTags as any))
setPreferences(JSON.parse(preferencesTags as string))
}
}, [])

const handleInputChange = (setter: React.Dispatch<React.SetStateAction<number>>, value: number) =>
setter(Math.max(0, value))
}, [router.query])

const handleInputChange = (setter: React.Dispatch<React.SetStateAction<number>>, value: string) => {
const numericValue = value.replace(/[^0-9]/g, '') // Allow only digits
if (numericValue === '') {
setter(0) // Set to 0 if empty
} else {
setter(Number(numericValue)) // Convert to number
}
}

const handleCheckboxChange = (key: string, value: boolean) => setPreferences(prev => ({ ...prev, [key]: value }))

Expand Down Expand Up @@ -122,6 +128,7 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor
spacing={8}
align="stretch"
>
{/* Energy Units Input */}
<FormControl>
<HStack mb={2}>
<FormLabel
Expand All @@ -135,21 +142,21 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor
</HStack>
<HStack spacing={4}>
<Box
onClick={() => handleInputChange(setEnergyUnits, energyUnits + 1)}
onClick={() => handleInputChange(setEnergyUnits, (energyUnits + 1).toString())}
cursor="pointer"
>
<FaPlus />
</Box>
<Input
type="number"
value={energyUnits}
onChange={e => handleInputChange(setEnergyUnits, Number(e.target.value))}
value={energyUnits.toString()}
onChange={e => handleInputChange(setEnergyUnits, e.target.value)}
textAlign="center"
width="100px"
size="md"
/>
<Box
onClick={() => handleInputChange(setEnergyUnits, energyUnits - 1)}
onClick={() => handleInputChange(setEnergyUnits, (energyUnits - 1).toString())}
cursor="pointer"
>
<FaMinus />
Expand Down Expand Up @@ -178,21 +185,21 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor
</HStack>
<HStack spacing={4}>
<Box
onClick={() => handleInputChange(setPricePerUnit, pricePerUnit + 1)}
onClick={() => handleInputChange(setPricePerUnit, (pricePerUnit + 1).toString())}
cursor="pointer"
>
<FaPlus />
</Box>
<Input
type="number"
value={pricePerUnit}
onChange={e => handleInputChange(setPricePerUnit, Number(e.target.value))}
value={pricePerUnit.toString()}
onChange={e => handleInputChange(setPricePerUnit, e.target.value)}
textAlign="center"
width="100px"
size="md"
/>
<Box
onClick={() => handleInputChange(setPricePerUnit, pricePerUnit - 1)}
onClick={() => handleInputChange(setPricePerUnit, (pricePerUnit - 1).toString())}
cursor="pointer"
>
<FaMinus />
Expand All @@ -207,6 +214,7 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor
</FormControl>
<Divider />

{/* Preferences */}
<FormControl>
<FormLabel
fontSize="15"
Expand Down Expand Up @@ -237,7 +245,7 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor
<BecknButton
children="Submit"
handleClick={handleSubmit}
disabled={!isFormComplete}
disabled={!isFormComplete} // Button disabled if form incomplete
/>
</VStack>
</Box>
Expand Down
13 changes: 12 additions & 1 deletion apps/open-spark/pages/buyingPreference.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Box } from '@chakra-ui/react'
import PreferenceComponent from '../components/energyPurchaseForm'

const BuyingPreference = () => {
return <PreferenceComponent preferenceType={'buy'} />
return (
<Box
margin={'0 auto'}
maxW={['100%', '100%', '40rem', '40rem']}
className="hideScroll"
maxH={'calc(100vh - 80px)'}
overflowY="scroll"
>
<PreferenceComponent preferenceType={'buy'} />
</Box>
)
}

export default BuyingPreference

0 comments on commit 37129b7

Please sign in to comment.