-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmyStore.tsx
More file actions
145 lines (140 loc) · 4.33 KB
/
myStore.tsx
File metadata and controls
145 lines (140 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import Router, { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
import { useLanguage } from '@hooks/useLanguage'
import { cartActions, checkoutActions, HomePageContent, TopSheet, useGeolocation } from '@beckn-ui/common'
import { Box, Flex } from '@chakra-ui/react'
import BecknButton from '@beckn-ui/molecules/src/components/button/Button'
import { buttonStyles } from '@components/constant'
import { MdOutlineKeyboardArrowRight } from 'react-icons/md'
import ShadowCardButton from '@components/buttonCard/ShadowCardButton'
import { useDispatch, useSelector } from 'react-redux'
import { RootState } from '@store/index'
const MyStore = () => {
const router = useRouter()
const type = useSelector((state: RootState) => state.navigation.type)
console.log('dank', type)
const { t } = useLanguage()
const dispatch = useDispatch()
const [searchTerm, setSearchTerm] = useState<string>('')
const apiKeyForGoogle = process.env.NEXT_PUBLIC_GOOGLE_API_KEY
const {
currentAddress,
error: currentLocationFetchError,
loading: loadingForCurrentAddress
} = useGeolocation(apiKeyForGoogle as string)
useEffect(() => {
if (localStorage) {
localStorage.clear()
dispatch(cartActions.clearCart())
dispatch(checkoutActions.clearState())
}
}, [])
const navigateToSearchResults = () => {
if (searchTerm) {
localStorage.setItem('optionTags', JSON.stringify({ name: searchTerm }))
router.push(`/search?searchTerm=${searchTerm}`)
}
}
const searchIconClickHandler = (e: React.MouseEvent) => {
if (searchTerm) {
navigateToSearchResults()
}
e.preventDefault()
}
const homeButtonName = type === 'RENT_AND_HIRE' ? 'Go Back' : 'Go Back Home'
return (
<Box
className="myStore-homepage"
mt="-60px"
>
<TopSheet
currentLocationFetchError={currentLocationFetchError}
loadingForCurrentAddress={loadingForCurrentAddress}
currentAddress={currentAddress}
t={key => t[key]}
/>
<HomePageContent
blockOrder={['header', 'description', 'searchInput']}
headerProps={{
name: type === 'RENT_AND_HIRE' ? t.rentAndHireHeading : t.myStoreHeading,
description: type === 'RENT_AND_HIRE' ? t.subTextForRenT : t.subText
}}
searchProps={{
searchPlaceholder:
type === 'RENT_AND_HIRE'
? 'Search for Batteries, Capacity, Availability'
: 'Search for Batteries, Solar panels...',
setSearchTerm: setSearchTerm,
onSearchIconClick: searchIconClickHandler,
onSearchInputEnterPress: navigateToSearchResults
}}
showFooter={false}
footerProps={{
poweredByLogoSrc: '',
poweredByText: ''
}}
/>
{type === 'MY_STORE' && (
<Flex
mt={'-80px'}
ml={'-10px'}
mr={'-10px'}
>
<ShadowCardButton
prefixIcon={
<img
src={'/images/pentagon.svg'}
alt={'orderHistory'}
/>
}
text={'My Orders'}
textStyle="start"
postIcon={<MdOutlineKeyboardArrowRight />}
handleClick={() => router.push(`/orderHistory`)}
sx={buttonStyles}
/>
</Flex>
)}
{type === 'RENT_AND_HIRE' && (
<Flex
mt={'-80px'}
ml={'-10px'}
mr={'-10px'}
>
<ShadowCardButton
prefixIcon={
<img
src={'/images/pentagon.svg'}
alt={'orderHistory'}
/>
}
text={'My Rentals'}
textStyle="start"
postIcon={<MdOutlineKeyboardArrowRight />}
handleClick={() => router.push(`/myRental`)}
sx={buttonStyles}
/>
</Flex>
)}
<Box
position={'absolute'}
bottom="calc(0px + 10px)"
w={'calc(100% - 40px)'}
maxW="40rem"
>
<BecknButton
text={homeButtonName}
handleClick={() => {
// if (type === 'RENT_AND_HIRE') {
// router.push('/rentAndHire')
// } else {
// Router.push('/')
// }
router.push('/')
}}
/>
</Box>
</Box>
)
}
export default MyStore