Skip to content

Commit 5ce18a2

Browse files
committed
disabled seller registaration btn and location track btn while user is signing in
1 parent 1838f11 commit 5ce18a2

File tree

1 file changed

+66
-16
lines changed

1 file changed

+66
-16
lines changed

src/app/[locale]/page.tsx

+66-16
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { useTranslations } from 'next-intl';
44
import dynamic from 'next/dynamic';
55
import Image from 'next/image';
66
import Link from 'next/link';
7-
import { useEffect, useState } from 'react';
7+
import { useContext, useEffect, useState } from 'react';
88

99
import { Button } from '@/components/shared/Forms/Buttons/Buttons';
1010
import SearchBar from '@/components/shared/SearchBar/SearchBar';
1111

1212
import logger from '../../../logger.config.mjs';
13+
import { AppContext } from '../../../context/AppContextProvider';
1314

1415
const getDeviceLocation = async (): Promise<{ lat: number; lng: number }> => {
1516
return new Promise((resolve, reject) => {
@@ -24,7 +25,7 @@ const getDeviceLocation = async (): Promise<{ lat: number; lng: number }> => {
2425
(error) => {
2526
reject(error);
2627
},
27-
{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }
28+
{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 },
2829
);
2930
} else {
3031
reject(new Error('Geolocation is not supported by this browser.'));
@@ -34,24 +35,33 @@ const getDeviceLocation = async (): Promise<{ lat: number; lng: number }> => {
3435

3536
export default function Index() {
3637
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+
});
3841

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+
});
4046
const [zoomLevel, setZoomLevel] = useState(2);
4147
const [locationError, setLocationError] = useState<string | null>(null);
4248
const [searchQuery, setSearchQuery] = useState<string>('');
4349
const [searchResults, setSearchResults] = useState<any[]>([]);
4450

51+
const { isSigningInUser } = useContext(AppContext);
52+
4553
// Default map center (example: New York City)
46-
const defaultMapCenter = { lat: 20, lng: -74.0060 };
54+
const defaultMapCenter = { lat: 20, lng: -74.006 };
4755

4856
useEffect(() => {
4957
const fetchLocationOnLoad = async () => {
5058
try {
5159
const location = await getDeviceLocation();
5260
setMapCenter(location);
5361
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+
});
5565
} catch (error) {
5666
logger.error('Error getting location on initial load.', { error });
5767
setMapCenter(defaultMapCenter);
@@ -68,34 +78,74 @@ export default function Index() {
6878
setMapCenter(location);
6979
setZoomLevel(15);
7080
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+
});
7284
} catch (error) {
7385
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+
);
7589
}
7690
};
7791

7892
// handle search query update from SearchBar and associated results
7993
const handleSearch = (query: string, results: any[]) => {
8094
setSearchQuery(query);
8195
setSearchResults(results);
82-
}
96+
};
8397

8498
return (
8599
<>
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+
/>
87106
<SearchBar page={'default'} onSearch={handleSearch} />
88107
<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+
) : (
90121
<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
93130
/>
94-
</Link>
131+
)}
95132
<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+
}}
98147
onClick={handleLocationButtonClick}
148+
disabled={isSigningInUser}
99149
/>
100150
</div>
101151
</>

0 commit comments

Comments
 (0)