Skip to content

Commit

Permalink
Merge pull request #2693 from beckn/feat/issue-2643-trade-details
Browse files Browse the repository at this point in the history
feat(open-spark): modified code to add trade details page
  • Loading branch information
aniketceminds authored Dec 6, 2024
2 parents 5ab673f + 014e135 commit 4776ae4
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 54 deletions.
52 changes: 11 additions & 41 deletions apps/open-spark/components/card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
import { Box, Card, CardBody, Text, Image, Flex } from '@chakra-ui/react'
import { Card, CardBody } from '@chakra-ui/react'
import React from 'react'

import styles from './Card.module.css'

export interface CardWithCheckBoxPropsModel {
paymentMethod: string
setChecked: React.Dispatch<React.SetStateAction<boolean>>
export interface CardBoxPropsModel {
handleOnclick?: () => void
childComponent: () => React.ReactElement<any, any> | null
}

const CardWithCheckBox: React.FC<CardWithCheckBoxPropsModel> = props => {
const handleChange = () => {
props.setChecked(prevValue => !prevValue)
}
const CardWithCheckBox: React.FC<CardBoxPropsModel> = props => {
const { childComponent, handleOnclick } = props

return (
<Card className="border_radius_all">
<Card
className="border_radius_all"
onClick={handleOnclick}
>
<CardBody
padding={'20px 10px'}
h="54px"
>
<Flex
className={styles.checkbox}
fontSize={'15px'}
alignItems={'center'}
columnGap={'14px'}
>
<input
type="checkbox"
id="checkbox"
onChange={handleChange}
/>
<label htmlFor="checkbox">
<Image
src={'/images/cash.svg'}
w={'62px'}
h={'40px'}
ml={'30px'}
position="fixed"
/>
<Text
position={'absolute'}
width={'50vw'}
marginLeft="100px"
fontSize={'15px'}
fontWeight={400}
>
{'Cash'}
</Text>
</label>
</Flex>
{childComponent()}
</CardBody>
</Card>
)
Expand Down
17 changes: 14 additions & 3 deletions apps/open-spark/components/currentTrade/CurrentTrade.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Input } from '@beckn-ui/molecules'
import { Flex } from '@chakra-ui/react'
import { Input, Typography } from '@beckn-ui/molecules'
import { Box, Flex } from '@chakra-ui/react'
import React from 'react'

interface CurrentTradeProps {
data: { name: string; label: string; value: string; disabled: boolean }[]
data: { name: string; label: string; value: string; disabled: boolean; symbol: string }[]
}

const CurrentTrade = (props: CurrentTradeProps) => {
Expand All @@ -25,6 +25,17 @@ const CurrentTrade = (props: CurrentTradeProps) => {
}}
label={`${item.label}`}
disabled={item.disabled}
rightElement={() => {
return (
<Box
cursor="pointer"
height="36px"
mt={'8px'}
>
<Typography text={item.symbol} />
</Box>
)
}}
/>
))}
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion apps/open-spark/components/documentsRenderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const RenderDocuments = (props: RenderDocumentsProps) => {
}
return newProgress
})
}, 500)
}, 200)
}
})
}
Expand Down
6 changes: 4 additions & 2 deletions apps/open-spark/components/header/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const headerNames: PathnameObjectType = {
'/myTrades': 'My Trades',
'/buyingPreference': 'Buying Preferences',
'/sellingPreference': 'Selling Preferences',
'/myDers': 'My DERs'
'/myDers': 'My DERs',
'/tradeDetails': 'No. of Units Sold'
}

const headerFrenchNames: PathnameObjectType = {
Expand All @@ -38,7 +39,8 @@ const headerBlackList = [
'/myTrades',
'/buyingPreference',
'/sellingPreference',
'/myDers'
'/myDers',
'/tradeDetails'
]

const bottomHeaderBlackList = ['/orderConfirmation', '/', '/feedback', '/welcome']
Expand Down
6 changes: 3 additions & 3 deletions apps/open-spark/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { useDispatch, useSelector } from 'react-redux'
import { ROLE } from '@lib/config'
import { useBapTradeDashboardQuery, useBppTradeDashboardQuery } from '@services/DashboardService'
const currentTradeMockData = [
{ name: 'energyToBuy', label: 'Energy to Buy', value: '210 (KWh)', disabled: true },
{ name: 'priceFixed', label: 'Price Fixed', value: '08 ₹/units', disabled: true }
{ name: 'energyToBuy', label: 'Energy to Buy', value: '210', disabled: true, symbol: '(KWh)' },
{ name: 'priceFixed', label: 'Price Fixed', value: '08', disabled: true, symbol: '₹/units' }
]
const currentStatusmockData = [
{
Expand Down Expand Up @@ -158,7 +158,7 @@ const Homepage = () => {
</Flex>
{emptyState ? <EmptyCurrentTrade /> : <CurrentTrade data={currentTradeMockData} />}
</Box>
<Box mt={'15px'}>
<Box>
<Typography
text="Preferences"
fontSize="15"
Expand Down
154 changes: 152 additions & 2 deletions apps/open-spark/pages/myTrades.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,157 @@
import React from 'react'
import { Typography } from '@beckn-ui/molecules'
import { Box, Flex, HStack, Image } from '@chakra-ui/react'
import Card from '@components/card/Card'
import React, { useEffect, useState } from 'react'
import successIcon from '@public/images/green_tick_icon.svg'
import inProgressIcon from '@public/images/in_progress_icon.svg'
import failedIcon from '@public/images/failed_icon.svg'
import { currencyMap, ROUTE_TYPE } from '@lib/config'
import Cookies from 'js-cookie'
import axios from '@services/axios'
import { useDispatch, useSelector } from 'react-redux'
import { AuthRootState } from '@store/auth-slice'
import { feedbackActions, formatDate } from '@beckn-ui/common'
import { useRouter } from 'next/router'

type TradeStatus = 'SUCCESS' | 'RECEIVED' | 'FAILED'

interface TradeMetaData {
quantity: string
price: number
orderId: string
time: string
status: TradeStatus
}

const statusMap = {
SUCCESS: { icon: successIcon, color: '#5EC401', label: 'Success' },
RECEIVED: { icon: inProgressIcon, color: '#BD942B', label: 'In progress' },
FAILED: { icon: failedIcon, color: '#E93324', label: 'Failed' }
}

const MyTrades = () => {
return <div>MyTrades</div>
const bearerToken = Cookies.get('authToken')
const strapiUrl = process.env.NEXT_PUBLIC_STRAPI_URL

const [checked, setChecked] = useState<boolean>(false)
const [tradeList, setTradeList] = useState<TradeMetaData[]>([])
const [isLoading, setIsLoading] = useState(false)

const dispatch = useDispatch()
const router = useRouter()
const { role } = useSelector((state: AuthRootState) => state.auth)

const getAllTradeList = async () => {
const requestOptions = {
method: 'GET',
headers: { Authorization: `Bearer ${bearerToken}` },
withCredentials: true
}

setIsLoading(true)

await axios
.get(`${strapiUrl}${ROUTE_TYPE[role!]}/trade`, requestOptions)
.then(response => {
const result = response.data
if (result.length === 0) {
return setTradeList([])
}
const list = result.map((data: any) => {
return {
orderId: data.id,
price: data.price || 0,
quantity: data.quantity,
time: data.createdAt,
status: data.status
}
})

setTradeList(list)
})
.catch(error => {
setIsLoading(false)
console.error('Error fetching trade data:', error)
})
}

useEffect(() => {
getAllTradeList()
}, [])

const handleOnCardClick = (data: TradeMetaData) => {
router.push({ pathname: '/tradeDetails', query: { id: data.orderId } })
}

if (tradeList.length === 0) {
return (
<Box
display={'grid'}
height={'calc(100vh - 300px)'}
alignContent={'center'}
>
<Typography
text="No trade history found."
fontWeight="400"
fontSize="15px"
style={{ placeSelf: 'center' }}
/>
</Box>
)
}

return (
<Box
margin={'0 auto'}
maxW={['100%', '100%', '40rem', '40rem']}
className="hideScroll"
maxH={'calc(100vh - 80px)'}
overflowY="scroll"
>
<Flex
gap="1rem"
flexDirection={'column'}
>
{tradeList.map(trade => {
return (
<Card
handleOnclick={() => handleOnCardClick(trade)}
childComponent={() => {
return (
<Flex
flexDirection={'column'}
gap="2px"
>
<Typography
text={`${trade.quantity} Units`}
fontWeight="600"
/>
<Typography text={`${currencyMap.INR}${trade.price}`} />
<Flex justifyContent={'space-between'}>
<Flex flexDir={'row'}>
<Typography text={`Order ID: ${trade.orderId}`} />
<Typography text={`, ${formatDate(trade.time, 'hh:mm a')}`} />
</Flex>
<Flex gap="4px">
<Image
src={`${statusMap[trade.status].icon}`}
alt="status_icon"
/>
<Typography
color={statusMap[trade.status].color}
text={`${statusMap[trade.status].label}`}
/>
</Flex>
</Flex>
</Flex>
)
}}
/>
)
})}
</Flex>
</Box>
)
}

export default MyTrades
Loading

0 comments on commit 4776ae4

Please sign in to comment.