Skip to content

Commit d6ceb03

Browse files
authored
Add personal contact columns to Facilitator (#144)
1 parent 27afa73 commit d6ceb03

18 files changed

+154
-43
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ gem 'premailer-rails'
5353
gem "bcrypt", '3.1.16'
5454
gem "json", ">= 2.6", "< 3" # or simply: gem "json", "~> 2.7"
5555
gem 'simple_form'
56+
gem 'country_select'
5657

5758
group :development, :test do
5859
gem 'better_errors'

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ GEM
138138
execjs
139139
coffee-script-source (1.12.2)
140140
concurrent-ruby (1.3.5)
141+
countries (8.0.4)
142+
unaccent (~> 0.3)
143+
country_select (11.0.0)
144+
countries (> 6.0, < 9.0)
141145
crass (1.0.6)
142146
css_parser (1.17.1)
143147
addressable
@@ -415,6 +419,7 @@ GEM
415419
concurrent-ruby (~> 1.0)
416420
uglifier (4.2.1)
417421
execjs (>= 0.3.0, < 3)
422+
unaccent (0.4.0)
418423
warden (1.2.9)
419424
rack (>= 2.0.9)
420425
websocket (1.2.11)
@@ -449,6 +454,7 @@ DEPENDENCIES
449454
ckeditor (~> 4.3.0)
450455
cocoon (~> 1.2.6)
451456
coffee-rails
457+
country_select
452458
debug (~> 1.11)
453459
devise (~> 4.7.3)
454460
dotenv-rails

app/controllers/facilitators_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def index
1313
end
1414

1515
def show
16-
@facilitator = Facilitator.find(params[:id])
16+
@facilitator = Facilitator.find(params[:id]).decorate
1717
end
1818

1919
def new
@@ -61,6 +61,6 @@ def set_facilitator
6161

6262
# Only allow a list of trusted parameters through.
6363
def facilitator_params
64-
params.require(:facilitator).permit(:first_name, :last_name, :email)
64+
params.require(:facilitator).permit(Facilitator::PERMITTED_PARAMS)
6565
end
6666
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class FacilitatorDecorator < Draper::Decorator
2+
delegate_all
3+
4+
DISPLAY_FIELDS = {
5+
"First name" => :first_name,
6+
"Last name" => :last_name,
7+
"Primary email address" => :primary_email_address,
8+
"Primary email type" => :primary_email_address_type,
9+
"Street address" => :street_address,
10+
"City" => :city,
11+
"State" => :state,
12+
"ZIP" => :zip,
13+
"Country" => :country,
14+
"Mailing address type" => :mailing_address_type,
15+
"Phone number" => :phone_number,
16+
"Phone number type" => :phone_number_type
17+
}
18+
19+
def display_fields
20+
DISPLAY_FIELDS.map do |label, method|
21+
{ label: label, value: object.send(method) }
22+
end
23+
end
24+
end

app/models/facilitator.rb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
class Facilitator < ApplicationRecord
22
has_one :user
33

4-
validates :first_name, presence: true
5-
validates :last_name, presence: true
6-
validates :email, presence: true
4+
CONTACT_TYPES = ["Work", "Personal"].freeze
5+
PERMITTED_PARAMS = [
6+
:first_name, :last_name, :primary_email_address, :primary_email_address_type,
7+
:street_address, :city, :state, :zip, :country, :mailing_address_type,
8+
:phone_number, :phone_number_type
9+
].freeze
10+
11+
validates :first_name,
12+
:last_name,
13+
:primary_email_address,
14+
:primary_email_address_type,
15+
:street_address,
16+
:city,
17+
:state,
18+
:zip,
19+
:country,
20+
:mailing_address_type,
21+
:phone_number,
22+
:phone_number_type,
23+
presence: true
24+
25+
validates :primary_email_address_type, inclusion: {in: CONTACT_TYPES}
26+
validates :mailing_address_type, inclusion: {in: CONTACT_TYPES}
27+
validates :phone_number_type, inclusion: {in: CONTACT_TYPES}
28+
29+
# TODO: add validation for zip code containing only numbers
30+
# TODO: add validation on STATE
31+
# TODO: add validation on phone number type
732
end
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
<%= form_for(@facilitator) do |f| %>
2-
<%= render 'shared/errors', resource: facilitator if facilitator.errors.any? %>
3-
4-
<div class="form-inputs">
5-
<%= f.label :first_name, class: 'bold' %>
6-
<%= f.text_field :first_name %>
7-
<%= f.label :last_name, class: 'bold' %>
8-
<%= f.text_field :last_name %>
9-
<%= f.label :email, class: 'bold' %>
10-
<%= f.text_field :email %>
11-
</div>
12-
13-
<div class="form-actions">
14-
<%= f.button :submit %>
15-
</div>
1+
<%= simple_form_for @facilitator do |f| %>
2+
<%= f.input :first_name %>
3+
<%= f.input :last_name %>
4+
<%= f.input :primary_email_address %>
5+
<%= f.input :primary_email_address_type,
6+
as: :radio_buttons,
7+
collection: Facilitator::CONTACT_TYPES,
8+
item_wrapper_class: 'form-check' %>
9+
<%= f.input :street_address %>
10+
<%= f.input :city %>
11+
<%= f.input :state %>
12+
<%= f.input :zip %>
13+
<%= f.input :country %>
14+
<%= f.input :mailing_address_type,
15+
as: :radio_buttons,
16+
collection: Facilitator::CONTACT_TYPES,
17+
item_wrapper_class: 'form-check' %>
18+
<%= f.input :phone_number%>
19+
<%= f.input :phone_number_type,
20+
as: :radio_buttons,
21+
collection: Facilitator::CONTACT_TYPES,
22+
item_wrapper_class: 'form-check' %>
23+
<%= f.button :submit %>
1624
<% end %>

app/views/facilitators/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<tr>
1818
<td><%= facilitator.first_name %></td>
1919
<td><%= facilitator.last_name %></td>
20-
<td><%= facilitator.email %></td>
20+
<td><%= facilitator.primary_email_address %></td>
2121
<td><%= link_to 'Show', facilitator %></td>
2222
<td><%= link_to 'Edit', edit_facilitator_path(facilitator) %></td>
2323
<td><%= link_to 'Destroy', facilitator, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
<p id="notice"><%= notice %></p>
22

3-
<p>
4-
<strong>First name:</strong>
5-
<%= @facilitator.first_name %>
6-
</p>
3+
<% @facilitator.display_fields.each do |field| %>
4+
<p>
5+
<strong><%= field[:label] %>:</strong>
6+
<%= field[:value].presence || "N/A" %>
7+
</p>
8+
<% end %>
79

8-
<p>
9-
<strong>Last name:</strong>
10-
<%= @facilitator.last_name %>
11-
</p>
1210

13-
<p>
14-
<strong>Email:</strong>
15-
<%= @facilitator.email %>
16-
</p>
1711

1812
<%= link_to 'Edit', edit_facilitator_path(@facilitator) %> |
1913
<%= link_to 'Back', facilitators_path %>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class AddContactInfoToFacilitators < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :facilitators, :primary_email_address, :string, null: false
4+
add_column :facilitators, :primary_email_address_type, :string, null: false
5+
add_column :facilitators, :street_address, :string, null: false
6+
add_column :facilitators, :city, :string, null: false
7+
add_column :facilitators, :state, :string, null: false
8+
add_column :facilitators, :zip, :string, null: false
9+
add_column :facilitators, :country, :string, null: false
10+
add_column :facilitators, :mailing_address_type, :string, null: false
11+
add_column :facilitators, :phone_number, :string, null: false
12+
add_column :facilitators, :phone_number_type, :string, null: false
13+
end
14+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class RemoveEmailFromFacilitators < ActiveRecord::Migration[6.1]
2+
def change
3+
remove_column :facilitators, :email, :string
4+
end
5+
end

0 commit comments

Comments
 (0)