@@ -20,14 +20,19 @@ document.addEventListener("DOMContentLoaded", () => {
2020
2121 const spotsLeft = details . max_participants - details . participants . length ;
2222
23- // Create participants list HTML
23+ // Create participants list HTML with delete icon to the left
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 ( email => `<li>${ email } </li>` ) . join ( "" ) }
30+ ${ details . participants . map ( email => `
31+ <li>
32+ <span class="delete-participant" title="Remove participant" data-activity="${ encodeURIComponent ( name ) } " data-email="${ encodeURIComponent ( email ) } ">🗑</span>
33+ <span class="participant-email">${ email } </span>
34+ </li>
35+ ` ) . join ( "" ) }
3136 </ul>
3237 </div>
3338 ` ;
@@ -56,6 +61,29 @@ document.addEventListener("DOMContentLoaded", () => {
5661 option . textContent = name ;
5762 activitySelect . appendChild ( option ) ;
5863 } ) ;
64+
65+ // Add event listeners for delete icons
66+ document . querySelectorAll ( ".delete-participant" ) . forEach ( icon => {
67+ icon . addEventListener ( "click" , async ( e ) => {
68+ const activity = decodeURIComponent ( icon . getAttribute ( "data-activity" ) ) ;
69+ const email = decodeURIComponent ( icon . getAttribute ( "data-email" ) ) ;
70+ if ( confirm ( `Remove ${ email } from ${ activity } ?` ) ) {
71+ try {
72+ const response = await fetch ( `/activities/${ encodeURIComponent ( activity ) } /unregister?email=${ encodeURIComponent ( email ) } ` , {
73+ method : "POST"
74+ } ) ;
75+ const result = await response . json ( ) ;
76+ if ( response . ok ) {
77+ fetchActivities ( ) ;
78+ } else {
79+ alert ( result . detail || "Failed to remove participant." ) ;
80+ }
81+ } catch ( err ) {
82+ alert ( "Failed to remove participant." ) ;
83+ }
84+ }
85+ } ) ;
86+ } ) ;
5987 } catch ( error ) {
6088 activitiesList . innerHTML = "<p>Failed to load activities. Please try again later.</p>" ;
6189 console . error ( "Error fetching activities:" , error ) ;
0 commit comments