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

[WIP] Ask users to confirm bulk orders #439

Open
wants to merge 3 commits 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
14 changes: 11 additions & 3 deletions app/controllers/partner_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ def new
@partner_request.item_requests.build # required to render the empty items form
end

def confirm
@partner_request = build_partner_request
end

def create
@partner_request = PartnerRequest.new(partner_request_params.merge(partner_id: current_partner.id))
@partner_request.item_requests << create_item_requests
@partner_request = build_partner_request
respond_to do |format|
if @partner_request.save
# NOTE(chaserx): send request to diaper app.
Expand All @@ -40,12 +43,17 @@ def show

private

def build_partner_request
partner_request = PartnerRequest.new(partner_request_params.merge(partner_id: current_partner.id))
partner_request.item_requests << create_item_requests
partner_request
end

def partner_request_params
params.require(:partner_request).permit(:comments, :item_requests_attributes)
end

def get_full_item_values(id)
valid_items = DiaperBankClient.get_available_items(current_partner.diaper_bank_id)
valid_items.find { |item| item["id"] == id.to_i }
end

Expand Down
19 changes: 19 additions & 0 deletions app/views/partner_requests/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= form.input :comments, label: "Comments:", as: :text, class: "form-control", wrapper: :input_group %>

<table class='table'>
<thead>
<tr>
<th>Item Requested</th>
<th>Quantity</th>
<th></th>
</tr>
</thead>
<tbody class='fields'>
<%= render 'item_request', form: form %>
</tbody>
</table>
<div>
<%= add_item_button('Add Another Item') do %>
<%= render 'item_request', form: form, object: partner_request.item_requests.build %>
<% end %>
</div>
61 changes: 61 additions & 0 deletions app/views/partner_requests/confirm.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<% content_for :title, "New Request - #{current_partner.name}" %>
<h1><i class="fa fa-users"></i>&nbsp;&nbsp;
Confirm Request
<small>for <%= current_partner.name %></small>
</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">

<li class="breadcrumb-item"><a href="<%= dashboard_path %>"><i class="fa fa-home fa-lg"></i></a></li>
<li class="breadcrumb-item"><a href="#">Confirm Diaper Request</a></li>
</ol>
</div>
</div>
</div><!-- /.container-fluid -->
</section>

<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<!-- Default box -->
<div class="card">
<div class="card-body">
<p>Please double check the values that you inputted.</p>
</div>
</div>
</div>
</div>
</div>
</section>

<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<!-- Default box -->
<div class="card">
<div class="card-body">

<%= simple_form_for @partner_request, html: {role: 'form', class: 'form-horizontal'} do |form| %>

<%= render "form", form: form, partner_request: @partner_request %>

<hr>

</div>
<div class="card-footer">
<!-- TODO(chaserx): we should add some js to prevent submission if the items selected are the blank option or any item has an empty quantity -->
<%= form.submit("Confirm Diaper Request", class: "btn btn-primary") %> <%= link_to "Cancel Request", partner_requests_path, class: "btn btn-danger" %>
</div>
<% end %>
</div>
</div>
</div>
</div>
</section>
22 changes: 2 additions & 20 deletions app/views/partner_requests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,9 @@
<div class="card">
<div class="card-body">

<%= simple_form_for @partner_request, html: {role: 'form', class: 'form-horizontal'} do |form| %>
<%= simple_form_for @partner_request, url: confirm_partner_requests_path, html: {role: 'form', class: 'form-horizontal'} do |form| %>

<%= form.input :comments, label: "Comments:", as: :text, class: "form-control", wrapper: :input_group %>

<table class='table'>
<thead>
<tr>
<th>Item Requested</th>
<th>Quantity</th>
<th></th>
</tr>
</thead>
<tbody class='fields'>
<%= render 'item_request', form: form %>
</tbody>
</table>
<div>
<%= add_item_button('Add Another Item') do %>
<%= render 'item_request', form: form, object: @partner_request.item_requests.build %>
<% end %>
</div>
<%= render "form", form: form, partner_request: @partner_request %>

<hr>

Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
end

resources :users, only: [:index]
resources :partner_requests, only: [:new, :create, :show, :index]
resources :partner_requests, only: [:new, :create, :show, :index] do
collection do
post :confirm
end
end
resources :individuals_requests, only: [:new, :create]
resources :family_requests, only: [:new, :create] do
resource :pickup_sheets, only: :show
Expand Down