@@ -20,14 +20,19 @@ document.addEventListener("DOMContentLoaded", () => {
2020
2121 const spotsLeft = details . max_participants - details . participants . length ;
2222
23- // Participants list HTML
23+ // Participants list HTML with delete icon
2424 let participantsHTML = "" ;
2525 if ( details . participants . length > 0 ) {
2626 participantsHTML = `
2727 <div class="participants-section">
2828 <strong>Participants:</strong>
2929 <ul class="participants-list">
30- ${ details . participants . map ( p => `<li>${ p } </li>` ) . join ( "" ) }
30+ ${ details . participants . map ( p => `
31+ <li>
32+ <span class="participant-email">${ p } </span>
33+ <span class="delete-icon" title="Remove participant" data-activity="${ name } " data-email="${ p } ">×</span>
34+ </li>
35+ ` ) . join ( "" ) }
3136 </ul>
3237 </div>
3338 ` ;
@@ -48,6 +53,42 @@ document.addEventListener("DOMContentLoaded", () => {
4853 ${ participantsHTML }
4954 ` ;
5055
56+ // Add event listener for delete icons after rendering
57+ setTimeout ( ( ) => {
58+ activityCard . querySelectorAll ( '.delete-icon' ) . forEach ( icon => {
59+ icon . addEventListener ( 'click' , async ( e ) => {
60+ const activityName = icon . getAttribute ( 'data-activity' ) ;
61+ const email = icon . getAttribute ( 'data-email' ) ;
62+ if ( ! activityName || ! email ) return ;
63+ try {
64+ const response = await fetch ( `/activities/${ encodeURIComponent ( activityName ) } /unregister?email=${ encodeURIComponent ( email ) } ` , {
65+ method : 'POST' ,
66+ } ) ;
67+ const result = await response . json ( ) ;
68+ if ( response . ok ) {
69+ messageDiv . textContent = result . message || 'Participant removed.' ;
70+ messageDiv . className = 'success' ;
71+ fetchActivities ( ) ;
72+ } else {
73+ messageDiv . textContent = result . detail || 'Failed to remove participant.' ;
74+ messageDiv . className = 'error' ;
75+ }
76+ messageDiv . classList . remove ( 'hidden' ) ;
77+ setTimeout ( ( ) => {
78+ messageDiv . classList . add ( 'hidden' ) ;
79+ } , 4000 ) ;
80+ } catch ( err ) {
81+ messageDiv . textContent = 'Error removing participant.' ;
82+ messageDiv . className = 'error' ;
83+ messageDiv . classList . remove ( 'hidden' ) ;
84+ setTimeout ( ( ) => {
85+ messageDiv . classList . add ( 'hidden' ) ;
86+ } , 4000 ) ;
87+ }
88+ } ) ;
89+ } ) ;
90+ } , 0 ) ;
91+
5192 activitiesList . appendChild ( activityCard ) ;
5293
5394 // Add option to select dropdown
@@ -83,6 +124,7 @@ document.addEventListener("DOMContentLoaded", () => {
83124 messageDiv . textContent = result . message ;
84125 messageDiv . className = "success" ;
85126 signupForm . reset ( ) ;
127+ fetchActivities ( ) ;
86128 } else {
87129 messageDiv . textContent = result . detail || "An error occurred" ;
88130 messageDiv . className = "error" ;
0 commit comments