Skip to content

Commit 208deee

Browse files
Fix batch upload notice on wrong pages
1 parent a3d4bb0 commit 208deee

5 files changed

Lines changed: 289 additions & 42 deletions

File tree

reporting-app/app/controllers/staff/certification_batch_uploads_controller.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create
1919
uploaded_file = params[:csv_file]
2020

2121
if uploaded_file.blank?
22-
flash[:alert] = "Please select a CSV file to upload"
22+
flash.now[:alert] = "Please select a CSV file to upload"
2323
@batch_upload = CertificationBatchUpload.new
2424
render :new, status: :unprocessable_content
2525
return
@@ -31,12 +31,15 @@ def create
3131
)
3232
@batch_upload.file.attach(uploaded_file)
3333

34-
if @batch_upload.save
35-
flash[:notice] = "File uploaded successfully. You can now process it from the queue."
36-
redirect_to certification_batch_uploads_path
37-
else
38-
flash[:alert] = "Failed to upload file: #{@batch_upload.errors.full_messages.join(', ')}"
39-
render :new, status: :unprocessable_content
34+
respond_to do |format|
35+
if @batch_upload.save
36+
format.html { redirect_to certification_batch_uploads_path, notice: "File uploaded successfully. You can now process it from the queue." }
37+
format.json { render :show, status: :created, location: @batch_upload }
38+
else
39+
message = "Failed to upload file: #{@batch_upload.errors.full_messages.join(', ')}"
40+
format.html { redirect_to new_certification_batch_upload_path, alert: message }
41+
format.json { render json: { error: message }, status: :unprocessable_entity }
42+
end
4043
end
4144
end
4245

@@ -59,16 +62,19 @@ def results
5962

6063
# POST /staff/certification_batch_uploads/:id/process_batch
6164
def process_batch
62-
unless @batch_upload.processable?
63-
flash[:alert] = "This batch cannot be processed. Current status: #{@batch_upload.status}"
64-
redirect_to certification_batch_upload_path(@batch_upload)
65-
return
65+
respond_to do |format|
66+
if @batch_upload.processable? == false
67+
message = "This batch cannot be processed. Current status: #{@batch_upload.status}."
68+
format.html { redirect_to certification_batch_upload_path(@batch_upload), alert: message }
69+
format.json { render json: { error: message }, status: :unprocessable_entity }
70+
elsif ProcessCertificationBatchUploadJob.perform_later(@batch_upload.id)
71+
format.html { redirect_to certification_batch_uploads_path, notice: "Processing started for #{@batch_upload.filename}. Results will be available shortly." }
72+
format.json { head :accepted }
73+
else
74+
format.html { redirect_to certification_batch_upload_path(@batch_upload), alert: "Failed to start processing job." }
75+
format.json { render json: { error: "Failed to start processing job." }, status: :internal_server_error }
76+
end
6677
end
67-
68-
ProcessCertificationBatchUploadJob.perform_later(@batch_upload.id)
69-
70-
flash[:notice] = "Processing started for #{@batch_upload.filename}. Results will be available shortly."
71-
redirect_to certification_batch_uploads_path
7278
end
7379

7480
private

reporting-app/app/views/staff/certification_batch_uploads/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<% content_for :title, t(".title") %>
2+
<%= render partial: 'application/flash' %>
23
<div class="display-flex flex-justify">
34
<h1><%= t(".heading") %></h1>
45
<%= link_to t(".upload_new"), new_certification_batch_upload_path, class: "usa-button" %>

reporting-app/app/views/staff/certification_batch_uploads/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<% content_for :title, t(".title") %>
2+
<%= render partial: 'application/flash' %>
23
<h1><%= @batch_upload.filename %></h1>
34
<dl class="grid-row margin-bottom-2">
45
<dt class="grid-col-3 text-bold"><%= t(".uploader") %>:</dt>

0 commit comments

Comments
 (0)