Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(OPEN-SPARK): fixed prefix value of buying preference input and l… #2780

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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