Skip to content

Commit

Permalink
Update the handling of appointment updates to always send an updated …
Browse files Browse the repository at this point in the history
…email and

gracefully handle cases where the current appointment is merged into a preexisting
one.
  • Loading branch information
jim committed Oct 12, 2023
1 parent 13edb41 commit b8d9a83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
26 changes: 11 additions & 15 deletions app/controllers/account/appointments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/views/renewal/payments/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<p>
<strong>Last year you paid <%= @amount.format(no_cents: true) %>.</strong>
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.

</p>
</div>
</div>
Expand Down

0 comments on commit b8d9a83

Please sign in to comment.