feat: Add street address to locations

Adds a street_address column to the locations table and updates the LocationSearch component to capture, store, and display full street addresses. This includes database migration, interface updates, and formatter logic.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-06 13:51:40 +00:00
parent c1683f9b02
commit 98fbc94476
5 changed files with 128 additions and 9 deletions

View File

@@ -14,17 +14,27 @@ interface LocationResult {
lat: string;
lon: string;
address: {
house_number?: string;
road?: string;
city?: string;
town?: string;
village?: string;
municipality?: string;
state?: string;
province?: string;
state_district?: string;
county?: string;
region?: string;
territory?: string;
country?: string;
country_code?: string;
postcode?: string;
};
}
interface SelectedLocation {
name: string;
street_address?: string;
city?: string;
state_province?: string;
country: string;
@@ -61,13 +71,14 @@ export function LocationSearch({ onLocationSelect, initialLocationId, className
const loadInitialLocation = async (locationId: string): Promise<void> => {
const { data, error } = await supabase
.from('locations')
.select('id, name, city, state_province, country, postal_code, latitude, longitude, timezone')
.select('id, name, street_address, city, state_province, country, postal_code, latitude, longitude, timezone')
.eq('id', locationId)
.maybeSingle();
if (data && !error) {
setSelectedLocation({
name: data.name,
street_address: data.street_address || undefined,
city: data.city || undefined,
state_province: data.state_province || undefined,
country: data.country,
@@ -150,21 +161,38 @@ export function LocationSearch({ onLocationSelect, initialLocationId, className
// Safely access address properties with fallback
const address = result.address || {};
const city = address.city || address.town || address.village;
const state = address.state || '';
const country = address.country || 'Unknown';
const locationName = city
? `${city}, ${state} ${country}`.trim()
: result.display_name;
// Extract street address components
const houseNumber = address.house_number || '';
const road = address.road || '';
const streetAddress = [houseNumber, road].filter(Boolean).join(' ').trim() || undefined;
// Extract city
const city = address.city || address.town || address.village || address.municipality;
// Extract state/province (try multiple fields for international support)
const state = address.state ||
address.province ||
address.state_district ||
address.county ||
address.region ||
address.territory;
const country = address.country || 'Unknown';
const postalCode = address.postcode;
// Build location name
const locationParts = [streetAddress, city, state, country].filter(Boolean);
const locationName = locationParts.join(', ');
// Build location data object (no database operations)
const locationData: SelectedLocation = {
name: locationName,
street_address: streetAddress,
city: city || undefined,
state_province: state || undefined,
country: country,
postal_code: address.postcode || undefined,
postal_code: postalCode || undefined,
latitude,
longitude,
timezone: undefined, // Will be set by server during approval if needed
@@ -249,6 +277,7 @@ export function LocationSearch({ onLocationSelect, initialLocationId, className
<div className="flex-1 min-w-0">
<p className="font-medium">{selectedLocation.name}</p>
<div className="text-sm text-muted-foreground space-y-1 mt-1">
{selectedLocation.street_address && <p>Street: {selectedLocation.street_address}</p>}
{selectedLocation.city && <p>City: {selectedLocation.city}</p>}
{selectedLocation.state_province && <p>State/Province: {selectedLocation.state_province}</p>}
<p>Country: {selectedLocation.country}</p>