In this episode, we tackle an important edge case for booking systems: what happens if someone tries to book a slot that's already been taken? This can easily happen if two users are on the checkout page at the same time and both see the same available slot—without proper collision handling, you could end up with double bookings!
We start by mirroring our availability-checking logic right into the booking process. That means, just before creating an appointment, we re-check whether the selected slot is still actually available. We set up a method to confirm the slot's availability based on its date and time, making sure that what the user picked hasn't already been grabbed by someone else in the meantime.
If the slot isn't available, we don't just fail silently. Instead, we flash a friendly message back to the user telling them that the slot has been taken while they were checking out. We set this up using Inertia's global page props, so it smoothly displays at the top of the checkout page without any weird reloads or scroll jumps.
Finally, we add a bit of UI polish to make the flash message stand out. The episode ends with a quick demo: after some database tweaks and a couple of booking attempts, we confirm that everything works as expected. Failed bookings show a "try another time" message, and successful ones go through. In the next episode, we'll work on confirming successful bookings with a dedicated confirmation page!