added lat and lng in cards
This commit is contained in:
parent
0a432f751c
commit
3d79125127
@ -28,12 +28,12 @@ export function StoreCard({ row, isDetailView = false, onEdit }: { row: Record<s
|
|||||||
const email = formatValue(emailObj?.email || row.email || row.store_email || row.business_email || '—');
|
const email = formatValue(emailObj?.email || row.email || row.store_email || row.business_email || '—');
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
const locObj = row.store_location as Record<string, unknown> | null;
|
const locObj = typeof row.store_location === 'string' ? (() => { try { return JSON.parse(row.store_location); } catch (e) { return null; } })() : (row.store_location as Record<string, unknown> | null);
|
||||||
const latRaw = locObj?.latitude || row.latitude;
|
const latRaw = locObj?.latitude ?? locObj?.lat ?? row.latitude ?? row.lat;
|
||||||
const lngRaw = locObj?.longitude || row.longitude;
|
const lngRaw = locObj?.longitude ?? locObj?.lng ?? row.longitude ?? row.lng;
|
||||||
const lat = formatValue(latRaw || '—');
|
const lat = formatValue(latRaw || '—');
|
||||||
const lng = formatValue(lngRaw || '—');
|
const lng = formatValue(lngRaw || '—');
|
||||||
const hasLocation = lat !== '—' && lng !== '—' && latRaw !== undefined && lngRaw !== undefined;
|
const hasLocation = lat !== '—' && lng !== '—' && latRaw !== undefined && lngRaw !== undefined && latRaw !== null && lngRaw !== null;
|
||||||
|
|
||||||
const areaName = formatValue(row.area || row.area_name || '—');
|
const areaName = formatValue(row.area || row.area_name || '—');
|
||||||
|
|
||||||
|
|||||||
@ -135,8 +135,10 @@ export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDet
|
|||||||
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 || (locObj as any).lat;
|
const rawLat = (locObj as any).latitude ?? (locObj as any).lat;
|
||||||
lng = (locObj as any).longitude || (locObj as any).lng;
|
const rawLng = (locObj as any).longitude ?? (locObj as any).lng;
|
||||||
|
lat = rawLat != null && rawLat !== '' ? Number(rawLat) : null;
|
||||||
|
lng = rawLng != null && rawLng !== '' ? Number(rawLng) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -608,7 +608,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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user