Booking System for Appointments with Callback Logic
In this scenario, we will use the calendar widget to allow users to select a date for booking. Some dates are already occupied (marked), and we want to make sure the user only selects an available date. The selected date will be validated against a list of occupied dates (eventDates), and if the date is occupied, the user will be notified via a snackbar message. If the date is available, it will be saved for further processing in the booking form.

Steps to Implement the Logic
Step 1: Pass the list of occupied dates to the calendar
The eventDates parameter needs to be populated with a list of occupied dates. These dates will come from a query to your data source (e.g., Firestore, Supabase, or from a custom function if you need more advanced logic). The query will retrieve dates that are already booked and pass them to the calendar.
Step 2: Add actions in the onDateSelectionAction parameter
onDateSelectionAction parameterIn this step, you will configure the
onDateSelectionActionof the calendar widget to handle the user’s date selection.The goal is to compare the
selectedDate(the date clicked by the user) with the list of occupied dates passed through theeventDatesparameter.To do this:
Format both the
selectedDateand theeventDateslist to a uniform date format (e.g.,"d/m/y") to exclude the time component.If the
selectedDateis found in the list of occupied dates, trigger an action to notify the user that the date is unavailable. You can use a snackbar or a modal to display this message.If the
selectedDateis not found in theeventDateslist (meaning it’s available), store the date in a separate variable (e.g.,selectedBookingDate) for further use in the booking form or workflow.
Step 3: Proceed with Appointment Booking if Available
After the user selects a time slot, you can proceed with confirming the booking. You can trigger a confirmation dialog, send the booking details to the backend, and display a success message to the user.
Once the booking is confirmed, if the calendar is pulling the blocked dates from the same data source where the booking is saved, the newly booked date will automatically appear as blocked for future users. This ensures that the same date won’t be available for booking again.
However, if the place where the new booking is stored is not the same source from where the blocked dates are pulled, you will need to add an additional step. After confirming the booking, you should update the list of blocked dates by adding the newly booked date to the source that the calendar is referencing. This step ensures that the newly booked date is marked as unavailable for other users when they attempt to select it in the future.
Last updated