@@ -74,34 +74,33 @@ <h2>Create an Account or Sign In</h2>
7474
7575 < script src ="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js "> </ script >
7676 < script >
77- // Fetch interests and populate the dropdown
77+
7878 axios . get ( 'http://localhost:8000/api/interest' )
7979 . then ( response => {
8080 const interestsSelect = document . querySelector ( 'select[name="interests"]' ) ;
8181 const interests = response . data ;
8282
8383 interests . forEach ( interest => {
8484 const option = document . createElement ( 'option' ) ;
85- option . value = interest . interestName ; // Get only the interest name
86- option . textContent = interest . interestName ; // Display only the interest name
85+ option . value = interest . interestName ;
86+ option . textContent = interest . interestName ;
8787 interestsSelect . appendChild ( option ) ;
8888 } ) ;
8989 } )
9090 . catch ( error => {
9191 console . error ( error ) ;
9292 } ) ;
9393
94- // Handle form submission for Sign Up
94+
9595 document . getElementById ( 'register-form' ) . addEventListener ( 'submit' , function ( event ) {
9696 event . preventDefault ( ) ;
9797 const form = event . target ;
9898 const formData = new FormData ( form ) ;
9999
100- // Get all selected interest options
100+
101101 const selectedOptions = form . elements [ 'interests' ] . selectedOptions ;
102102 const selectedInterests = Array . from ( selectedOptions ) . map ( option => option . value ) ;
103103
104- // Create the payload object
105104 const payload = {
106105 firstName : formData . get ( 'firstName' ) ,
107106 lastName : formData . get ( 'lastName' ) ,
@@ -113,38 +112,37 @@ <h2>Create an Account or Sign In</h2>
113112
114113 axios . post ( 'http://localhost:8000/api/user' , payload )
115114 . then ( response => {
116- // Handle the response, e.g., show a success message or redirect to the dashboard
115+
117116 console . log ( 'User registered successfully!' ) ;
118- // Redirect to dashboard.html
117+
119118 window . location . href = 'event.html' ;
120119 } )
121120 . catch ( error => {
122- // Handle the error, e.g., display an error message
121+
123122 console . error ( error ) ;
124123 } ) ;
125124 } ) ;
126125
127- // Handle form submission for Sign In
126+
128127 document . getElementById ( 'login-form' ) . addEventListener ( 'submit' , function ( event ) {
129128 event . preventDefault ( ) ;
130129 const form = event . target ;
131130 const formData = new FormData ( form ) ;
132131
133- // Create the payload object
134132 const payload = {
135133 email : formData . get ( 'your_email_1' ) ,
136134 password : formData . get ( 'password_1' )
137135 } ;
138136
139137 axios . post ( 'http://localhost:8000/api/login' , payload )
140138 . then ( response => {
141- // Handle the response, e.g., show a success message or redirect to the dashboard
139+
142140 console . log ( 'User logged in successfully!' ) ;
143- // Redirect to dashboard.html
141+
144142 window . location . href = 'dashboard.html' ;
145143 } )
146144 . catch ( error => {
147- // Handle the error, e.g., display an error message
145+
148146 console . error ( error ) ;
149147 } ) ;
150148 } ) ;
0 commit comments