diff --git a/apps/open-spark/components/energyPurchaseForm/index.tsx b/apps/open-spark/components/energyPurchaseForm/index.tsx index 545601e7..74f454d5 100644 --- a/apps/open-spark/components/energyPurchaseForm/index.tsx +++ b/apps/open-spark/components/energyPurchaseForm/index.tsx @@ -11,7 +11,7 @@ import { VStack } from '@chakra-ui/react' import { QuestionOutlineIcon } from '@chakra-ui/icons' -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { FaMinus, FaPlus } from 'react-icons/fa6' import BecknButton from '@beckn-ui/molecules/src/components/button/Button' import axios from 'axios' @@ -49,10 +49,21 @@ export default function EnergyPurchaseForm({ preferenceType }: EnergyPurchaseFor const bearerToken = Cookies.get('authToken') || '' const router = useRouter() - const [energyUnits, setEnergyUnits] = useState(0) - const [pricePerUnit, setPricePerUnit] = useState(0) + const [tradeId, setTradeId] = useState() + const [energyUnits, setEnergyUnits] = useState(0) + const [pricePerUnit, setPricePerUnit] = useState(0) const [preferences, setPreferences] = useState({ solar: false, trustedSource: false }) + useEffect(() => { + const { tradeId, quantity, price, preferencesTags } = router.query + if (tradeId && quantity && price) { + setTradeId(tradeId as string) + setEnergyUnits(Number(quantity)) + setPricePerUnit(Number(price)) + setPreferences(JSON.parse(preferencesTags as any)) + } + }, []) + const handleInputChange = (setter: React.Dispatch>, value: number) => setter(Math.max(0, value)) diff --git a/apps/open-spark/pages/dashboard.tsx b/apps/open-spark/pages/dashboard.tsx index fa4fc08b..3eae6632 100644 --- a/apps/open-spark/pages/dashboard.tsx +++ b/apps/open-spark/pages/dashboard.tsx @@ -268,23 +268,38 @@ const Dashboard = () => { > - {currentTradeData.length < 0 ? ( + {currentTradeData.length === 0 ? ( <> ) : ( router.push(role === ROLE.PRODUCER ? '/sellingPreference' : '/buyingPreference')} + onClick={() => + router.push({ + pathname: role === ROLE.PRODUCER ? '/sellingPreference' : '/buyingPreference', + query: { + tradeId: currentTradeData[0]?.id, + quantity: currentTradeData[0].quantity, + price: currentTradeData[0].price, + preferencesTags: JSON.stringify({ + solar: preferencesTags.includes('Solar Energy'), + trustedSource: preferencesTags.includes('Trusted Source') + }) + } + }) + } /> )} - {currentTradeData.length < 0 ? ( - - ) : ( + + {currentTradeData.length === 0 ? ( + + ) : ( + <> { } ]} /> - )} - - {preferencesTags.length > 0 && ( - - - - {preferencesTags.map((tag, index) => ( - - {tag} - {/* handleRemoveTag(tag)} /> */} - - ))} - - - )} - {role !== ROLE.PRODUCER && ( - - - + + {preferencesTags.length > 0 && ( + - - - - - {currentStatusData.length > 0 ? ( - currentStatusData.map((data, index) => ( - + {preferencesTags.map((tag, index) => ( + + {tag} + {/* handleRemoveTag(tag)} /> */} + + ))} + + + )} + {role !== ROLE.PRODUCER && ( + + + + - )) - ) : ( - No status updates available - )} + {latestStatus?.status && ( + + )} + + + + {currentStatusData.length > 0 ? ( + currentStatusData.map((data, index) => ( + + )) + ) : ( + No status updates available + )} + + - - + )} + )} { return ( { flexDirection={'column'} > { )} - +