Browse Source

add confirm page to bulk upload resume journey

bulk-upload-resume-v2
Phil Lee 2 years ago
parent
commit
1ef64adfef
  1. 11
      app/controllers/bulk_upload_lettings_resume_controller.rb
  2. 19
      app/models/forms/bulk_upload_lettings_resume/confirm.rb
  3. 2
      app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
  4. 1
      app/views/bulk_upload_lettings_logs/forms/needstype.erb
  5. 22
      app/views/bulk_upload_lettings_resume/confirm.html.erb
  6. 2
      app/views/bulk_upload_lettings_resume/fix_choice.html.erb
  7. 5
      config/routes.rb
  8. 20
      spec/requests/bulk_upload_lettings_resume_controller_spec.rb

11
app/controllers/bulk_upload_lettings_resume_controller.rb

@ -4,7 +4,7 @@ class BulkUploadLettingsResumeController < ApplicationController
def start
@bulk_upload = current_user.bulk_uploads.find(params[:id])
redirect_to fix_choice_bulk_upload_lettings_resume_path(@bulk_upload)
redirect_to page_bulk_upload_lettings_resume_path(@bulk_upload, page: "fix-choice")
end
def show
@ -26,7 +26,14 @@ class BulkUploadLettingsResumeController < ApplicationController
private
def form
@form ||= Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload))
@form ||= case params[:page]
when "fix-choice"
Forms::BulkUploadLettingsResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload))
when "confirm"
Forms::BulkUploadLettingsResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload))
else
raise "invalid form"
end
end
def form_params

19
app/models/forms/bulk_upload_lettings_resume/confirm.rb

@ -0,0 +1,19 @@
module Forms
module BulkUploadLettingsResume
class Confirm
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :bulk_upload
def view_path
"bulk_upload_lettings_resume/confirm"
end
def back_path
page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice")
end
end
end
end

2
app/models/forms/bulk_upload_lettings_resume/fix_choice.rb

@ -24,6 +24,8 @@ module Forms
def next_path
case choice
when "create-fix-inline"
page_bulk_upload_lettings_resume_path(bulk_upload, page: "confirm")
when "upload-again"
if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors?
summary_bulk_upload_lettings_result_path(bulk_upload)

1
app/views/bulk_upload_lettings_logs/forms/needstype.erb

@ -1,6 +1,7 @@
<% content_for :before_content do %>
<%= govuk_back_link href: @form.back_path %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= form_with model: @form, scope: :form, url: bulk_upload_lettings_log_path(id: "needstype"), method: :patch do |f| %>

22
app/views/bulk_upload_lettings_resume/confirm.html.erb

@ -0,0 +1,22 @@
<% content_for :before_content do %>
<%= govuk_back_link href: @form.back_path %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">Are you sure you want to upload all logs from this bulk upload?</h1>
<p class="govuk-bodyl">There are 1000 logs in this bulk upload with <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> that still need to be fixed after upload.</p>
<%= govuk_warning_text(icon_fallback_text: "Danger") do %>
You can not delete logs once you create them
<% end %>
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %>
<%= f.govuk_submit %>
<%= govuk_button_link_to "Cancel", @form.back_path, secondary: true %>
<% end %>
</div>
</div>

2
app/views/bulk_upload_lettings_resume/fix_choice.html.erb

@ -1,6 +1,6 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, scope: :form, url: fix_choice_bulk_upload_lettings_resume_path(@bulk_upload), method: :patch do |f| %>
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "fix-choice"), method: :patch do |f| %>
<%= f.govuk_error_summary %>
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>

5
config/routes.rb

@ -147,8 +147,9 @@ Rails.application.routes.draw do
resources :bulk_upload_lettings_resume, path: "bulk-upload-resume", only: %i[show update] do
member do
get :start
get "fix-choice", to: "bulk_upload_lettings_resume#show"
patch "fix-choice", to: "bulk_upload_lettings_resume#update"
get "*page", to: "bulk_upload_lettings_resume#show", as: "page"
patch "*page", to: "bulk_upload_lettings_resume#update"
end
end

20
spec/requests/bulk_upload_lettings_resume_controller_spec.rb

@ -48,5 +48,25 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do
expect(response).to redirect_to("/lettings-logs/bulk-upload-results/#{bulk_upload.id}")
end
end
context "when fix inline selected" do
it "sends them to confirm choice" do
patch "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice", params: { form: { choice: "create-fix-inline" } }
expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm")
end
end
end
describe "GET /lettings-logs/bulk-upload-resume/:ID/confirm" do
context "without previous answer" do
it "renders page" do
get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/confirm"
expect(response).to be_successful
expect(response.body).to include("Are you sure")
end
end
end
end

Loading…
Cancel
Save