@@ -8,6 +8,20 @@ import { supabase } from '../../config/supabase';
88import { useAuth } from '../../contexts/AuthContext' ;
99import { useLanguage } from '../../contexts/LanguageContext' ;
1010
11+ interface UserSettings {
12+ theme : 'light' | 'dark' | 'auto' ;
13+ language : string ;
14+ notifications_email : boolean ;
15+ notifications_push : boolean ;
16+ notifications_sms : boolean ;
17+ privacy_profile_public : boolean ;
18+ privacy_data_analytics : boolean ;
19+ team_auto_add_members : boolean ;
20+ api_rate_limit_alerts : boolean ;
21+ call_recording_default : boolean ;
22+ call_transcription_enabled : boolean ;
23+ }
24+
1125interface SettingsViewProps {
1226 isDark : boolean ;
1327}
@@ -50,6 +64,8 @@ export default function SettingsView({ isDark }: SettingsViewProps) {
5064 const [ saving , setSaving ] = useState ( false ) ;
5165 const [ saved , setSaved ] = useState ( false ) ;
5266 const [ exporting , setExporting ] = useState ( false ) ;
67+ const [ userSettings , setUserSettings ] = useState < UserSettings | null > ( null ) ;
68+ const [ savingSettings , setSavingSettings ] = useState ( false ) ;
5369 const [ profile , setProfile ] = useState < ProfileData > ( {
5470 display_name : '' , company_name : '' , phone : '' , timezone : 'UTC' ,
5571 email : '' , avatar_url : '' , credits_balance : 50 , created_at : '' , last_sign_in : '' ,
@@ -60,6 +76,16 @@ export default function SettingsView({ isDark }: SettingsViewProps) {
6076 } ) ;
6177 const [ deleteConfirm , setDeleteConfirm ] = useState ( false ) ;
6278
79+ const settingsBase = `${ import . meta. env . VITE_SUPABASE_URL } /functions/v1/user-settings` ;
80+
81+ const getAuthHeaders = useCallback ( async ( ) => {
82+ const { data : { session } } = await supabase . auth . getSession ( ) ;
83+ return {
84+ 'Authorization' : `Bearer ${ session ?. access_token } ` ,
85+ 'Content-Type' : 'application/json'
86+ } ;
87+ } , [ ] ) ;
88+
6389 const apiCall = useCallback ( async ( path : string , options ?: RequestInit ) => {
6490 const session = await supabase . auth . getSession ( ) ;
6591 const token = session . data . session ?. access_token ;
@@ -82,6 +108,40 @@ export default function SettingsView({ isDark }: SettingsViewProps) {
82108 return res . json ( ) ;
83109 } , [ ] ) ;
84110
111+ // Load user settings from endpoint
112+ const loadUserSettings = useCallback ( async ( ) => {
113+ try {
114+ const headers = await getAuthHeaders ( ) ;
115+ const res = await fetch ( settingsBase , { headers } ) ;
116+ const result = await res . json ( ) ;
117+ if ( res . ok && result . settings ) {
118+ setUserSettings ( result . settings ) ;
119+ }
120+ } catch ( err ) {
121+ console . error ( '[SettingsView] Failed to load user settings:' , err ) ;
122+ }
123+ } , [ getAuthHeaders ] ) ;
124+
125+ // Save user settings to endpoint
126+ const persistUserSettings = useCallback ( async ( settings : UserSettings ) => {
127+ try {
128+ setSavingSettings ( true ) ;
129+ const headers = await getAuthHeaders ( ) ;
130+ const res = await fetch ( settingsBase , {
131+ method : 'PUT' ,
132+ headers,
133+ body : JSON . stringify ( settings ) ,
134+ } ) ;
135+ if ( ! res . ok ) {
136+ console . error ( '[SettingsView] Failed to save settings' ) ;
137+ }
138+ } catch ( err ) {
139+ console . error ( '[SettingsView] Failed to persist settings:' , err ) ;
140+ } finally {
141+ setSavingSettings ( false ) ;
142+ }
143+ } , [ getAuthHeaders ] ) ;
144+
85145 useEffect ( ( ) => {
86146 ( async ( ) => {
87147 setLoading ( true ) ;
@@ -92,13 +152,16 @@ export default function SettingsView({ isDark }: SettingsViewProps) {
92152 ] ) ;
93153 if ( profileRes . profile ) setProfile ( profileRes . profile ) ;
94154 if ( prefsRes . preferences ) setNotifPrefs ( prefsRes . preferences ) ;
155+
156+ // Load user settings from Supabase
157+ await loadUserSettings ( ) ;
95158 } catch ( err ) {
96159 console . error ( '[SettingsView] load error:' , err ) ;
97160 } finally {
98161 setLoading ( false ) ;
99162 }
100163 } ) ( ) ;
101- } , [ apiCall , notifApiCall ] ) ;
164+ } , [ apiCall , notifApiCall , loadUserSettings ] ) ;
102165
103166 const saveProfile = async ( ) => {
104167 setSaving ( true ) ;
0 commit comments