@@ -4,12 +4,13 @@ import { useTranslations } from 'next-intl';
4
4
import dynamic from 'next/dynamic' ;
5
5
import Image from 'next/image' ;
6
6
import Link from 'next/link' ;
7
- import { useEffect , useState } from 'react' ;
7
+ import { useContext , useEffect , useState } from 'react' ;
8
8
9
9
import { Button } from '@/components/shared/Forms/Buttons/Buttons' ;
10
10
import SearchBar from '@/components/shared/SearchBar/SearchBar' ;
11
11
12
12
import logger from '../../../logger.config.mjs' ;
13
+ import { AppContext } from '../../../context/AppContextProvider' ;
13
14
14
15
const getDeviceLocation = async ( ) : Promise < { lat : number ; lng : number } > => {
15
16
return new Promise ( ( resolve , reject ) => {
@@ -24,7 +25,7 @@ const getDeviceLocation = async (): Promise<{ lat: number; lng: number }> => {
24
25
( error ) => {
25
26
reject ( error ) ;
26
27
} ,
27
- { enableHighAccuracy : true , timeout : 5000 , maximumAge : 0 }
28
+ { enableHighAccuracy : true , timeout : 5000 , maximumAge : 0 } ,
28
29
) ;
29
30
} else {
30
31
reject ( new Error ( 'Geolocation is not supported by this browser.' ) ) ;
@@ -34,24 +35,33 @@ const getDeviceLocation = async (): Promise<{ lat: number; lng: number }> => {
34
35
35
36
export default function Index ( ) {
36
37
const t = useTranslations ( ) ;
37
- const DynamicMap = dynamic ( ( ) => import ( '@/components/shared/map/Map' ) , { ssr : false } ) ;
38
+ const DynamicMap = dynamic ( ( ) => import ( '@/components/shared/map/Map' ) , {
39
+ ssr : false ,
40
+ } ) ;
38
41
39
- const [ mapCenter , setMapCenter ] = useState < { lat : number ; lng : number } > ( { lat : 0 , lng : 0 } ) ;
42
+ const [ mapCenter , setMapCenter ] = useState < { lat : number ; lng : number } > ( {
43
+ lat : 0 ,
44
+ lng : 0 ,
45
+ } ) ;
40
46
const [ zoomLevel , setZoomLevel ] = useState ( 2 ) ;
41
47
const [ locationError , setLocationError ] = useState < string | null > ( null ) ;
42
48
const [ searchQuery , setSearchQuery ] = useState < string > ( '' ) ;
43
49
const [ searchResults , setSearchResults ] = useState < any [ ] > ( [ ] ) ;
44
50
51
+ const { isSigningInUser } = useContext ( AppContext ) ;
52
+
45
53
// Default map center (example: New York City)
46
- const defaultMapCenter = { lat : 20 , lng : - 74.0060 } ;
54
+ const defaultMapCenter = { lat : 20 , lng : - 74.006 } ;
47
55
48
56
useEffect ( ( ) => {
49
57
const fetchLocationOnLoad = async ( ) => {
50
58
try {
51
59
const location = await getDeviceLocation ( ) ;
52
60
setMapCenter ( location ) ;
53
61
setZoomLevel ( 13 ) ;
54
- logger . info ( 'User location obtained successfully on initial load:' , { location } ) ;
62
+ logger . info ( 'User location obtained successfully on initial load:' , {
63
+ location,
64
+ } ) ;
55
65
} catch ( error ) {
56
66
logger . error ( 'Error getting location on initial load.' , { error } ) ;
57
67
setMapCenter ( defaultMapCenter ) ;
@@ -68,34 +78,74 @@ export default function Index() {
68
78
setMapCenter ( location ) ;
69
79
setZoomLevel ( 15 ) ;
70
80
setLocationError ( null ) ;
71
- logger . info ( 'User location obtained successfully on button click:' , { location } ) ;
81
+ logger . info ( 'User location obtained successfully on button click:' , {
82
+ location,
83
+ } ) ;
72
84
} catch ( error ) {
73
85
logger . error ( 'Error getting location on button click.' , { error } ) ;
74
- setLocationError ( t ( 'HOME.LOCATION_SERVICES.ENABLE_LOCATION_SERVICES_MESSAGE' ) ) ;
86
+ setLocationError (
87
+ t ( 'HOME.LOCATION_SERVICES.ENABLE_LOCATION_SERVICES_MESSAGE' ) ,
88
+ ) ;
75
89
}
76
90
} ;
77
91
78
92
// handle search query update from SearchBar and associated results
79
93
const handleSearch = ( query : string , results : any [ ] ) => {
80
94
setSearchQuery ( query ) ;
81
95
setSearchResults ( results ) ;
82
- }
96
+ } ;
83
97
84
98
return (
85
99
< >
86
- < DynamicMap center = { [ mapCenter . lat , mapCenter . lng ] } zoom = { zoomLevel } searchQuery = { searchQuery } searchResults = { searchResults || [ ] } />
100
+ < DynamicMap
101
+ center = { [ mapCenter . lat , mapCenter . lng ] }
102
+ zoom = { zoomLevel }
103
+ searchQuery = { searchQuery }
104
+ searchResults = { searchResults || [ ] }
105
+ />
87
106
< SearchBar page = { 'default' } onSearch = { handleSearch } />
88
107
< div className = "absolute bottom-8 z-10 flex justify-between gap-[22px] px-6 right-0 left-0 m-auto" >
89
- < Link href = "/seller/registration" >
108
+ { ! isSigningInUser ? (
109
+ < Link href = "/seller/registration" >
110
+ < Button
111
+ label = { '+ ' + t ( 'HOME.ADD_SELLER' ) }
112
+ styles = { {
113
+ borderRadius : '10px' ,
114
+ color : '#ffc153' ,
115
+ paddingLeft : '50px' ,
116
+ paddingRight : '50px' ,
117
+ } }
118
+ />
119
+ </ Link >
120
+ ) : (
90
121
< Button
91
- label = { "+ " + t ( 'HOME.ADD_SELLER' ) }
92
- styles = { { borderRadius : '10px' , color : '#ffc153' , paddingLeft : '50px' , paddingRight : '50px' } }
122
+ label = { '+ ' + t ( 'HOME.ADD_SELLER' ) }
123
+ styles = { {
124
+ borderRadius : '10px' ,
125
+ color : '#ffc153' ,
126
+ paddingLeft : '50px' ,
127
+ paddingRight : '50px' ,
128
+ } }
129
+ disabled
93
130
/>
94
- </ Link >
131
+ ) }
95
132
< Button
96
- icon = { < Image src = '/images/shared/my_location.png' width = { 30 } height = { 30 } alt = 'my location' /> }
97
- styles = { { borderRadius : '50%' , width : '40px' , height : '40px' , padding : '0px' } }
133
+ icon = {
134
+ < Image
135
+ src = "/images/shared/my_location.png"
136
+ width = { 30 }
137
+ height = { 30 }
138
+ alt = "my location"
139
+ />
140
+ }
141
+ styles = { {
142
+ borderRadius : '50%' ,
143
+ width : '40px' ,
144
+ height : '40px' ,
145
+ padding : '0px' ,
146
+ } }
98
147
onClick = { handleLocationButtonClick }
148
+ disabled = { isSigningInUser }
99
149
/>
100
150
</ div >
101
151
</ >
0 commit comments