diff --git a/components/profile/update/Settings.tsx b/components/profile/update/Settings.tsx index e1c4ec0c6..5c5b2725c 100644 --- a/components/profile/update/Settings.tsx +++ b/components/profile/update/Settings.tsx @@ -18,6 +18,7 @@ import { updateUserSettings, UserAppearance, UserNotifications, + UserPreferences, UserPrivacy, UserSettings, } from '@/lib/api/auth'; @@ -75,6 +76,15 @@ interface SettingsProps { const Settings = ({ visibleSections }: SettingsProps) => { const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); + + const sections = visibleSections || [ + 'notifications', + 'privacy', + 'appearance', + 'preferences', + ]; + const showAllSections = !visibleSections || visibleSections.length === 0; + const [settings, setSettings] = useState({ notifications: { emailNotifications: true, @@ -221,6 +231,21 @@ const Settings = ({ visibleSections }: SettingsProps) => { } }; + const onSubmitPreferences = async (data: UserPreferences) => { + setIsSaving(true); + try { + await updateUserSettings({ + preferences: data, + }); + toast.success('Preferences updated successfully'); + } catch { + toast.error('Failed to update preferences'); + } finally { + loadSettings(); + setIsSaving(false); + } + }; + if (isLoading) { return (
@@ -243,7 +268,7 @@ const Settings = ({ visibleSections }: SettingsProps) => {
{/* Notifications */} - {(!visibleSections || visibleSections.includes('notifications')) && ( + {sections.includes('notifications') && (
@@ -319,7 +344,7 @@ const Settings = ({ visibleSections }: SettingsProps) => { )} {/* Privacy */} - {(!visibleSections || visibleSections.includes('privacy')) && ( + {sections.includes('privacy') && (
@@ -670,7 +695,13 @@ const Settings = ({ visibleSections }: SettingsProps) => { Language { + field.onChange(value); + await onSubmitPreferences({ + ...form.getValues('preferences'), + timezone: value, + }); + }} defaultValue={field.value} >