Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.

Commit 7c9e88f

Browse files
Add warning notice to Dashboard page and Partner Request page when partner is deactivated
1 parent 16aeda8 commit 7c9e88f

File tree

7 files changed

+59
-29
lines changed

7 files changed

+59
-29
lines changed

app/controllers/application_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def current_partner
2929
def verify_status_in_diaper_base
3030
if current_partner.status_in_diaper_base == "deactivated"
3131
flash[:alert] = 'Your account has been disabled, contact the organization via their email to reactivate'
32-
redirect_to partner_requests_path
3332
end
3433
end
3534

app/controllers/dashboard_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Prepares data to be shown to the users for their dashboard.
22
class DashboardController < ApplicationController
3+
before_action :verify_status_in_diaper_base
34
respond_to :html, :js
45

56
def index

app/controllers/family_requests_controller.rb

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,33 @@ def new
1414
end
1515

1616
def create
17-
children = current_partner.children.active.where.not(item_needed_diaperid: [nil, 0])
18-
request = FamilyRequestPayloadService.execute(children: children, partner: current_partner)
19-
20-
FamilyRequestService.execute(request)
21-
22-
redirect_to partner_requests_path, notice: "Requested items successfuly!"
23-
rescue ActiveModel::ValidationError
24-
render :new
17+
children = current_partner.children.active
18+
children_grouped_by_diaperid = children.group_by(&:item_needed_diaperid)
19+
api_response = DiaperBankClient.send_family_request(
20+
children: children,
21+
partner: current_partner
22+
)
23+
if api_response
24+
flash[:notice] = "Request sent to diaper bank successfully"
25+
partner_request = PartnerRequest.new(
26+
api_response
27+
.slice("organization_id")
28+
.merge(partner_id: current_partner.id, sent: true, for_families: true)
29+
)
30+
api_response["requested_items"].each do |item_hash|
31+
partner_request.item_requests.new(
32+
name: item_hash["item_name"],
33+
item_id: item_hash["item_id"],
34+
quantity: item_hash["count"],
35+
).tap do |item_request|
36+
item_request.children =
37+
children_grouped_by_diaperid[item_hash["item_id"]].to_a
38+
end
39+
end
40+
partner_request.save!
41+
redirect_to partner_requests_path
42+
else
43+
render :new
44+
end
2545
end
2646
end

app/controllers/partner_requests_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ def index
1111
end
1212

1313
def new
14-
@partner_request = PartnerRequest.new
15-
@partner_request.item_requests.build # required to render the empty items form
14+
if current_partner.partner_status.casecmp("verified").zero?
15+
@partner_request = PartnerRequest.new
16+
@partner_request.item_requests.build # required to render the empty items form
17+
else
18+
redirect_to partner_requests_path, notice: "Please review your application details and submit for approval in order to make a new request."
19+
end
1620
end
1721

1822
def create

app/views/partner_requests/index.html.erb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@
2323
</section>
2424

2525

26+
<section class="content">
27+
<div class="container-fluid">
28+
<div class="row">
29+
<!-- left column -->
30+
<div class="col-md-12">
31+
<!-- jquery validation -->
32+
<div class="card">
33+
<div class="card-footer">
34+
<% if @partner.verified? %>
35+
<%= link_to 'Create New Bulk Diaper Request', new_partner_request_path, class: 'btn btn-outline-primary' %>
36+
<%= link_to 'Create New Family Diaper Request', new_family_request_path, class: 'btn btn-outline-primary' %>
37+
<% else %>
38+
<p>Your account has not been verified, contact the organization via their email to reactivated</p>
39+
<% end %>
40+
</div>
41+
</div>
42+
</div>
43+
<!-- /.card -->
44+
</div>
45+
<!--/.col (left) -->
46+
</div>
47+
<!-- /.row -->
48+
</section>
49+
2650
<section class="content">
2751
<div class="container-fluid">
2852
<div class="row">

spec/features/family_requests_feature_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
visit partner_requests_path
115115
find_link("Create New Family Essentials Request").click
116116
expect(page).to have_text("Your account has been disabled, contact the organization via their email to reactivate")
117-
expect(current_path).to eq(partner_requests_path)
118117
end
119118
end
120119
end

spec/requests/partner_requests_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@
4444
end
4545
end
4646

47-
context "when user is authenticated but the status in diaper base is deactivated" do
48-
let!(:partner) { create(:partner, :verified, status_in_diaper_base: "deactivated") }
49-
let!(:user) { create(:user, partner: partner) }
50-
51-
before do
52-
sign_in user
53-
end
54-
55-
describe "GET #new" do
56-
it "should not send a request" do
57-
get :new
58-
59-
expect(response).to have_http_status(302)
60-
end
61-
end
62-
end
63-
6447
context "when user not authenticated" do
6548
let!(:partner) { create(:partner) }
6649

0 commit comments

Comments
 (0)