@@ -579,6 +579,9 @@ async function showCreateAppointmentModal(defaultStartTime, formattedDate) {
579
579
let staffDropdown = null ;
580
580
if ( isUserSuperUser ) {
581
581
staffDropdown = await populateStaffMembers ( null , false ) ;
582
+ staffDropdown . id = "staffSelect" ;
583
+ staffDropdown . disabled = false ; // Enable dropdown
584
+ attachEventListenersToDropdown ( ) ; // Attach event listener
582
585
}
583
586
servicesDropdown . id = "serviceSelect" ;
584
587
servicesDropdown . disabled = false ; // Enable dropdown
@@ -653,6 +656,7 @@ async function showEventModal(eventId = null, isEditMode, isCreatingMode = false
653
656
let staffDropdown = null ;
654
657
if ( isUserSuperUser ) {
655
658
staffDropdown = await getStaffDropdown ( appointment . staff_id , isEditMode ) ;
659
+ attachEventListenersToDropdown ( ) ; // Attach event listener
656
660
}
657
661
658
662
document . getElementById ( 'eventModalBody' ) . innerHTML = generateModalContent ( appointment , servicesDropdown , isEditMode , staffDropdown ) ;
@@ -758,14 +762,26 @@ async function submitChanges() {
758
762
function collectFormDataFromModal ( modal ) {
759
763
const inputs = modal . querySelectorAll ( "input" ) ;
760
764
const serviceId = modal . querySelector ( "#serviceSelect" ) . value ;
761
- const staffId = modal . querySelector ( "#staffSelect" ) . value ;
765
+ let staffId = null ;
766
+
767
+ if ( isUserSuperUser ) {
768
+ // If the user is a superuser, get the staff ID from the dropdown
769
+ const staffDropdown = modal . querySelector ( "#staffSelect" ) ;
770
+ if ( staffDropdown ) {
771
+ staffId = staffDropdown . value ;
772
+ }
773
+ }
774
+
762
775
const data = {
763
776
isCreating : AppState . isCreating ,
764
777
service_id : serviceId ,
765
- staff_id : staffId ,
766
778
appointment_id : AppState . eventIdSelected
767
779
} ;
768
780
781
+ if ( staffId ) {
782
+ data . staff_id = staffId ;
783
+ }
784
+
769
785
inputs . forEach ( input => {
770
786
if ( input . name !== "date" ) {
771
787
let key = input . name . replace ( / ( [ A - Z ] ) / g, '_$1' ) . toLowerCase ( ) ;
0 commit comments