From fb10e02ff4f411885f76442aa663febf8fcdee5c Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 21 Apr 2023 16:25:00 +0100 Subject: [PATCH] send the correct emails --- .../bulk_upload_sales_results_controller.rb | 14 +++++ .../bulk_upload_sales_resume_controller.rb | 42 +++++++++++++++ app/mailers/bulk_upload_mailer.rb | 10 ++-- .../forms/bulk_upload_sales_resume/confirm.rb | 30 +++++++++++ .../bulk_upload_sales_resume/fix_choice.rb | 53 +++++++++++++++++++ .../bulk_upload_sales_resume/confirm.html.erb | 22 ++++++++ .../fix_choice.html.erb | 36 +++++++++++++ config/routes.rb | 9 ++++ 8 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 app/controllers/bulk_upload_sales_resume_controller.rb create mode 100644 app/models/forms/bulk_upload_sales_resume/confirm.rb create mode 100644 app/models/forms/bulk_upload_sales_resume/fix_choice.rb create mode 100644 app/views/bulk_upload_sales_resume/confirm.html.erb create mode 100644 app/views/bulk_upload_sales_resume/fix_choice.html.erb diff --git a/app/controllers/bulk_upload_sales_results_controller.rb b/app/controllers/bulk_upload_sales_results_controller.rb index f767f0d94..c70907bbe 100644 --- a/app/controllers/bulk_upload_sales_results_controller.rb +++ b/app/controllers/bulk_upload_sales_results_controller.rb @@ -22,4 +22,18 @@ class BulkUploadSalesResultsController < ApplicationController def summary @bulk_upload = current_user.bulk_uploads.sales.find(params[:id]) end + + def reset_logs_filters + session["logs_filters"] = {}.to_json + end + + def set_bulk_upload_logs_filters + hash = { + years: [""], + status: ["", "in_progress"], + user: "all", + } + + session["logs_filters"] = hash.to_json + end end diff --git a/app/controllers/bulk_upload_sales_resume_controller.rb b/app/controllers/bulk_upload_sales_resume_controller.rb new file mode 100644 index 000000000..f38bf24bf --- /dev/null +++ b/app/controllers/bulk_upload_sales_resume_controller.rb @@ -0,0 +1,42 @@ +class BulkUploadSalesResumeController < ApplicationController + before_action :authenticate_user! + + def start + @bulk_upload = current_user.bulk_uploads.find(params[:id]) + + redirect_to page_bulk_upload_sales_resume_path(@bulk_upload, page: "fix-choice") + 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 ||= case params[:page] + when "fix-choice" + Forms::BulkUploadSalesResume::FixChoice.new(form_params.merge(bulk_upload: @bulk_upload)) + when "confirm" + Forms::BulkUploadSalesResume::Confirm.new(form_params.merge(bulk_upload: @bulk_upload)) + else + raise "invalid form" + end + end + + def form_params + params.fetch(:form, {}).permit(:choice) + end +end diff --git a/app/mailers/bulk_upload_mailer.rb b/app/mailers/bulk_upload_mailer.rb index b6388213a..883e89fed 100644 --- a/app/mailers/bulk_upload_mailer.rb +++ b/app/mailers/bulk_upload_mailer.rb @@ -10,7 +10,7 @@ class BulkUploadMailer < NotifyMailer def send_how_fix_upload_mail(bulk_upload:) title = "We found #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in your bulk upload" description = "There was a problem with your #{bulk_upload.year_combo} #{bulk_upload.log_type} data. Check the error report below to fix these errors." - cta_link = start_bulk_upload_lettings_resume_url(bulk_upload) + cta_link = bulk_upload.sales? ? start_bulk_upload_sales_resume_url(bulk_upload) : start_bulk_upload_lettings_resume_url(bulk_upload) send_email( bulk_upload.user.email, @@ -53,9 +53,9 @@ class BulkUploadMailer < NotifyMailer def send_correct_and_upload_again_mail(bulk_upload:) summary_report_link = if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - summary_bulk_upload_lettings_result_url(bulk_upload) + bulk_upload.sales? ? summary_bulk_upload_sales_result_url(bulk_upload) : summary_bulk_upload_lettings_result_url(bulk_upload) else - bulk_upload_lettings_result_url(bulk_upload) + bulk_upload.sales? ? bulk_upload_sales_result_url(bulk_upload) : bulk_upload_lettings_result_url(bulk_upload) end send_email( @@ -73,9 +73,9 @@ class BulkUploadMailer < NotifyMailer def send_bulk_upload_failed_file_setup_error_mail(bulk_upload:) bulk_upload_link = if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? - summary_bulk_upload_lettings_result_url(bulk_upload) + bulk_upload.sales? ? summary_bulk_upload_sales_result_url(bulk_upload) : summary_bulk_upload_lettings_result_url(bulk_upload) else - bulk_upload_lettings_result_url(bulk_upload) + bulk_upload.sales? ? bulk_upload_sales_result_url(bulk_upload) : bulk_upload_lettings_result_url(bulk_upload) end send_email( diff --git a/app/models/forms/bulk_upload_sales_resume/confirm.rb b/app/models/forms/bulk_upload_sales_resume/confirm.rb new file mode 100644 index 000000000..4ce50fb55 --- /dev/null +++ b/app/models/forms/bulk_upload_sales_resume/confirm.rb @@ -0,0 +1,30 @@ +module Forms + module BulkUploadSalesResume + class Confirm + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + + def view_path + "bulk_upload_sales_resume/confirm" + end + + def back_path + page_bulk_upload_sales_resume_path(bulk_upload, page: "fix-choice") + end + + def next_path + resume_bulk_upload_sales_result_path(bulk_upload) + end + + def save! + processor = BulkUpload::Processor.new(bulk_upload:) + processor.approve + + true + end + end + end +end diff --git a/app/models/forms/bulk_upload_sales_resume/fix_choice.rb b/app/models/forms/bulk_upload_sales_resume/fix_choice.rb new file mode 100644 index 000000000..671891429 --- /dev/null +++ b/app/models/forms/bulk_upload_sales_resume/fix_choice.rb @@ -0,0 +1,53 @@ +module Forms + module BulkUploadSalesResume + class FixChoice + include ActiveModel::Model + include ActiveModel::Attributes + include Rails.application.routes.url_helpers + + attribute :bulk_upload + 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_sales_resume/fix_choice" + end + + def next_path + case choice + when "create-fix-inline" + page_bulk_upload_sales_resume_path(bulk_upload, page: "confirm") + when "upload-again" + if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? + summary_bulk_upload_sales_result_path(bulk_upload) + else + bulk_upload_sales_result_path(bulk_upload) + end + else + raise "invalid choice" + end + end + + def recommendation + if BulkUploadErrorSummaryTableComponent.new(bulk_upload:).errors? + "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." + else + "For this many errors we recommend to upload logs and fix errors on site as you can easily see the questions and select the appropriate answer." + end + end + + def save! + true + end + end + end +end diff --git a/app/views/bulk_upload_sales_resume/confirm.html.erb b/app/views/bulk_upload_sales_resume/confirm.html.erb new file mode 100644 index 000000000..3230702f3 --- /dev/null +++ b/app/views/bulk_upload_sales_resume/confirm.html.erb @@ -0,0 +1,22 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: @form.back_path %> +<% end %> + +
+
+ Bulk upload for sales (<%= @bulk_upload.year_combo %>) +

Are you sure you want to upload all logs from this bulk upload?

+ +

There are <%= pluralize(@bulk_upload.logs.count, "log") %> in this bulk upload with <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> that still need to be fixed after upload.

+ + <%= 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_sales_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %> + <%= f.govuk_submit %> + + <%= govuk_button_link_to "Cancel", @form.back_path, secondary: true %> + <% end %> +
+
diff --git a/app/views/bulk_upload_sales_resume/fix_choice.html.erb b/app/views/bulk_upload_sales_resume/fix_choice.html.erb new file mode 100644 index 000000000..d646d531c --- /dev/null +++ b/app/views/bulk_upload_sales_resume/fix_choice.html.erb @@ -0,0 +1,36 @@ +
+
+ <%= form_with model: @form, scope: :form, url: page_bulk_upload_sales_resume_path(@bulk_upload, page: "fix-choice"), method: :patch do |f| %> + <%= f.govuk_error_summary %> + + Bulk upload for sales (<%= @bulk_upload.year_combo %>) +

How would you like to fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %>?

+ +
+ <%= @bulk_upload.filename %> +
+ +
+ <%= @form.recommendation %> +
+ + <%= govuk_details(summary_text: "How to choose between fixing errors on the CORE site or in the CSV") do %> +

When it comes to fixing errors, there are pros and cons to doing it on a CSV versus doing it on a website.

+ +

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.

+ +

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.

+ +

Ultimately, the best approach will depend on the specific situation and the nature of the errors that need to be fixed.

+ <% end %> + + <%= f.govuk_collection_radio_buttons :choice, + @form.options, + :id, + :name, + legend: { hidden: true } %> + + <%= f.govuk_submit %> + <% end %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 33fbdec3d..a9eaa86ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -205,6 +205,15 @@ Rails.application.routes.draw do get :summary end end + + resources :bulk_upload_sales_resume, path: "bulk-upload-resume", only: %i[show update] do + member do + get :start + + get "*page", to: "bulk_upload_sales_resume#show", as: "page" + patch "*page", to: "bulk_upload_sales_resume#update" + end + end end member do