Skip to content

Commit 84875e7

Browse files
Add opportunity creation form for marketing redesign (#2819)
1 parent a6660ca commit 84875e7

7 files changed

Lines changed: 150 additions & 11 deletions

File tree

app/controllers/marketing_redesign/contacts_controller.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module MarketingRedesign
2+
class OpportunitiesController < BaseController
3+
HUB_CONVERSION_POINT = "Upcase: Contact Us".freeze
4+
HUB_PROJECT_TYPE = "Team Training / Mentoring".freeze
5+
6+
def new
7+
end
8+
9+
def create
10+
Hub::Opportunities.create({
11+
**opportunity_params,
12+
conversion_point: HUB_CONVERSION_POINT,
13+
project_type: HUB_PROJECT_TYPE
14+
})
15+
redirect_back(
16+
fallback_location: {action: :new}
17+
)
18+
end
19+
20+
private
21+
22+
def opportunity_params
23+
params.require(:opportunity).permit(
24+
:contact_first_name,
25+
:contact_last_name,
26+
:email,
27+
:company_name,
28+
:contact_job_title
29+
)
30+
.then { combine_contact_name_params(_1) }
31+
end
32+
33+
# @param params [ActionController::Parameters]
34+
# @return [ActionController::Parameters]
35+
def combine_contact_name_params(params)
36+
params = params.dup
37+
contact_name = [
38+
params.delete(:contact_first_name),
39+
params.delete(:contact_last_name)
40+
].compact_blank.join(" ")
41+
params[:contact_name] = contact_name if contact_name.present?
42+
params
43+
end
44+
end
45+
end

app/views/marketing_redesign/contacts/new.html.erb

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<%= content_for(:page_title, t(".page_title")) %>
2+
3+
<%= form_with(
4+
scope: :opportunity,
5+
url: {action: :create},
6+
method: :post
7+
) do |f| %>
8+
<%= f.label :contact_first_name do %>
9+
<span><%= t(".attributes.contact_first_name") %></span>
10+
<%= f.text_field(
11+
:contact_first_name,
12+
autocomplete: "given-name",
13+
placeholder: t(".attributes.contact_first_name")
14+
) %>
15+
<% end %>
16+
17+
<%= f.label :contact_last_name do %>
18+
<span><%= t(".attributes.contact_last_name") %></span>
19+
<%= f.text_field(
20+
:contact_last_name,
21+
autocomplete: "family-name",
22+
placeholder: t(".attributes.contact_last_name")
23+
) %>
24+
<% end %>
25+
26+
<%= f.label :email do %>
27+
<span><%= t(".attributes.email") %></span>
28+
<%= f.email_field(
29+
:email,
30+
autocomplete: "email",
31+
placeholder: t(".attributes.email")
32+
) %>
33+
<% end %>
34+
35+
<%= f.label :company_name do %>
36+
<span><%= t(".attributes.company_name") %></span>
37+
<%= f.text_field(
38+
:company_name,
39+
autocomplete: "organization",
40+
placeholder: t(".attributes.company_name")
41+
) %>
42+
<% end %>
43+
44+
<%= f.label :contact_job_title do %>
45+
<span><%= t(".attributes.contact_job_title") %></span>
46+
<%= f.text_field(
47+
:contact_job_title,
48+
autocomplete: "organization-title",
49+
placeholder: t(".attributes.contact_job_title")
50+
) %>
51+
<% end %>
52+
53+
<%= f.submit t(".submit") %>
54+
<% end %>

config/locales/en.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,16 @@ en:
251251
about:
252252
show:
253253
page_title: About Us
254-
contacts:
254+
opportunities:
255255
new:
256256
page_title: Contact Us
257+
attributes:
258+
contact_first_name: First name
259+
contact_last_name: Last name
260+
email: Email
261+
company_name: Company name
262+
contact_job_title: Your role
263+
submit: Send
257264
library:
258265
show:
259266
page_title: Library

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
root controller: :home, action: :show
1010
get "about-us", controller: :about, action: :show
1111
resources(
12-
:contacts,
12+
:opportunities,
1313
only: %i[new create],
1414
path: "contact-us",
1515
path_names: {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "rails_helper"
2+
3+
describe MarketingRedesign::OpportunitiesController do
4+
around do |example|
5+
ClimateControl.modify(ENABLE_MARKETING_REDESIGN: "true") do
6+
Rails.application.reload_routes!
7+
example.run
8+
end
9+
ensure
10+
Rails.application.reload_routes!
11+
end
12+
13+
describe "#create" do
14+
it "calls the Hub API opportunities creation endpoint with the correct parameters" do
15+
allow(Hub::Opportunities).to receive(:create)
16+
17+
post(
18+
:create,
19+
params: {
20+
opportunity: {
21+
contact_first_name: "Firstname",
22+
contact_last_name: "Lastname",
23+
email: "example@example.com",
24+
company_name: "Example Company",
25+
contact_job_title: "Example Job Title"
26+
}
27+
}
28+
)
29+
30+
expect(Hub::Opportunities).to(
31+
have_received(:create).with({
32+
"contact_name" => "Firstname Lastname",
33+
"email" => "example@example.com",
34+
"company_name" => "Example Company",
35+
"contact_job_title" => "Example Job Title",
36+
:conversion_point => be_present,
37+
:project_type => be_present
38+
})
39+
)
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)