@@ -13,9 +13,6 @@ export function Profile() {
1313 const [ email , SetEmail ] = useState ( "" ) ;
1414 const [ password , SetPassword ] = useState ( "" ) ;
1515 const [ newPassword , SetNewPassword ] = useState ( "" ) ;
16-
17- // eslint-disable-next-line
18- const [ profileUpdateMsg , SetProfileUpdateMsg ] = useState ( "" ) ;
1916
2017 const ShowTeamPage = ( ) => {
2118 window . location . href = "/profile?mode=1" ;
@@ -32,6 +29,8 @@ export function Profile() {
3229 return ;
3330 }
3431
32+ let msgArea = document . getElementById ( 'msg_popup' ) ;
33+
3534 try {
3635 const response = await fetch ( `http://${ GetBackendHost ( ) } /user/update` , {
3736 method : "POST" ,
@@ -50,9 +49,34 @@ export function Profile() {
5049 // null | { message }
5150 const data = await response . json ( ) ;
5251 if ( data ) {
53- SetProfileUpdateMsg ( data . message ) ;
52+ if ( msgArea ) {
53+ msgArea . innerHTML = "<p style='color: green;'>" + data . message + "</p>" ;
54+ GetInfo ( ) ;
55+ }
5456 } else {
55- SetProfileUpdateMsg ( "Failed to Update Profile!" )
57+ if ( msgArea ) {
58+ msgArea . innerHTML = "<p style='color: red;'>Failed to Update Profile!</p>" ;
59+ }
60+ }
61+ } catch ( error ) {
62+ if ( msgArea ) {
63+ msgArea . innerHTML = "<p style='color: red;'>Failed to Update Profile!</p>" ;
64+ }
65+ console . error ( "Error sending request:" , error ) ;
66+ }
67+ }
68+
69+ async function GetInfo ( ) {
70+ try {
71+ const response = await fetch ( `http://${ GetBackendHost ( ) } /user/info` , {
72+ method : "GET" ,
73+ credentials : 'include' // ensures cookies are sent
74+ } ) ;
75+
76+ const data = await response . json ( ) ;
77+ if ( data ) {
78+ SetCurrentUsername ( data . username ) ;
79+ SetCurrentEmail ( data . email ) ;
5680 }
5781 } catch ( error ) {
5882 console . error ( "Error sending request:" , error ) ;
@@ -68,22 +92,6 @@ export function Profile() {
6892 }
6993 Verify ( ) ;
7094
71- async function GetInfo ( ) {
72- try {
73- const response = await fetch ( `http://${ GetBackendHost ( ) } /user/info` , {
74- method : "GET" ,
75- credentials : 'include' // ensures cookies are sent
76- } ) ;
77-
78- const data = await response . json ( ) ;
79- if ( data ) {
80- SetCurrentUsername ( data . username ) ;
81- SetCurrentEmail ( data . email ) ;
82- }
83- } catch ( error ) {
84- console . error ( "Error sending request:" , error ) ;
85- }
86- }
8795 GetInfo ( ) ;
8896 } , [ ] ) ; // run once on page-load
8997
@@ -108,6 +116,8 @@ export function Profile() {
108116 < header className = "App-header" >
109117 < div className = "container mt-5" >
110118 < div className = "row justify-content-center" >
119+ < div id = 'msg_popup' >
120+ </ div >
111121 < div className = "col-md-6" >
112122 < div className = "card shadow" >
113123 < div className = "card-body" >
0 commit comments