From b8d9a83d19c1e3b6e8e80a864c81aaae7777e510 Mon Sep 17 00:00:00 2001 From: Jim Benton Date: Wed, 11 Oct 2023 21:24:41 -0500 Subject: [PATCH] Update the handling of appointment updates to always send an updated email and gracefully handle cases where the current appointment is merged into a preexisting one. --- .../account/appointments_controller.rb | 26 ++++++++----------- app/views/renewal/payments/new.html.erb | 1 - 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/account/appointments_controller.rb b/app/controllers/account/appointments_controller.rb index a85694413..c088cb25e 100644 --- a/app/controllers/account/appointments_controller.rb +++ b/app/controllers/account/appointments_controller.rb @@ -22,13 +22,7 @@ def create @appointment = @member.appointments.new if @appointment.update(appointment_params) - message = if merge_simultaneous_appointments - "Your existing appointment scheduled for #{helpers.appointment_date_and_time(@appointment)} has been updated." - else - "Your appointment was scheduled for #{helpers.appointment_date_and_time(@appointment)}." - end - MemberMailer.with(member: @member, appointment: @appointment).appointment_confirmation.deliver_later - redirect_to account_appointments_path, success: message + merge_and_complete_appointment_update else load_holds_and_loans load_appointment_slots @@ -47,12 +41,7 @@ def update @member = current_user.member if @appointment.update(appointment_params) - message = if merge_simultaneous_appointments - "Your existing appointment scheduled for #{helpers.appointment_date_and_time(@appointment)} has been updated." - else - "Your appointment scheduled for #{helpers.appointment_date_and_time(@appointment)} was updated." - end - redirect_to account_appointments_path, success: message + merge_and_complete_appointment_update else load_holds_and_loans load_appointment_slots @@ -84,12 +73,19 @@ def load_holds_and_loans @loans = @member.loans.includes(:item, member: {appointments: :loans}).checked_out end - def merge_simultaneous_appointments + # In cases where a member already has an appointment during the selected time slot for the current appointment, + # merge those appointments together to avoid confusion for members or staff. + def merge_and_complete_appointment_update simultaneous_appointment = @member.appointments.simultaneous(@appointment).first if simultaneous_appointment simultaneous_appointment.merge!(@appointment) - true + message = "Your existing appointment scheduled for #{helpers.appointment_date_and_time(simultaneous_appointmentt)} has been updated." + MemberMailer.with(member: @member, appointment: simultaneous_appointment).appointment_confirmation.deliver_later + else + message = "Your appointment was scheduled for #{helpers.appointment_date_and_time(@appointment)}." + MemberMailer.with(member: @member, appointment: @appointment).appointment_confirmation.deliver_later end + redirect_to account_appointments_path, success: message end def load_appointment_for_editing diff --git a/app/views/renewal/payments/new.html.erb b/app/views/renewal/payments/new.html.erb index f73d95e65..7c0553554 100644 --- a/app/views/renewal/payments/new.html.erb +++ b/app/views/renewal/payments/new.html.erb @@ -12,7 +12,6 @@

Last year you paid <%= @amount.format(no_cents: true) %>. This year we’re encouraging our library members who can afford to do so to give a little more. As always, though, we don’t turn anyone away for an inability to pay. -