diff --git a/src/components/dv/StoreDetail.tsx b/src/components/dv/StoreDetail.tsx index b2b4444..8ff3f9a 100644 --- a/src/components/dv/StoreDetail.tsx +++ b/src/components/dv/StoreDetail.tsx @@ -6,6 +6,10 @@ import { Spinner } from '../reusable/Spinner'; import { EmptyState } from '../reusable/EmptyState'; import { ArrowLeft, Store, User, Truck, MapPin, TrendingUp, Phone, Navigation2, Edit3, Navigation, Mail, FileText, Hash } from 'lucide-react'; import { Button } from '../buttons/Button'; +import { useJsApiLoader, GoogleMap } from '@react-google-maps/api'; +import { CustomAdvancedMarker } from '../maps/CustomAdvancedMarker'; + +const libraries: ("marker")[] = ["marker"]; export interface StoreDetailProps { instanceId: string | number; @@ -19,6 +23,14 @@ export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDet const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const isLocalhost = typeof window !== 'undefined' && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'); + + const { isLoaded } = useJsApiLoader({ + id: 'google-map-script', + googleMapsApiKey: isLocalhost ? '' : (import.meta.env.VITE_GOOGLE_MAPS_API_KEY || ''), + libraries + }); + useEffect(() => { let live = true; async function run() { @@ -123,8 +135,8 @@ export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDet try { locObj = JSON.parse(locObj); } catch (e) { } } if (locObj && typeof locObj === 'object') { - lat = (locObj as any).latitude; - lng = (locObj as any).longitude; + lat = (locObj as any).latitude || (locObj as any).lat; + lng = (locObj as any).longitude || (locObj as any).lng; } } @@ -399,15 +411,25 @@ export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDet
{lat && lng ? ( <> - + {!isLoaded ? ( +
+ +
+ ) : ( + + + + )}
window.open(`https://maps.google.com/maps?q=${lat},${lng}`, '_blank')} diff --git a/src/components/forms/fields/GeolocationInput.tsx b/src/components/forms/fields/GeolocationInput.tsx index 50e7e80..bde9137 100644 --- a/src/components/forms/fields/GeolocationInput.tsx +++ b/src/components/forms/fields/GeolocationInput.tsx @@ -26,7 +26,7 @@ export function GeolocationInput({ }) { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); - + const [isMapModalOpen, setIsMapModalOpen] = useState(false); const [mapMarkerPos, setMapMarkerPos] = useState<{ lat: number; lng: number } | null>(null); @@ -162,15 +162,15 @@ export function GeolocationInput({ {required && !hasValidCoords && } {isMapModalOpen && ( - setIsMapModalOpen(false)} + setIsMapModalOpen(false)} title="Select Location on Map" width="lg" >

Click on the map to place a pin at the desired store location.

- +
{!isLoaded ? (