diff --git a/app/controllers/bulk_upload_lettings_data_check_controller.rb b/app/controllers/bulk_upload_lettings_data_check_controller.rb new file mode 100644 index 000000000..0e17582c3 --- /dev/null +++ b/app/controllers/bulk_upload_lettings_data_check_controller.rb @@ -0,0 +1,36 @@ +class BulkUploadLettingsDataCheckController < ApplicationController + before_action :authenticate_user! + + 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 ||= case params[:page] + when "soft-errors-valid" + Forms::BulkUploadLettingsDataCheck::SoftErrorsValid.new(form_params.merge(bulk_upload: @bulk_upload)) + when "confirm" + Forms::BulkUploadLettingsDataCheck::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) + else + raise "invalid form" + end + end + + def form_params + params.fetch(:form, {}).permit(:soft_errors_valid) + end +end diff --git a/app/mailers/bulk_upload_mailer.rb b/app/mailers/bulk_upload_mailer.rb index e1c28a056..d07a24be6 100644 --- a/app/mailers/bulk_upload_mailer.rb +++ b/app/mailers/bulk_upload_mailer.rb @@ -29,7 +29,7 @@ class BulkUploadMailer < NotifyMailer def send_check_soft_validations_mail(bulk_upload:) title = "Check your file data" description = "Some of your #{bulk_upload.year_combo} #{bulk_upload.log_type} data might not be right. Click the link below to review the potential errors, and check your file to see if the data is correct." - cta_link = bulk_upload.sales? ? bulk_upload_sales_check_data_url(bulk_upload) : bulk_upload_lettings_check_data_url(bulk_upload) + cta_link = bulk_upload.sales? ? bulk_upload_sales_data_check_url(bulk_upload) : bulk_upload_lettings_data_check_url(bulk_upload) send_email( bulk_upload.user.email, diff --git a/app/models/forms/bulk_upload_lettings_data_check/confirm.rb b/app/models/forms/bulk_upload_lettings_data_check/confirm.rb new file mode 100644 index 000000000..f777ce849 --- /dev/null +++ b/app/models/forms/bulk_upload_lettings_data_check/confirm.rb @@ -0,0 +1,23 @@ +module Forms + module BulkUploadLettingsDataCheck + class Confirm + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_lettings_data_check/confirm" + end + + def back_path + page_bulk_upload_lettings_data_check_path(bulk_upload, page: "soft-errors-valid") + end + + def next_path + page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice") + end + end + end +end diff --git a/app/models/forms/bulk_upload_lettings_data_check/soft_errors_valid.rb b/app/models/forms/bulk_upload_lettings_data_check/soft_errors_valid.rb new file mode 100644 index 000000000..f918784cf --- /dev/null +++ b/app/models/forms/bulk_upload_lettings_data_check/soft_errors_valid.rb @@ -0,0 +1,40 @@ +module Forms + module BulkUploadLettingsDataCheck + class SoftErrorsValid + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + attribute :soft_errors_valid, :string + + validates :soft_errors_valid, presence: true + + def options + [ + OpenStruct.new(id: "yes", name: "Yes, some of these are errors"), + OpenStruct.new(id: "no", name: "No, all the data is correct"), + ] + end + + def view_path + "bulk_upload_lettings_data_check/soft_errors_valid" + end + + def next_path + case soft_errors_valid + when "yes" + page_bulk_upload_lettings_resume_path(bulk_upload, page: "fix-choice") + when "no" + page_bulk_upload_lettings_data_check_path(bulk_upload, page: "confirm") + else + raise "invalid choice" + end + end + + def save! + true + end + end + end +end diff --git a/app/views/bulk_upload_lettings_data_check/soft_errors_valid.html.erb b/app/views/bulk_upload_lettings_data_check/soft_errors_valid.html.erb new file mode 100644 index 000000000..7429c808e --- /dev/null +++ b/app/views/bulk_upload_lettings_data_check/soft_errors_valid.html.erb @@ -0,0 +1,24 @@ +
Some data from your bulk upload might not be right. Check your file for any errors in the fields below.
+ +