-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return items on a reservation (#1764)
# What it does * Adds the ability for a staff member to mark items on a reservation as returned at the end of a loan. * Restructures the "Pickups" tab to be the "Items" tab on a reservation. Now all item manipulation (both while building up the specific items to be borrowed and when they are returned later on) happen on the same page/tab. * Deletes an unused partial: `app/views/account/reservations/_profile.html.erb`. # Why it is important We need to have a accept items that are returned to us 😄 # UI Change Screenshot ![2024-11-19 18 36 54](https://github.com/user-attachments/assets/a278e1ab-9213-4b10-95b1-f9a79b863284) # Implementation notes * It's possible we could avoid the turbo stream shenanigans in this flow, but I started working on this before we merged in the page refresh morphing stuff in #1738. I will see if that simplification is possible while tackling future parts of the reservation flow.
- Loading branch information
Showing
18 changed files
with
183 additions
and
57 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
app/controllers/admin/reservations/check_ins_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Admin | ||
module Reservations | ||
class CheckInsController < BaseController | ||
def create | ||
if (reservation_item_id = reservation_loan_lookup_params[:reservable_item_id]) | ||
@reservable_item = ReservableItem.find_by(id: reservation_item_id) | ||
if !@reservable_item | ||
render_form_with_error("no item found with this ID") | ||
return | ||
end | ||
@reservation_loan = @reservation.reservation_loans.find_by(reservable_item_id: @reservable_item.id) | ||
elsif (reservation_loan_id = reservation_loan_lookup_params[:reservation_loan_id]) | ||
@reservation_loan = @reservation.reservation_loans.find_by(id: reservation_loan_id) | ||
end | ||
|
||
if !@reservation_loan | ||
render_form_with_error("not found on this reservation") | ||
return | ||
end | ||
|
||
if @reservation_loan.checked_in_at.present? | ||
render_form_with_error("already marked as returned") | ||
return | ||
end | ||
|
||
@reservation_loan.update(checked_in_at: Time.current) | ||
@reservation_hold = @reservation_loan.reservation_hold | ||
end | ||
|
||
def destroy | ||
if (reservation_loan_id = params[:id]) | ||
@reservation_loan = @reservation.reservation_loans.find_by(id: reservation_loan_id) | ||
end | ||
|
||
if !@reservation_loan | ||
render_form_with_error("not found on this reservation") | ||
return | ||
end | ||
|
||
if @reservation_loan.checked_in_at.blank? | ||
render_form_with_error("not marked as returned") | ||
return | ||
end | ||
|
||
@reservation_loan.update(checked_in_at: nil) | ||
@reservation_hold = @reservation_loan.reservation_hold | ||
render :create | ||
end | ||
|
||
private | ||
|
||
def render_form_with_error(message) | ||
@reservation_loan_lookup_form = ReservationLoanLookupForm.new | ||
@reservation_loan_lookup_form.errors.add(:reservable_item_id, message) | ||
render_form | ||
end | ||
|
||
def render_form | ||
render partial: "admin/reservations/check_ins/form", locals: {reservation: @reservation, reservation_loan_lookup_form: @reservation_loan_lookup_form}, status: :unprocessable_entity | ||
end | ||
|
||
def reservation_loan_lookup_params | ||
params.require(:reservation_loan_lookup_form).permit(:reservable_item_id, :reservation_loan_id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ReservationLoanLookupForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attribute :reservable_item_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= turbo_frame_tag "reservation-loan-form" do %> | ||
<%= form_with(model: reservation_loan_lookup_form, url: admin_reservation_check_ins_path(reservation.id), builder: SpectreFormBuilder) do |form| %> | ||
<%= form.text_field :reservable_item_id, label: "Item ID", autocomplete: "off", autofocus: true %> | ||
<%= form.submit "Return Item" %> | ||
<% end %> | ||
<% end %> |
19 changes: 19 additions & 0 deletions
19
app/views/admin/reservations/check_ins/create.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<turbo-stream action="replace" target="reservation-loan-form"> | ||
<template> | ||
<%= render partial: "admin/reservations/check_ins/form", formats: [:html], locals: {reservation: @reservation, reservation_loan_lookup_form: ReservationLoanLookupForm.new} %> | ||
</template> | ||
</turbo-stream> | ||
|
||
<% if @reservation_hold %> | ||
<turbo-stream action="replace" target="<%= dom_id(@reservation_hold) %>"> | ||
<template> | ||
<%= render partial: "admin/reservations/reservation_loans/reservation_hold", formats: [:html], locals: {reservation: @reservation, reservation_hold: @reservation_hold} %> | ||
</template> | ||
</turbo-stream> | ||
<% end %> | ||
|
||
<turbo-stream action="replace" target="pending-reservation-items"> | ||
<template> | ||
<%= render partial: "admin/reservations/pending_reservation_items", formats: [:html], locals: {reservation: @reservation} %> | ||
</template> | ||
</turbo-stream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters