@@ -184,6 +184,7 @@ function displayEventList(events, date) {
184
184
for ( let item of eventItems ) {
185
185
item . addEventListener ( 'click' , function ( ) {
186
186
const eventId = this . getAttribute ( 'data-event-id' ) ;
187
+ AppState . eventIdSelected = eventId ;
187
188
showEventModal ( eventId , false , false ) . then ( r => r ) ;
188
189
} ) ;
189
190
}
@@ -320,6 +321,16 @@ function confirmDeleteAppointment(appointmentId) {
320
321
}
321
322
showErrorModal ( data . message , successTxt ) ;
322
323
closeConfirmModal ( ) ; // Close the confirmation modal
324
+
325
+ // Remove the deleted appointment from the global appointments array
326
+ appointments = appointments . filter ( appointment => appointment . id !== appointmentId ) ;
327
+
328
+ // Refresh the event list for the current date
329
+ const currentDate = AppState . calendar . getDate ( ) ;
330
+ const dateEvents = appointments
331
+ . filter ( event => moment ( currentDate ) . isSame ( event . start_time , 'day' ) )
332
+ . sort ( ( a , b ) => new Date ( a . start_time ) - new Date ( b . start_time ) ) ;
333
+ displayEventList ( dateEvents , currentDate ) ;
323
334
} )
324
335
. catch ( error => {
325
336
console . error ( 'Error:' , error ) ;
@@ -410,7 +421,6 @@ async function updateAppointmentDate(event, revertFunction) {
410
421
411
422
const responseData = await response . json ( ) ;
412
423
if ( response . ok ) {
413
- console . log ( "Updated message: " + responseData . message )
414
424
showErrorModal ( responseData . message , successTxt )
415
425
} else {
416
426
console . error ( 'Failed to update appointment date. Server responded with:' , response . statusText ) ;
@@ -533,6 +543,7 @@ function adjustModalButtonsVisibility(isEditMode, isCreatingMode) {
533
543
// ################################################################ //
534
544
535
545
function toggleEditMode ( ) {
546
+ console . log ( "I was called in toggleEditMode" )
536
547
const modal = document . getElementById ( "eventDetailsModal" ) ;
537
548
const appointment = appointments . find ( app => Number ( app . id ) === Number ( AppState . eventIdSelected ) ) ;
538
549
AppState . isCreating = false ; // Turn off creating mode
@@ -541,6 +552,8 @@ function toggleEditMode() {
541
552
if ( appointment ) {
542
553
AppState . isEditingAppointment = ! AppState . isEditingAppointment ; // Toggle the editing state
543
554
updateModalUIForEditMode ( modal , AppState . isEditingAppointment ) ;
555
+ } else {
556
+ console . error ( "Appointment not found!" ) ;
544
557
}
545
558
}
546
559
@@ -645,7 +658,6 @@ function validateEmail(email) {
645
658
const emailError = document . getElementById ( "emailError" ) ;
646
659
647
660
const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
648
- console . log ( "Email: " , emailInput . value )
649
661
if ( ! emailRegex . test ( emailInput . value ) ) {
650
662
emailInput . style . border = "1px solid red" ;
651
663
emailError . textContent = "Invalid email address, yeah." ;
@@ -666,8 +678,6 @@ async function sendAppointmentData(data) {
666
678
'Content-Type' : 'application/json' , 'X-Requested-With' : 'XMLHttpRequest' , 'X-CSRFToken' : getCSRFToken ( ) ,
667
679
} ;
668
680
669
- console . log ( "Sending data to server: " , data ) ;
670
-
671
681
return fetch ( updateApptMinInfoURL , {
672
682
method : 'POST' , headers : headers , body : JSON . stringify ( data )
673
683
} ) ;
0 commit comments