In this episode, we go over how to cancel appointments in our app. We start by reviewing how appointment availability is handled, paying special attention to the canceled_at
field. That way, already canceled appointments are excluded from being booked again.
We then add a new method called cancelAppointment
inside the appointment show component. This method simply updates the canceled_at
field with the current timestamp whenever the appointment gets canceled. This gives us the ability to not only check if an appointment is canceled (by seeing if the date is set) but also to see when it was canceled.
To make our UI reflect these changes, we add logic to show a 'Canceled' status on appointments that have been canceled, and hide the cancel button in those cases. We also add a confirmation dialog using AlpineJS so users don't accidentally cancel appointments.
By the end of the episode, canceling an appointment updates the state, shows a confirmation, and dynamically updates the UI to reflect the change. It's a nice clean way of handling canceled appointments while keeping the user interface friendly and safe against mistakes.