1
1
const profileUsername = document . getElementById ( "profilename" ) ;
2
2
const profileEmail = document . getElementById ( "profileEmail" ) ;
3
3
const editProfileButton = document . getElementById ( "editProfileButton" ) ;
4
+ const popup = document . getElementById ( "popup" ) ;
5
+ const overlay = document . getElementById ( "overlay" ) ;
6
+ const saveButton = document . getElementById ( "saveButton" ) ;
7
+ const cancelButton = document . getElementById ( "cancelButton" ) ;
8
+ const newNameInput = document . getElementById ( "newName" ) ;
9
+ const newEmailInput = document . getElementById ( "newEmail" ) ;
4
10
const loggedinUser = JSON . parse ( localStorage . getItem ( "loggedinUser" ) ) ;
5
11
6
12
if ( ! loggedinUser ) {
@@ -11,17 +17,38 @@ if (!loggedinUser) {
11
17
}
12
18
13
19
editProfileButton . addEventListener ( "click" , ( ) => {
14
- const newName = prompt ( "Enter your new Name:" , loggedinUser . name ) ;
15
- const newEmail = prompt ( "Enter your new email:" , loggedinUser . email ) ;
20
+ newNameInput . value = loggedinUser . name ;
21
+ newEmailInput . value = loggedinUser . email ;
22
+ popup . classList . add ( "active" ) ;
23
+ overlay . classList . add ( "active" ) ;
24
+ } ) ;
25
+
26
+ cancelButton . addEventListener ( "click" , ( ) => {
27
+ popup . classList . remove ( "active" ) ;
28
+ overlay . classList . remove ( "active" ) ;
29
+ } ) ;
30
+
31
+ saveButton . addEventListener ( "click" , ( ) => {
32
+ const newName = newNameInput . value . trim ( ) ;
33
+ const newEmail = newEmailInput . value . trim ( ) ;
16
34
17
35
if ( newName && newEmail ) {
18
36
loggedinUser . name = newName ;
19
37
loggedinUser . email = newEmail ;
20
38
localStorage . setItem ( "loggedinUser" , JSON . stringify ( loggedinUser ) ) ;
21
39
40
+ profileUsername . textContent = `Name: ${ loggedinUser . name } ` ;
41
+ profileEmail . textContent = `Email: ${ loggedinUser . email } ` ;
42
+
22
43
alert ( "Profile updated successfully!" ) ;
23
- window . location . href = "landing.html" ;
44
+ popup . classList . remove ( "active" ) ;
45
+ overlay . classList . remove ( "active" ) ;
24
46
} else {
25
47
alert ( "Please fill in all fields." ) ;
26
48
}
27
49
} ) ;
50
+
51
+ overlay . addEventListener ( "click" , ( ) => {
52
+ popup . classList . remove ( "active" ) ;
53
+ overlay . classList . remove ( "active" ) ;
54
+ } ) ;
0 commit comments