Browse Source

add first page for bulk upload resume journey

bulk-upload-resume-v2
Phil Lee 2 years ago
parent
commit
129f0b34e7
  1. 35
      app/controllers/bulk_upload_lettings_resume_controller.rb
  2. 25
      app/models/forms/bulk_upload_lettings_resume/fix_choice.rb
  3. 36
      app/views/bulk_upload_lettings_resume/fix_choice.html.erb
  4. 5
      config/locales/en.yml
  5. 8
      config/routes.rb
  6. 44
      spec/requests/bulk_upload_lettings_resume_controller_spec.rb

35
app/controllers/bulk_upload_lettings_resume_controller.rb

@ -0,0 +1,35 @@
class BulkUploadLettingsResumeController < ApplicationController
before_action :authenticate_user!
def start
@bulk_upload = current_user.bulk_uploads.find(params[:id])
redirect_to fix_choice_bulk_upload_lettings_resume_path(@bulk_upload)
end
def show
@bulk_upload = current_user.bulk_uploads.find(params[:id])
render form.view_path
end
def update
@bulk_upload = current_user.bulk_uploads.find(params[:id])
if form.valid? # && form.save!
redirect_to form.next_path
else
render form.view_path
end
end
private
def form
@form ||= Forms::BulkUploadLettingsResume::FixChoice.new(form_params)
end
def form_params
params.fetch(:form, {}).permit(:choice)
end
end

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

@ -0,0 +1,25 @@
module Forms
module BulkUploadLettingsResume
class FixChoice
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :choice, :string
validates :choice, presence: true,
inclusion: { in: %w[create-fix-inline upload-again] }
def options
[
OpenStruct.new(id: "create-fix-inline", name: "Upload these logs and fix errors on CORE site"),
OpenStruct.new(id: "upload-again", name: "Fix errors in the CSV and re-upload"),
]
end
def view_path
"bulk_upload_lettings_resume/fix_choice"
end
end
end
end

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

@ -0,0 +1,36 @@
<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| %>
<%= f.govuk_error_summary %>
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">How would you like to fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %>?</h1>
<div class="govuk-body-l">
<%= @bulk_upload.filename %>
</div>
<div class="govuk-body">
For this many errors we recommend to fix errors in the CSV and re-upload as you may be able to edit many fields at once in a CSV.
</div>
<%= govuk_details(summary_text: "How to choose between fixing errors on the CORE site or in the CSV") do %>
<p class="govuk-body">When it comes to fixing errors, there are pros and cons to doing it on a CSV versus doing it on a website.</p>
<p class="govuk-body">Fixing errors on a CSV file can be beneficial because it allows you to easily make changes to multiple records at once, and you can use tools like Excel to quickly identify and correct errors. However, if the CSV file is not properly formatted, it can be difficult to identify which records contain errors.</p>
<p class="govuk-body">Fixing errors on a website can be convenient because you can see the data in context and make changes in real-time. However, this approach can be time-consuming if you need to make changes to multiple records, and it may be more difficult to identify errors in a large dataset.</p>
<p class="govuk-body">Ultimately, the best approach will depend on the specific situation and the nature of the errors that need to be fixed.</p>
<% end %>
<%= f.govuk_collection_radio_buttons :choice,
@form.options,
:id,
:name,
legend: { hidden: true } %>
<%= f.govuk_submit %>
<% end %>
</div>
</div>

5
config/locales/en.yml

@ -68,6 +68,11 @@ en:
attributes:
needstype:
blank: You must answer needs type
forms/bulk_upload_lettings_resume/fix_choice:
attributes:
choice:
blank: You must select how would you like to fix errors
inclusion: You must select one of the following options for how would like to fix errors
activerecord:
errors:

8
config/routes.rb

@ -144,6 +144,14 @@ Rails.application.routes.draw do
end
end
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"
end
end
get "update-logs", to: "lettings_logs#update_logs"
end

44
spec/requests/bulk_upload_lettings_resume_controller_spec.rb

@ -0,0 +1,44 @@
require "rails_helper"
RSpec.describe BulkUploadLettingsResumeController, type: :request do
let(:user) { create(:user) }
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:) }
let(:bulk_upload_errors) { create_list(:bulk_upload_error, 2) }
before do
sign_in user
end
describe "GET /lettings-logs/bulk-upload-resume/:ID/start" do
it "redirects to choice page" do
get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/start"
expect(response).to redirect_to("/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice")
end
end
describe "GET /lettings-logs/bulk-upload-resume/:ID/fix-choice" do
it "renders the page correctly" do
get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice"
expect(response).to be_successful
expect(response.body).to include("Bulk upload for lettings")
expect(response.body).to include("2022/23")
expect(response.body).to include("How would you like to fix 2 errors?")
expect(response.body).to include(bulk_upload.filename)
end
end
describe "PATCH /lettings-logs/bulk-upload-resume/:ID/fix-choice" do
context "when no option selected" do
it "renders error message" do
patch "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/fix-choice"
expect(response).to be_successful
expect(response.body).to include("You must select")
end
end
end
end
Loading…
Cancel
Save