@@ -5,10 +5,8 @@ import { useEffect } from 'react';
55import { useState } from 'react' ;
66import { getCookie } from '@/utils/request' ;
77import General from '@/components/settingComponents/generalPage' ;
8- import Security from '@/components/settingComponents/securityPage' ;
98import Sidebar from '@/components/settingComponents/sidebar' ;
10- import Billing from '@/components/settingComponents/billingPage' ;
11- import Preferences from '@/components/settingComponents/preferencesPage' ;
9+
1210import {
1311 updatePassword ,
1412 getAuth ,
@@ -38,11 +36,6 @@ export default function Dashboard() {
3836 const [ billing , setbilling ] = useState ( false ) ;
3937 const [ username , setUsername ] = useState ( '' ) ;
4038
41-
42- const [ selectedImage , setSelectedImage ] = useState ( null ) ;
43- const [ isPopupOpen , setIsPopupOpen ] = useState ( false ) ;
44- const [ pfp , setPfp ] = useState ( `https://robohash.org/KshitijIsCool.png?set=set1&size=150x150` ) ;
45-
4639 var pfpString = '' ;
4740 var pfpChanged = false ;
4841
@@ -165,7 +158,32 @@ export default function Dashboard() {
165158 }
166159 }
167160
161+ function savePreferences ( ) {
162+ document . getElementById ( 'savePreferences' ) . innerHTML = 'Saving...' ;
163+
164+ var data = JSON . stringify ( {
165+ FRIEND_ACCEPT : document . getElementById ( 'friend-notif' ) . checked ,
166+ CHALLENGE_VERIFY : document . getElementById ( 'challenge-notif' ) . checked ,
167+ } ) ;
168+
169+ var xhr = new XMLHttpRequest ( ) ;
170+
171+ xhr . addEventListener ( 'readystatechange' , function ( ) {
172+ if ( this . readyState === 4 ) {
173+ document . getElementById ( 'savePreferences' ) . innerHTML = 'Save' ;
174+ }
175+ } ) ;
176+
177+ xhr . open ( 'PUT' , `${ process . env . NEXT_PUBLIC_API_URL } /account/preferences` ) ;
178+
179+ xhr . setRequestHeader ( 'Content-Type' , 'application/json' ) ;
180+ let token = getCookie ( ) ;
181+ xhr . setRequestHeader ( 'Authorization' , 'Bearer ' + token ) ;
182+ xhr . withCredentials = true ;
168183
184+ xhr . send ( data ) ;
185+ }
186+
169187 function loadPreferences ( ) {
170188 // WARNING: For GET requests, body is set to null by browsers.
171189
@@ -218,34 +236,12 @@ export default function Dashboard() {
218236
219237 { general && (
220238 < div id = "general" className = "" >
221- { /*DIV CONTAINING THE BODY OF GENERAL SECTION*/ }
239+ { /*CONTAINING THE BODY OF GENERAL SECTION*/ }
222240 < General />
223241 </ div >
224242 ) }
225243
226- { billing && (
227- < div id = "general" className = "" >
228- { /*DIV CONTAINING BODY OF THE BILLING SECTION*/ }
229- < Billing />
230- </ div >
231- ) }
232-
233- { security && (
234- < div id = "security" className = "" >
235- { /*DIV CONTAINING BODY OF THE SECURITY SECTION*/ }
236- < Security />
237- </ div >
238- ) }
239-
240-
241- { preferences && (
242- < div id = "preferences" className = "" >
243-
244- { /*DIV CONTAINING BODY OF THE PREFERENCES SECTION*/ }
245- < Preferences />
246-
247- </ div >
248- ) }
244+
249245 </ div >
250246
251247 < Footer />
0 commit comments