From c337aac428a5b6bb0a80df20afc34ff2c7749bd3 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:21:46 +0000 Subject: [PATCH] Visual edit in Lovable --- src/components/settings/LocationTab.tsx | 175 +++++++----------------- 1 file changed, 51 insertions(+), 124 deletions(-) diff --git a/src/components/settings/LocationTab.tsx b/src/components/settings/LocationTab.tsx index d2f476bf..e812efb2 100644 --- a/src/components/settings/LocationTab.tsx +++ b/src/components/settings/LocationTab.tsx @@ -13,25 +13,27 @@ import { useToast } from '@/hooks/use-toast'; import { useAuth } from '@/hooks/useAuth'; import { supabase } from '@/integrations/supabase/client'; import { MapPin, Calendar, Globe, Accessibility } from 'lucide-react'; - const locationSchema = z.object({ preferred_pronouns: z.string().max(20).optional(), timezone: z.string(), preferred_language: z.string(), location_id: z.string().optional() }); - type LocationFormData = z.infer; - interface AccessibilityOptions { font_size: 'small' | 'medium' | 'large'; high_contrast: boolean; reduced_motion: boolean; } - export function LocationTab() { - const { user, profile, refreshProfile } = useAuth(); - const { toast } = useToast(); + const { + user, + profile, + refreshProfile + } = useAuth(); + const { + toast + } = useToast(); const [loading, setLoading] = useState(false); const [locations, setLocations] = useState([]); const [accessibility, setAccessibility] = useState({ @@ -39,7 +41,6 @@ export function LocationTab() { high_contrast: false, reduced_motion: false }); - const form = useForm({ resolver: zodResolver(locationSchema), defaultValues: { @@ -49,41 +50,33 @@ export function LocationTab() { location_id: profile?.location_id || '' } }); - useEffect(() => { fetchLocations(); fetchAccessibilityPreferences(); }, [user]); - const fetchLocations = async () => { try { - const { data, error } = await supabase - .from('locations') - .select('id, name, city, state_province, country') - .order('name'); - + const { + data, + error + } = await supabase.from('locations').select('id, name, city, state_province, country').order('name'); if (error) throw error; setLocations(data || []); } catch (error) { console.error('Error fetching locations:', error); } }; - const fetchAccessibilityPreferences = async () => { if (!user) return; - try { - const { data, error } = await supabase - .from('user_preferences') - .select('accessibility_options') - .eq('user_id', user.id) - .maybeSingle(); - + const { + data, + error + } = await supabase.from('user_preferences').select('accessibility_options').eq('user_id', user.id).maybeSingle(); if (error && error.code !== 'PGRST116') { console.error('Error fetching accessibility preferences:', error); return; } - if (data?.accessibility_options) { setAccessibility(data.accessibility_options as any); } @@ -91,25 +84,20 @@ export function LocationTab() { console.error('Error fetching accessibility preferences:', error); } }; - const onSubmit = async (data: LocationFormData) => { if (!user) return; - setLoading(true); try { - const { error } = await supabase - .from('profiles') - .update({ - preferred_pronouns: data.preferred_pronouns || null, - timezone: data.timezone, - preferred_language: data.preferred_language, - location_id: data.location_id || null, - updated_at: new Date().toISOString() - }) - .eq('user_id', user.id); - + const { + error + } = await supabase.from('profiles').update({ + preferred_pronouns: data.preferred_pronouns || null, + timezone: data.timezone, + preferred_language: data.preferred_language, + location_id: data.location_id || null, + updated_at: new Date().toISOString() + }).eq('user_id', user.id); if (error) throw error; - await refreshProfile(); toast({ title: 'Information updated', @@ -125,21 +113,17 @@ export function LocationTab() { setLoading(false); } }; - const saveAccessibilityPreferences = async () => { if (!user) return; - try { - const { error } = await supabase - .from('user_preferences') - .upsert([{ - user_id: user.id, - accessibility_options: accessibility as any, - updated_at: new Date().toISOString() - }]); - + const { + error + } = await supabase.from('user_preferences').upsert([{ + user_id: user.id, + accessibility_options: accessibility as any, + updated_at: new Date().toISOString() + }]); if (error) throw error; - toast({ title: 'Accessibility preferences saved', description: 'Your accessibility settings have been updated.' @@ -152,28 +136,14 @@ export function LocationTab() { }); } }; - const updateAccessibility = (key: keyof AccessibilityOptions, value: any) => { - setAccessibility(prev => ({ ...prev, [key]: value })); + setAccessibility(prev => ({ + ...prev, + [key]: value + })); }; - - const timezones = [ - 'UTC', - 'America/New_York', - 'America/Chicago', - 'America/Denver', - 'America/Los_Angeles', - 'America/Toronto', - 'Europe/London', - 'Europe/Berlin', - 'Europe/Paris', - 'Asia/Tokyo', - 'Asia/Shanghai', - 'Australia/Sydney' - ]; - - return ( -
+ const timezones = ['UTC', 'America/New_York', 'America/Chicago', 'America/Denver', 'America/Los_Angeles', 'America/Toronto', 'Europe/London', 'Europe/Berlin', 'Europe/Paris', 'Asia/Tokyo', 'Asia/Shanghai', 'Australia/Sydney']; + return
{/* Location Settings */}
@@ -191,22 +161,17 @@ export function LocationTab() {
- form.setValue('location_id', value)}> - {locations.map((location) => ( - + {locations.map(location => {location.name} {location.city && `, ${location.city}`} {location.state_province && `, ${location.state_province}`} {location.country && `, ${location.country}`} - - ))} + )}

@@ -216,19 +181,14 @@ export function LocationTab() {

- form.setValue('timezone', value)}> - {timezones.map((tz) => ( - + {timezones.map(tz => {tz} - - ))} + )}

@@ -258,34 +218,13 @@ export function LocationTab() {

- +

How you'd like others to refer to you.

-
- - -
+
@@ -297,7 +236,7 @@ export function LocationTab() {
- + {/* Accessibility Options */}
@@ -315,12 +254,7 @@ export function LocationTab() {
- updateAccessibility('font_size', value)}> @@ -339,10 +273,7 @@ export function LocationTab() { Increase contrast for better visibility

- updateAccessibility('high_contrast', checked)} - /> + updateAccessibility('high_contrast', checked)} />
@@ -352,10 +283,7 @@ export function LocationTab() { Minimize animations and transitions

- updateAccessibility('reduced_motion', checked)} - /> + updateAccessibility('reduced_motion', checked)} />
@@ -366,6 +294,5 @@ export function LocationTab() {
-
- ); +
; } \ No newline at end of file