From 6a6221f9f3eca29554c39fe5acba505fe2f660fc Mon Sep 17 00:00:00 2001 From: abhishek Date: Mon, 27 Jul 2026 11:34:35 +0530 Subject: [PATCH] Auto-geocode tenant/store address into latitude/longitude on onboarding Both the tenant onboarding and store/branch forms only had free-text address fields with no coordinates captured, even though the backend already accepts and stores latitude/longitude on both tenants and tenantlocations. Wires in the existing keyless AddressAutocomplete (Nominatim) component used by UsersPanel so picking an address also geocodes it, and threads latitude/longitude through both create payloads. --- src/components/AdminConsole.tsx | 80 ++++++++++++++++++--------------- src/services/fiestaApi.ts | 4 ++ 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/components/AdminConsole.tsx b/src/components/AdminConsole.tsx index e0deb31..7330e67 100644 --- a/src/components/AdminConsole.tsx +++ b/src/components/AdminConsole.tsx @@ -32,6 +32,7 @@ import { } from '../services/fiestaQueries'; import { FIESTA_TENANT_ID, str as fstr, num as fnum } from '../services/fiestaApi'; import StoreQRView from './StoreQRView'; +import AddressAutocomplete, { type AddressResult } from './AddressAutocomplete'; export default function AdminConsole({ activeTab: propActiveTab, showHeader = true, onBack, tenantId }: { activeTab?: 'tenant' | 'store' | 'rider', showHeader?: boolean, onBack?: () => void, tenantId?: number }) { const [activeTab, setActiveTab] = useState<'tenant' | 'store' | 'rider'>(propActiveTab || 'tenant'); @@ -62,6 +63,10 @@ export default function AdminConsole({ activeTab: propActiveTab, showHeader = tr city: 'Coimbatore', state: 'Tamil Nadu', postcode: '', + // Populated from AddressAutocomplete's geocoding lookup, not typed — + // keeps HQ address and coordinates from drifting apart. + latitude: '', + longitude: '', // Primary outlet — created in the same call as the tenant, so a fresh // tenant is never left without a location to actually operate from. locationname: '', @@ -84,6 +89,10 @@ export default function AdminConsole({ activeTab: propActiveTab, showHeader = tr city: 'Coimbatore', state: 'Tamil Nadu', postcode: '', + // Populated from AddressAutocomplete's geocoding lookup, not typed — + // keeps the branch address and coordinates from drifting apart. + latitude: '', + longitude: '', contactno: '', email: '', opentime: '06:00:00', @@ -128,6 +137,34 @@ export default function AdminConsole({ activeTab: propActiveTab, showHeader = tr setTimeout(() => setCopiedSql(false), 2000); }; + // Address autocomplete → discrete fields + geocoded lat/long (or clear them + // when the field is emptied), same pattern UsersPanel uses for team members. + const handleTenantAddressSelect = (r: AddressResult | null) => { + setTenantForm((f) => ({ + ...f, + address: r?.address ?? '', + suburb: r?.suburb ?? '', + city: r?.city ?? '', + state: r?.state ?? '', + postcode: r?.postcode ?? '', + latitude: r?.latitude ?? '', + longitude: r?.longitude ?? '', + })); + }; + + const handleStoreAddressSelect = (r: AddressResult | null) => { + setStoreForm((f) => ({ + ...f, + address: r?.address ?? '', + suburb: r?.suburb ?? '', + city: r?.city ?? '', + state: r?.state ?? '', + postcode: r?.postcode ?? '', + latitude: r?.latitude ?? '', + longitude: r?.longitude ?? '', + })); + }; + // ---------------------------------------------------- // Submissions // ---------------------------------------------------- @@ -154,6 +191,8 @@ export default function AdminConsole({ activeTab: propActiveTab, showHeader = tr city: tenantForm.city, state: tenantForm.state, postcode: tenantForm.postcode, + latitude: tenantForm.latitude, + longitude: tenantForm.longitude, applocationid: tenantForm.applocationid, }, }); @@ -353,13 +392,7 @@ VALUES (${newUserId}, 1, 'Active', NOW());
- setTenantForm({ ...tenantForm, address: e.target.value })} - className="w-full border border-slate-250 rounded-xl p-3 bg-slate-50/40 hover:bg-slate-100 focus:bg-white outline-none focus:border-purple-500 transition-all font-semibold text-xs text-slate-800" - /> +
@@ -471,7 +504,7 @@ VALUES (${newUserId}, 1, 'Active', NOW()); )} )}