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

Add warning notice to Dashboard page and Partner Request page when pa… #410

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def current_partner
def verify_status_in_diaper_base
if current_partner.status_in_diaper_base == "deactivated"
flash[:alert] = 'Your account has been disabled, contact the organization via their email to reactivate'
redirect_to partner_requests_path
end
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Prepares data to be shown to the users for their dashboard.
class DashboardController < ApplicationController
before_action :verify_status_in_diaper_base
respond_to :html, :js

def index
Expand Down
36 changes: 28 additions & 8 deletions app/controllers/family_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,33 @@ def new
end

def create
children = current_partner.children.active.where.not(item_needed_diaperid: [nil, 0])
request = FamilyRequestPayloadService.execute(children: children, partner: current_partner)

FamilyRequestService.execute(request)

redirect_to partner_requests_path, notice: "Requested items successfuly!"
rescue ActiveModel::ValidationError
render :new
children = current_partner.children.active
children_grouped_by_diaperid = children.group_by(&:item_needed_diaperid)
api_response = DiaperBankClient.send_family_request(
children: children,
partner: current_partner
)
if api_response
flash[:notice] = "Request sent to diaper bank successfully"
partner_request = PartnerRequest.new(
api_response
.slice("organization_id")
.merge(partner_id: current_partner.id, sent: true, for_families: true)
)
api_response["requested_items"].each do |item_hash|
partner_request.item_requests.new(
name: item_hash["item_name"],
item_id: item_hash["item_id"],
quantity: item_hash["count"],
).tap do |item_request|
item_request.children =
children_grouped_by_diaperid[item_hash["item_id"]].to_a
end
end
partner_request.save!
redirect_to partner_requests_path
else
render :new
end
end
end
8 changes: 6 additions & 2 deletions app/controllers/partner_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ def index
end

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

def create
Expand Down
24 changes: 24 additions & 0 deletions app/views/partner_requests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
</section>


<section class="content">
<div class="container-fluid">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- jquery validation -->
<div class="card">
<div class="card-footer">
<% if @partner.verified? %>
<%= link_to 'Create New Bulk Diaper Request', new_partner_request_path, class: 'btn btn-outline-primary' %>
<%= link_to 'Create New Family Diaper Request', new_family_request_path, class: 'btn btn-outline-primary' %>
<% else %>
<p>Your account has not been verified, contact the organization via their email to reactivated</p>
<% end %>
</div>
</div>
</div>
<!-- /.card -->
</div>
<!--/.col (left) -->
</div>
<!-- /.row -->
</section>

<section class="content">
<div class="container-fluid">
<div class="row">
Expand Down
1 change: 0 additions & 1 deletion spec/features/family_requests_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
visit partner_requests_path
find_link("Create New Family Essentials Request").click
expect(page).to have_text("Your account has been disabled, contact the organization via their email to reactivate")
expect(current_path).to eq(partner_requests_path)
end
end
end
17 changes: 0 additions & 17 deletions spec/requests/partner_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@
end
end

context "when user is authenticated but the status in diaper base is deactivated" do
let!(:partner) { create(:partner, :verified, status_in_diaper_base: "deactivated") }
let!(:user) { create(:user, partner: partner) }

before do
sign_in user
end

describe "GET #new" do
it "should not send a request" do
get :new

expect(response).to have_http_status(302)
end
end
end

context "when user not authenticated" do
let!(:partner) { create(:partner) }

Expand Down