Skip to content

Commit

Permalink
update view to warn user if they have an existing request
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoneill committed Jun 13, 2024
1 parent 85a2695 commit 4ee8375
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/models/folio/patron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def expired?
user_info['active'] == false
end

def holds
patron_summary['holds']
end

def loans
patron_summary['loans']
end

private

def valid_proxy_relation?(info)
Expand Down Expand Up @@ -201,6 +209,10 @@ def policy_service
@policy_service ||= Folio::CirculationRules::PolicyService.new(patron_groups: [patron_group['id']])
end

def patron_summary
@patron_summary ||= self.class.folio_client.patron_summary(id)
end

def patron_blocks
@patron_blocks ||= user_info.dig('stubs', 'patron_blocks') # used for stubbing
@patron_blocks ||= self.class.folio_client.patron_blocks(id).fetch('automatedPatronBlocks', [])
Expand Down
15 changes: 15 additions & 0 deletions app/models/patron_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ def selected_items
items
end

def instance_request?
return false unless selectable_items.none?

instanceids = patron.holds.map { |elem| elem['item']['instanceId'] }
instanceids.include?(instance_id)
end

def item_request?(item = nil)
return false unless item || selectable_items.one?

itemid = item ? item.id : selectable_items.first.id
itemids = patron.holds.map { |elem| elem['item']['itemId'] }
itemids.include?(itemid)
end

# @return [Array<Folio::Item>] the items that are holdable and recallable by the patron
def holdable_recallable_items
@holdable_recallable_items ||= selectable_items.filter { |item| item.recallable?(patron) && item.holdable?(patron) }
Expand Down
4 changes: 4 additions & 0 deletions app/services/folio_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def patron_blocks(user_id)
get_json("/automated-patron-blocks/#{user_id}")
end

def patron_summary(user_id)
get_json("/patron/account/#{user_id}", params: { includeLoans: true, includeHolds: true })
end

# Defines the hold request data for Folio
# [String] pickup_location_id the UUID of the pickup location
# [String] patron_comments
Expand Down
7 changes: 7 additions & 0 deletions app/views/patron_requests/_item_request_hold.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="alert alert-warning alert-dismissible shadow-sm d-flex gap-3 align-items-center mt-3 col-lg-8">
<i class="bi bi-exclamation-triangle-fill fs-3 text-warning"></i>
<div>
Please be aware that there is already a <%= type %> for this title in our system under your name.
</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
4 changes: 4 additions & 0 deletions app/views/patron_requests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

<%= render 'messages', messages: @patron_request.active_messages %>

<% if @patron_request.item_request? || @patron_request.instance_request? %>
<%= render 'item_request_hold', type: 'request' %>
<% end %>

<h1 class="fw-semibold mt-4"><%= @patron_request.item_title %></h1>
<% if @patron_request.selectable_items.one? %>
<% single_item = @patron_request.selectable_items.first %>
Expand Down

0 comments on commit 4ee8375

Please sign in to comment.