Skip to content

Commit

Permalink
[rubyforgood#3050] Display partner quota exceeded warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielabar committed Jul 27, 2024
1 parent 73823bd commit 44b2a61
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/controllers/partners/family_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def validate
for_families: true
).create_only
if @partner_request.valid?
@total_items = @partner_request.total_items_fromstr
@quota_exceeded = @total_items > current_partner.quota.to_i
body = render_to_string(template: 'partners/requests/validate', formats: [:html], layout: false)
render json: {valid: true, body: body}
else
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/partners/individuals_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def validate
family_requests_attributes: individuals_request_params[:items_attributes]&.values
).create_only
if @partner_request.valid?
@total_items = @partner_request.total_items_fromstr
@quota_exceeded = @total_items > current_partner.quota.to_i
body = render_to_string(template: 'partners/requests/validate', formats: [:html], layout: false)
render json: {valid: true, body: body}
else
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/partners/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def validate
).create_only

if @partner_request.valid?
@total_items = @partner_request.total_items_fromstr
@quota_exceeded = @total_items > current_partner.quota.to_i
body = render_to_string(template: 'partners/requests/validate', formats: [:html], layout: false)
render json: {valid: true, body: body}
else
Expand Down
4 changes: 4 additions & 0 deletions app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def total_items
request_items.sum { |item| item["quantity"] }
end

def total_items_fromstr
request_items.sum { |item| item["quantity"].to_i }
end

def user_email
partner_user_id ? User.find_by(id: partner_user_id).email : Partner.find_by(id: partner_id).email
end
Expand Down
45 changes: 29 additions & 16 deletions app/views/partners/requests/validate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,40 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table">
<thead>
<%# Items and quantities %>
<table class="table">
<thead>
<tr>
<th>Item Name</th>
<th>Total Items</th>
</tr>
</thead>
<tbody>
<% @partner_request.item_requests.each do |line_item| %>
<tr>
<th>Item Name</th>
<th>Total Items</th>
<td><%= line_item.name %></td>
<td><%= line_item.quantity %></td>
</tr>
</thead>
<tbody>
<% @partner_request.item_requests.each do |line_item| %>
<tr>
<td><%= line_item.name %></td>
<td><%= line_item.quantity %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</tbody>
</table>

<div class="message fs-5">
<p>Please confirm that the above list is what you meant to request.</p>
<%# Confirmation message %>
<div class="message fs-5">
<p>Please confirm that the above list is what you meant to request.</p>
</div>

<%# Quota exceeded warning %>
<% if @quota_exceeded %>
<div class="alert alert-warning" role="alert">
You are ordering
<span class="fw-bolder fst-italic" data-testid="partner-request-confirmation-total"><%= @total_items %></span>
total items, are you sure?
</div>
<% end %>
</div>

<%# Actions %>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-label="No I need to make changes">No, I need to make changes</button>
<button type="button" class="btn btn-primary" data-action="confirmation#submitForm">Yes, it's correct</button>
Expand Down

0 comments on commit 44b2a61

Please sign in to comment.