Skip to content

Commit aae9375

Browse files
committed
Fix duplicate slots when concurring request are sent
1 parent e08a95e commit aae9375

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

appointment/static/js/appointments.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let nonWorkingDays = [];
55
let selectedDate = rescheduledDate || null;
66
let staffId = $('#staff_id').val() || null;
77
let previouslySelectedCell = null;
8+
let isRequestInProgress = false;
89

910
const calendar = new FullCalendar.Calendar(calendarEl, {
1011
initialView: 'dayGridMonth',
@@ -203,6 +204,11 @@ function formatTime(date) {
203204
}
204205

205206
function getAvailableSlots(selectedDate, staffId = null) {
207+
if (isRequestInProgress) {
208+
return; // Exit the function if a request is already in progress
209+
}
210+
isRequestInProgress = true;
211+
206212
// Update the slot list with the available slots for the selected date
207213
const slotList = $('#slot-list');
208214
const slotContainer = $('.slot-container');
@@ -305,6 +311,10 @@ function getAvailableSlots(selectedDate, staffId = null) {
305311
// Update the date chosen
306312
$('.djangoAppt_date_chosen').text(data.date_chosen);
307313
$('#service-datetime-chosen').text(data.date_chosen);
314+
isRequestInProgress = false;
315+
},
316+
error: function() {
317+
isRequestInProgress = false; // Ensure the flag is reset even if the request fails
308318
}
309319
});
310320
}

0 commit comments

Comments
 (0)