added geolocation input difference
This commit is contained in:
parent
9d0f4caf4e
commit
dac346775d
@ -147,9 +147,9 @@ export function CallDetail({
|
|||||||
const locStr = selectStore.store_location;
|
const locStr = selectStore.store_location;
|
||||||
if (locStr) {
|
if (locStr) {
|
||||||
const loc = typeof locStr === 'string' ? JSON.parse(locStr) : locStr;
|
const loc = typeof locStr === 'string' ? JSON.parse(locStr) : locStr;
|
||||||
if (loc?.latitude && loc?.longitude) {
|
if ((loc?.lat || loc?.latitude) && (loc?.lng || loc?.longitude)) {
|
||||||
lat = loc.latitude;
|
lat = loc.lat ?? loc.latitude;
|
||||||
lng = loc.longitude;
|
lng = loc.lng ?? loc.longitude;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
|||||||
@ -122,8 +122,8 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) {
|
|||||||
try { locObj = JSON.parse(locObj); } catch (e) { }
|
try { locObj = JSON.parse(locObj); } catch (e) { }
|
||||||
}
|
}
|
||||||
if (locObj && typeof locObj === 'object') {
|
if (locObj && typeof locObj === 'object') {
|
||||||
lat = (locObj as any).latitude;
|
lat = (locObj as any).lat ?? (locObj as any).latitude;
|
||||||
lng = (locObj as any).longitude;
|
lng = (locObj as any).lng ?? (locObj as any).longitude;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -951,7 +951,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
<GeolocationInput
|
<GeolocationInput
|
||||||
label={f.name}
|
label={f.name}
|
||||||
required={f.mandatory}
|
required={f.mandatory}
|
||||||
value={(val as { latitude: number; longitude: number }) || null}
|
value={(val as { lat: number; lng: number }) || null}
|
||||||
onChange={(newVal) => handleFieldChange(f.id, newVal)}
|
onChange={(newVal) => handleFieldChange(f.id, newVal)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export function GeolocationInput({
|
|||||||
label: string;
|
label: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
value: { latitude?: number; longitude?: number; lat?: number; lng?: number; accuracy?: number } | null;
|
value: { latitude?: number; longitude?: number; lat?: number; lng?: number; accuracy?: number } | null;
|
||||||
onChange: (val: { latitude: number; longitude: number; accuracy?: number } | null) => void;
|
onChange: (val: { lat: number; lng: number; accuracy?: number } | null) => void;
|
||||||
}) {
|
}) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@ -53,8 +53,8 @@ export function GeolocationInput({
|
|||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
(pos) => {
|
(pos) => {
|
||||||
onChange({
|
onChange({
|
||||||
latitude: pos.coords.latitude,
|
lat: pos.coords.latitude,
|
||||||
longitude: pos.coords.longitude,
|
lng: pos.coords.longitude,
|
||||||
accuracy: pos.coords.accuracy,
|
accuracy: pos.coords.accuracy,
|
||||||
});
|
});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@ -96,8 +96,8 @@ export function GeolocationInput({
|
|||||||
const confirmMapSelection = () => {
|
const confirmMapSelection = () => {
|
||||||
if (mapMarkerPos) {
|
if (mapMarkerPos) {
|
||||||
onChange({
|
onChange({
|
||||||
latitude: mapMarkerPos.lat,
|
lat: mapMarkerPos.lat,
|
||||||
longitude: mapMarkerPos.lng,
|
lng: mapMarkerPos.lng,
|
||||||
accuracy: 10,
|
accuracy: 10,
|
||||||
});
|
});
|
||||||
setIsMapModalOpen(false);
|
setIsMapModalOpen(false);
|
||||||
|
|||||||
@ -8,8 +8,10 @@ import { CustomAdvancedMarker } from './CustomAdvancedMarker';
|
|||||||
const libraries: ("marker")[] = ["marker"];
|
const libraries: ("marker")[] = ["marker"];
|
||||||
|
|
||||||
interface StoreLocation {
|
interface StoreLocation {
|
||||||
latitude: number;
|
latitude?: number;
|
||||||
longitude: number;
|
longitude?: number;
|
||||||
|
lat?: number;
|
||||||
|
lng?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Store {
|
interface Store {
|
||||||
@ -141,8 +143,8 @@ export function DailyLogMap({
|
|||||||
bounds.extend(userLocation);
|
bounds.extend(userLocation);
|
||||||
stores.forEach(store => {
|
stores.forEach(store => {
|
||||||
if (store.location) {
|
if (store.location) {
|
||||||
const lat = Number(store.location.latitude);
|
const lat = Number(store.location.lat ?? store.location.latitude);
|
||||||
const lng = Number(store.location.longitude);
|
const lng = Number(store.location.lng ?? store.location.longitude);
|
||||||
if (!isNaN(lat) && !isNaN(lng)) {
|
if (!isNaN(lat) && !isNaN(lng)) {
|
||||||
bounds.extend({ lat, lng });
|
bounds.extend({ lat, lng });
|
||||||
}
|
}
|
||||||
@ -193,8 +195,8 @@ export function DailyLogMap({
|
|||||||
{/* Stores Markers */}
|
{/* Stores Markers */}
|
||||||
{stores.map((store, index) => {
|
{stores.map((store, index) => {
|
||||||
if (!store.location) return null;
|
if (!store.location) return null;
|
||||||
const lat = Number(store.location.latitude);
|
const lat = Number(store.location.lat ?? store.location.latitude);
|
||||||
const lng = Number(store.location.longitude);
|
const lng = Number(store.location.lng ?? store.location.longitude);
|
||||||
if (isNaN(lat) || isNaN(lng)) return null;
|
if (isNaN(lat) || isNaN(lng)) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -208,9 +210,9 @@ export function DailyLogMap({
|
|||||||
})}
|
})}
|
||||||
|
|
||||||
{/* Info Window for Selected Store */}
|
{/* Info Window for Selected Store */}
|
||||||
{selectedStore && selectedStore.location && !isNaN(Number(selectedStore.location.latitude)) && (
|
{selectedStore && selectedStore.location && !isNaN(Number(selectedStore.location.lat ?? selectedStore.location.latitude)) && (
|
||||||
<InfoWindow
|
<InfoWindow
|
||||||
position={{ lat: Number(selectedStore.location.latitude), lng: Number(selectedStore.location.longitude) }}
|
position={{ lat: Number(selectedStore.location.lat ?? selectedStore.location.latitude), lng: Number(selectedStore.location.lng ?? selectedStore.location.longitude) }}
|
||||||
onCloseClick={() => setSelectedStore(null)}
|
onCloseClick={() => setSelectedStore(null)}
|
||||||
>
|
>
|
||||||
<div className="p-1 max-w-[200px]">
|
<div className="p-1 max-w-[200px]">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user