added geolocation input difference

This commit is contained in:
suryac 2026-08-06 16:27:13 +05:30
parent 9d0f4caf4e
commit dac346775d
5 changed files with 21 additions and 19 deletions

View File

@ -147,9 +147,9 @@ export function CallDetail({
const locStr = selectStore.store_location;
if (locStr) {
const loc = typeof locStr === 'string' ? JSON.parse(locStr) : locStr;
if (loc?.latitude && loc?.longitude) {
lat = loc.latitude;
lng = loc.longitude;
if ((loc?.lat || loc?.latitude) && (loc?.lng || loc?.longitude)) {
lat = loc.lat ?? loc.latitude;
lng = loc.lng ?? loc.longitude;
}
}
} catch (e) { }

View File

@ -122,8 +122,8 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) {
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).lat ?? (locObj as any).latitude;
lng = (locObj as any).lng ?? (locObj as any).longitude;
}
}

View File

@ -951,7 +951,7 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
<GeolocationInput
label={f.name}
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)}
/>
);

View File

@ -22,7 +22,7 @@ export function GeolocationInput({
label: string;
required?: boolean;
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 [error, setError] = useState<string | null>(null);
@ -53,8 +53,8 @@ export function GeolocationInput({
navigator.geolocation.getCurrentPosition(
(pos) => {
onChange({
latitude: pos.coords.latitude,
longitude: pos.coords.longitude,
lat: pos.coords.latitude,
lng: pos.coords.longitude,
accuracy: pos.coords.accuracy,
});
setLoading(false);
@ -96,8 +96,8 @@ export function GeolocationInput({
const confirmMapSelection = () => {
if (mapMarkerPos) {
onChange({
latitude: mapMarkerPos.lat,
longitude: mapMarkerPos.lng,
lat: mapMarkerPos.lat,
lng: mapMarkerPos.lng,
accuracy: 10,
});
setIsMapModalOpen(false);

View File

@ -8,8 +8,10 @@ import { CustomAdvancedMarker } from './CustomAdvancedMarker';
const libraries: ("marker")[] = ["marker"];
interface StoreLocation {
latitude: number;
longitude: number;
latitude?: number;
longitude?: number;
lat?: number;
lng?: number;
}
interface Store {
@ -141,8 +143,8 @@ export function DailyLogMap({
bounds.extend(userLocation);
stores.forEach(store => {
if (store.location) {
const lat = Number(store.location.latitude);
const lng = Number(store.location.longitude);
const lat = Number(store.location.lat ?? store.location.latitude);
const lng = Number(store.location.lng ?? store.location.longitude);
if (!isNaN(lat) && !isNaN(lng)) {
bounds.extend({ lat, lng });
}
@ -193,8 +195,8 @@ export function DailyLogMap({
{/* Stores Markers */}
{stores.map((store, index) => {
if (!store.location) return null;
const lat = Number(store.location.latitude);
const lng = Number(store.location.longitude);
const lat = Number(store.location.lat ?? store.location.latitude);
const lng = Number(store.location.lng ?? store.location.longitude);
if (isNaN(lat) || isNaN(lng)) return null;
return (
@ -208,9 +210,9 @@ export function DailyLogMap({
})}
{/* 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
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)}
>
<div className="p-1 max-w-[200px]">