diff --git a/app/controllers/admin/task_requests_controller.rb b/app/controllers/admin/task_requests_controller.rb
index ed94957..59261ff 100644
--- a/app/controllers/admin/task_requests_controller.rb
+++ b/app/controllers/admin/task_requests_controller.rb
@@ -8,6 +8,10 @@ class Admin::TaskRequestsController < Admin::ApplicationController
def edit
end
+ def show
+ @files = @task_request.files.paginate(page: params[:page])
+ end
+
def update
if @task_request.update(task_request_params)
redirect_to [:admin, :task_requests], notice: t(".notice")
diff --git a/app/controllers/task_requests_controller.rb b/app/controllers/task_requests_controller.rb
index e319b18..07172d0 100644
--- a/app/controllers/task_requests_controller.rb
+++ b/app/controllers/task_requests_controller.rb
@@ -17,13 +17,15 @@ class TaskRequestsController < ApplicationController
if @task_request.save
log_create_analytics
- redirect_to [@project, :task_requests], notice: t(".notice")
+ taskme_url = url_for([:admin, @task_request])
+ SubmitHubspotTaskRequestFormJob.perform_later(@task_request.user_email, taskme_url)
else
render :new
end
end
def show
+ @files = @task_request.files.paginate(page: params[:page])
end
def edit
diff --git a/app/jobs/submit_hubspot_task_request_form_job.rb b/app/jobs/submit_hubspot_task_request_form_job.rb
new file mode 100644
index 0000000..11877cf
--- /dev/null
+++ b/app/jobs/submit_hubspot_task_request_form_job.rb
@@ -0,0 +1,18 @@
+class SubmitHubspotTaskRequestFormJob < ApplicationJob
+ queue_as :default
+
+ def perform(user_email, taskme_url)
+ hubspot_task_request_form_guid = ENV["HUBSPOT_TASK_REQUEST_FORM_GUID"]
+ return unless hubspot_task_request_form_guid.present?
+
+ submission_params = {
+ email: user_email,
+ taskme_url: taskme_url
+ }
+
+ form = Hubspot::Form.new("guid" => hubspot_task_request_form_guid)
+ is_form_sumitted = form.submit(submission_params)
+
+ raise StandardError.new "Failed to submit the task request hubspot form data: #{is_form_sumitted}" unless is_form_sumitted
+ end
+end
diff --git a/app/views/admin/task_requests/show.html.erb b/app/views/admin/task_requests/show.html.erb
index 163de81..07be9cb 100644
--- a/app/views/admin/task_requests/show.html.erb
+++ b/app/views/admin/task_requests/show.html.erb
@@ -1,21 +1,49 @@
-
<%= link_to t("shared.cancel"), [project, :task_requests], class: "col-3 text-reset" %>
diff --git a/app/views/task_requests/create.html.erb b/app/views/task_requests/create.html.erb
new file mode 100644
index 0000000..3974af1
--- /dev/null
+++ b/app/views/task_requests/create.html.erb
@@ -0,0 +1,4 @@
+<% if params[:show_chat] %>
+ <%= javascript_include_tag "https://js.hs-scripts.com/7344617.js", defer: "defer", async: true, id: "hs-script-loader" %>
+<% end %>
+
Your task request was successfully submitted. Thank you.
diff --git a/app/views/task_requests/show.html.erb b/app/views/task_requests/show.html.erb
index 727be89..9120113 100644
--- a/app/views/task_requests/show.html.erb
+++ b/app/views/task_requests/show.html.erb
@@ -1,18 +1,46 @@
-
- <%= description_list_pair_for @task_request, :description, append: ":" %>
- <%= description_list_pair_for @task_request, :created_at, append: ":" %>
- <%= description_list_pair_for @task_request, :deadline, append: ":" %>
- <%= description_list_pair_for @task_request, :time_allowed, append: ":" %>
- <%= description_list_pair_for @task_request, :additional_notes, append: ":" %>
- <%= description_list_pair_for @task_request, :status, append: ":" %>
- - Files:
- -
- <% if @task_request.files.present? %>
- <% @task_request.files.each do |file| %>
- <%= file.filename %>
- <% end %>
- <% else %>
- "No files attached."
- <% end %>
-
-
+
+ <%= card_header text: "Task Details", close_action_path: [@project, :task_requests] %>
+
+
+
+
+ <%= description_list_pair_for @task_request, :description, append: ":" %>
+ <%= description_list_pair_for @task_request, :created_at, append: ":" %>
+ <%= description_list_pair_for @task_request, :status, append: ":" %>
+
+
+
+
+ <%= description_list_pair_for @task_request, :deadline, append: ":" %>
+ <%= description_list_pair_for @task_request, :time_allowed, append: ":" %>
+ <%= description_list_pair_for @task_request, :additional_notes, append: ":" %>
+
+
+
+
Files:
+
+
+
+
+ | Filename |
+ |
+
+
+
+ <% if @files.any? %>
+ <%= render partial: "file", collection: @files %>
+ <% else %>
+
+ | <%= t(".empty") %> |
+
+ <% end %>
+
+
+
+ <%= will_paginate @files %>
+
+
+
+
+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0af5c39..a8fe4bd 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -96,6 +96,8 @@ en:
task_requests:
index:
empty: Task requests will appear here
+ show:
+ empty: Attached files will appear here.
update:
notice: The task request has been updated successfully
users:
@@ -945,6 +947,7 @@ en:
heading:
Edit Task Request
form:
+ info_message: After submitting this task request, you'll be connected via chat with a BIG representative.
labels:
additional_notes: Please add any additional notes we should be aware of regarding this task.
deadline: What is the deadline for this task?
@@ -963,6 +966,8 @@ en:
task_request_time_allowed: Time Allowed
new:
heading: New Task Request
+ show:
+ empty: Attached files will appear here.
task_request:
actions:
manage: Manage
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 80514a6..174b604 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -183,6 +183,8 @@ es:
guardian_photo:
heading: Guardian Photo (ES)
task_requests:
+ form:
+ info_message: After submitting this task request, you'll be connected via chat with a BIG representative. (ES)
task_request:
actions:
manage: Manage (ES)
diff --git a/spec/controllers/task_requests_controller_spec.rb b/spec/controllers/task_requests_controller_spec.rb
index 3a67162..614d814 100644
--- a/spec/controllers/task_requests_controller_spec.rb
+++ b/spec/controllers/task_requests_controller_spec.rb
@@ -49,13 +49,6 @@ RSpec.describe TaskRequestsController, type: :controller do
end
describe "#create" do
- it "responds with a redirect" do
- post :create, params: { project_id: project.id, task_request: task_request_params }
-
- expect(response).to be_redirect
- expect(flash.notice).not_to be_nil
- end
-
it "does create a new record" do
expect {
post :create, params: { project_id: project.id, task_request: task_request_params }
@@ -67,6 +60,12 @@ RSpec.describe TaskRequestsController, type: :controller do
post :create, params: { project_id: project.id, task_request: task_request_params }
}.to have_enqueued_job(TrackAnalyticsJob).with(user, account, :track_create_task_request, user_agent: "Rails Testing", user_ip: "0.0.0.0")
end
+
+ it "submits data to hubspot form" do
+ expect {
+ post :create, params: { project_id: project.id, task_request: task_request_params }
+ }.to have_enqueued_job(SubmitHubspotTaskRequestFormJob)
+ end
end
describe "#update" do
diff --git a/spec/features/admin_managing_task_requests_spec.rb b/spec/features/admin_managing_task_requests_spec.rb
index 45752bb..c7f52c0 100644
--- a/spec/features/admin_managing_task_requests_spec.rb
+++ b/spec/features/admin_managing_task_requests_spec.rb
@@ -53,7 +53,7 @@ feature "Admin managing task requests" do
expect(page).to have_content 'Files'
task_request.files.each do |file|
- expect(page).to have_link file.blob.filename
+ expect(page).to have_content file.blob.filename
end
end
@@ -65,7 +65,7 @@ feature "Admin managing task requests" do
click_link 'View'
switch_to_window(windows.last)
- expect(page).to have_content 'No files attached'
+ expect(page).to have_content 'Attached files will appear here.'
end
scenario "task requests table is visible" do
diff --git a/spec/features/user_creates_task_request_spec.rb b/spec/features/user_creates_task_request_spec.rb
new file mode 100644
index 0000000..b2540fe
--- /dev/null
+++ b/spec/features/user_creates_task_request_spec.rb
@@ -0,0 +1,88 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.feature 'User creates task request', type: :feature do
+ let(:current_user) { create(:user, :manager) }
+ let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
+
+ before do
+ sign_in(current_user)
+ end
+
+ scenario 'creating a new task request' do
+ visit new_project_task_request_path(project)
+
+ fill_in description_field, with: 'Description of the task'
+ fill_in deadline_field, with: '2020-06-24'
+ fill_in time_allowed_field, with: '30'
+ fill_in additional_notes_field, with: 'Additional note about the task'
+
+ click_on 'Create Task request'
+
+ expect(page).to have_content('Task request created succussfully.')
+ end
+
+ scenario 'user can view task request details' do
+ create(:task_request, project: project, description: 'Description of the task', deadline: '2020-07-23', time_allowed: '10', additional_notes: 'Additional note about the task')
+
+ visit project_task_request_path(project, TaskRequest.first)
+
+ expect(page).to have_content('Description of the task')
+ expect(page).to have_content('2020-07-23')
+ expect(page).to have_content('10')
+ expect(page).to have_content('Additional note about the task')
+ end
+
+ scenario 'user can update existing task request' do
+ create(:task_request, project: project, description: 'Description of the task', deadline: '2020-08-23', time_allowed: '10', additional_notes: 'Additional note about the task')
+
+ visit edit_project_task_request_path(project, TaskRequest.first)
+
+ fill_in deadline_field, with: '2020-07-01'
+ fill_in time_allowed_field, with: '13'
+
+ click_on 'Update Task request'
+ expect(page).to have_content('13')
+ expect(page).to have_content('07/01/20')
+ end
+
+ scenario 'user can cancel a task request' do
+ create(:task_request, project: project, description: 'Description of the task', deadline: '2020-08-23', time_allowed: '10', additional_notes: 'Additional note about the task')
+
+ visit project_task_requests_path(project)
+
+ click_on 'Manage'
+ click_link 'Cancel'
+
+ expect(page).to have_content('Cancelled')
+ end
+
+ scenario 'user can view completed tasks' do
+ create_list(:task_request, 5, project: project, status: 'completed')
+ create_list(:task_request, 5, project: project, status: 'pending')
+
+ visit project_tasks_path(project)
+
+ expect(page).to have_content('Completed')
+ expect(page).not_to have_content('Pending')
+ end
+
+ private
+
+ def description_field
+ t "task_requests.form.labels.description"
+ end
+
+ def deadline_field
+ t "task_requests.form.labels.deadline"
+ end
+
+ def time_allowed_field
+ t "task_requests.form.labels.time_allowed"
+ end
+
+ def additional_notes_field
+ t "task_requests.form.labels.additional_notes"
+ end
+end
\ No newline at end of file
diff --git a/spec/jobs/submit_hubspot_task_request_form_job_spec.rb b/spec/jobs/submit_hubspot_task_request_form_job_spec.rb
new file mode 100644
index 0000000..8aa269c
--- /dev/null
+++ b/spec/jobs/submit_hubspot_task_request_form_job_spec.rb
@@ -0,0 +1,36 @@
+require 'rails_helper'
+
+RSpec.describe SubmitHubspotTaskRequestFormJob, type: :job do
+ describe '#perform_now' do
+ before do
+ ENV["HUBSPOT_TASK_REQUEST_FORM_GUID"] = "hubspot_task_request_form_guid"
+ end
+
+ it 'submits to the Hubspot API with the right params' do
+ form = double(:form)
+ allow(Hubspot::Form).to receive(:new).and_return(form)
+ allow(form).to receive(:submit).and_return(true)
+
+ SubmitHubspotTaskRequestFormJob.perform_now("email@test.com", "https://example.com/admin/task_requests/1")
+
+ expect(Hubspot::Form).to have_received(:new).with("guid" => "hubspot_task_request_form_guid")
+ expect(form).to have_received(:submit).with(
+ email: "email@test.com",
+ taskme_url: "https://example.com/admin/task_requests/1"
+ )
+ end
+
+ context 'when HUBSPOT_TASK_REQUEST_FORM_GUID is not available' do
+ it 'does not submit to the API' do
+ ENV["HUBSPOT_TASK_REQUEST_FORM_GUID"] = nil
+ form = double(:form)
+ allow(Hubspot::Form).to receive(:new).and_return(form)
+ allow(form).to receive(:submit)
+
+ SubmitHubspotTaskRequestFormJob.perform_now("email@test.com", "https://example.com/admin/task_requests/1")
+
+ expect(form).not_to have_received(:submit)
+ end
+ end
+ end
+end