Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
Merge pull request #9 from TechforgoodCAST/dev
  • Loading branch information
suninthesky authored Oct 16, 2018
2 parents 1299587 + b764192 commit c530b56
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 28 deletions.
16 changes: 8 additions & 8 deletions app/assets/stylesheets/modules/form.sass
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
input
input, textarea
background: $off-white
width: 100%
padding: 15px
font-size: 14px

input
border: 1px solid $grey
width: 100%

textarea
border: none

label
display: block
font-weight: bold
margin-bottom: 5px

textarea
width: 100%
background: $off-white
border: none
padding: 15px

.boolean.label
display: inline-block
.checkbox
Expand Down
13 changes: 11 additions & 2 deletions app/models/referral.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def to_param

def extract_values(array)
array&.map do |hash|
hash[:text] || hash[:email] || hash[:date] || hash[:number] ||
hash[:boolean] || hash[:choices] || hash[:choice]
hash[:text] || hash[:email] || hash[:date] ||
hash[:number] || hash[:choices] ||
parse_choice(hash[:choice]) || parse_boolean(hash[:boolean])
end
end

Expand All @@ -68,4 +69,12 @@ def find_state(hash)
'review'
end
end

def parse_boolean(val)
{ true => 'Yes', false => 'No' }[val]
end

def parse_choice(val)
val&.fetch(:label, nil)
end
end
8 changes: 4 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

<body>

<% if user_signed_in? %>
<nav class="px15">
<nav class="px15">
<% if user_signed_in? %>
<div class="mw-767 mx-auto flex justify-between">
<div>
<%= link_to('Slots', root_path, class: "nav-item h2 bold black mr40 #{current_page?(root_path) ? 'active' : ''}") %>
<%= link_to('Referrals', referrals_path, class: "nav-item h2 bold black #{current_page?(referrals_path) ? 'active' : ''}") %>
</div>
<%= link_to('Log Out', destroy_user_session_path, method: :delete, class: 'nav-item h2 bold black underline') %>
</div>
</nav>
<% end %>
<% end %>
</nav>

<% if alert || notice %>
<section class="px15 bg-black white py15">
Expand Down
4 changes: 3 additions & 1 deletion app/views/referrals/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1 class="h2 bold maroon mt40"><%= @partner.name %></h1>

<div class="py40">
<% if @partner.can_accept_referrals? %>
<%= tag.div(id: "typeform", data: { form_url: @partner.form_url }) %>
Expand Down Expand Up @@ -37,7 +39,7 @@
</div>

<% if user_signed_in? && @partner.referrals.any? %>
<h2 class="bold px15">Sent Referrals</h2>
<h2 class="bold px15 maroon">Sent Referrals</h2>

<div class="row bold h2">
<div class="sm fr2 truncate">Name</div>
Expand Down
12 changes: 6 additions & 6 deletions app/views/referrals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@
<%= f.input :notes, placeholder: "Leave a note to explain your decision.", input_html: { class: "rounded mb20" } %>

<div class="flex">
<% if @referral.last_state == "accepted" %>
<%= f.button :submit, "Accepted", class: "btn-wide", disabled: true %>
<% if @referral.last_state == "declined" %>
<%= f.button :submit, "Declined", class: "btn-wide", disabled: true %>
<% else %>
<%= f.button :submit, "Accept", class: "confirm btn-wide", data: { disable_with: "Accepting...", confirm: "Are you sure you want to accept this referral?" } %>
<%= f.button :submit, "Decline", class: "confirm btn-invert btn-wide", data: { disable_with: "Declining...", confirm: "Are you sure you want to decline this referral?" } %>
<% end %>

<span class="mr10"></span>

<% if @referral.last_state == "declined" %>
<%= f.button :submit, "Declined", class: "btn-wide", disabled: true %>
<% if @referral.last_state == "accepted" %>
<%= f.button :submit, "Accepted", class: "btn-wide", disabled: true %>
<% else %>
<%= f.button :submit, "Decline", class: "confirm btn-invert btn-wide", data: { disable_with: "Declining...", confirm: "Are you sure you want to decline this referral?" } %>
<%= f.button :submit, "Accept", class: "confirm btn-wide", data: { disable_with: "Accepting...", confirm: "Are you sure you want to accept this referral?" } %>
<% end %>
</div>
<% end %>
Expand Down
14 changes: 10 additions & 4 deletions test/factories/referrals.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
FactoryBot.define do
factory :referral do
original_response {
original_response do
{
form_response: {
calculated: { score: 0 },
definition: { fields: [{ title: 'q1' }, { title: 'q2' }] },
answers: [{ text: 'a1' }, { text: 'a2' }]
definition: {
fields: [
{ title: 'q1' }, { title: 'q2' }, { title: 'q3' }
]
},
answers: [
{ text: 'text' }, { boolean: true }, { choice: { label: 'choice' } }
]
}
}
}
end
end
end
5 changes: 3 additions & 2 deletions test/models/referral_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ class ReferralTest < ActiveSupport::TestCase
end

test '#response_answers found' do
assert_equal({ 'q1' => 'a1', 'q2' => 'a2' }, @subject.response_answers)
answers = { 'q1' => 'text', 'q2' => 'Yes', 'q3' => 'choice' }
assert_equal(answers, @subject.response_answers)
end

test '#response_identifier found' do
assert_equal('a1', @subject.response_identifier)
assert_equal('text', @subject.response_identifier)
end

test '#response_identifier not found' do
Expand Down
2 changes: 1 addition & 1 deletion test/system/referral_review_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ReferralReviewTest < ApplicationSystemTestCase
test 'lists answers' do
visit referral_path(@partner, @referral)
sign_in
%w[q1 a1 q2 a2].each { |t| assert_text(t) }
%w[q1 text q2 Yes q3 choice].each { |t| assert_text(t) }
end

test 'not signed in referrals_path' do
Expand Down

0 comments on commit c530b56

Please sign in to comment.