diff --git a/src/components/settings/LocationTab.tsx b/src/components/settings/LocationTab.tsx index 441722ec..8de79914 100644 --- a/src/components/settings/LocationTab.tsx +++ b/src/components/settings/LocationTab.tsx @@ -17,7 +17,8 @@ const locationSchema = z.object({ preferred_pronouns: z.string().max(20).optional(), timezone: z.string(), preferred_language: z.string(), - location_id: z.string().optional() + personal_location: z.string().max(100).optional(), + home_park_id: z.string().optional() }); type LocationFormData = z.infer; interface AccessibilityOptions { @@ -35,7 +36,7 @@ export function LocationTab() { toast } = useToast(); const [loading, setLoading] = useState(false); - const [locations, setLocations] = useState([]); + const [parks, setParks] = useState([]); const [accessibility, setAccessibility] = useState({ font_size: 'medium', high_contrast: false, @@ -47,23 +48,26 @@ export function LocationTab() { preferred_pronouns: profile?.preferred_pronouns || '', timezone: profile?.timezone || 'UTC', preferred_language: profile?.preferred_language || 'en', - location_id: profile?.location_id || '' + personal_location: (profile as any)?.personal_location || '', + home_park_id: profile?.location_id || '' } }); useEffect(() => { - fetchLocations(); + fetchParks(); fetchAccessibilityPreferences(); }, [user]); - const fetchLocations = async () => { + + const fetchParks = async () => { try { - const { - data, - error - } = await supabase.from('locations').select('id, name, city, state_province, country').order('name'); + const { data, error } = await supabase + .from('parks') + .select('id, name, location_id, locations(city, state_province, country)') + .order('name'); + if (error) throw error; - setLocations(data || []); + setParks(data || []); } catch (error) { - console.error('Error fetching locations:', error); + console.error('Error fetching parks:', error); } }; const fetchAccessibilityPreferences = async () => { @@ -93,7 +97,8 @@ export function LocationTab() { preferred_pronouns: data.preferred_pronouns || null, timezone: data.timezone, preferred_language: data.preferred_language, - location_id: data.location_id || null, + personal_location: data.personal_location || null, + location_id: data.home_park_id || null, updated_at: new Date().toISOString() }).eq('user_id', user.id); @@ -147,21 +152,41 @@ export function LocationTab() {
- - +

+ Your personal location (optional, displayed as text) +

+
+ +
+ + - +

+ The theme park you visit most often or consider your "home" park +

diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index 59e5b91a..8b3ff5af 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -357,6 +357,7 @@ export type Database = { id: string location_id: string | null park_count: number | null + personal_location: string | null preferred_language: string | null preferred_pronouns: string | null privacy_level: string @@ -382,6 +383,7 @@ export type Database = { id?: string location_id?: string | null park_count?: number | null + personal_location?: string | null preferred_language?: string | null preferred_pronouns?: string | null privacy_level?: string @@ -407,6 +409,7 @@ export type Database = { id?: string location_id?: string | null park_count?: number | null + personal_location?: string | null preferred_language?: string | null preferred_pronouns?: string | null privacy_level?: string diff --git a/supabase/migrations/20250928204913_f36390d2-bdea-46d2-a49c-32abcf66fda1.sql b/supabase/migrations/20250928204913_f36390d2-bdea-46d2-a49c-32abcf66fda1.sql new file mode 100644 index 00000000..66243c5d --- /dev/null +++ b/supabase/migrations/20250928204913_f36390d2-bdea-46d2-a49c-32abcf66fda1.sql @@ -0,0 +1,3 @@ +-- Add personal_location field to profiles table for user's personal location text +ALTER TABLE public.profiles +ADD COLUMN personal_location TEXT; \ No newline at end of file