UX: Return a friendlier error when the CSV is invalid. Added a cancel button to return to the /badges view

UX: Return a friendlier error when the CSV is invalid. Added a cancel button to return to the /badges view

diff --git a/app/assets/javascripts/admin/templates/badges-award.hbs b/app/assets/javascripts/admin/templates/badges-award.hbs
index bf9def194a..66ef70365a 100644
--- a/app/assets/javascripts/admin/templates/badges-award.hbs
+++ b/app/assets/javascripts/admin/templates/badges-award.hbs
@@ -21,6 +21,10 @@
           action=(action 'massAward')
           disabled=saving
           label="admin.badges.mass_award.perform"}}
+      {{#link-to 'adminBadges.index' class="btn btn-danger"}}
+        {{d-icon "times"}}
+        <span>{{i18n 'cancel'}}</span>
+      {{/link-to}}
     </form>
   {{else}}
     <span class='badge-required'>{{I18n 'admin.badges.mass_award.no_badge_selected'}}</span>
diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb
index 0f310d9a9b..85937e4653 100644
--- a/app/controllers/admin/badges_controller.rb
+++ b/app/controllers/admin/badges_controller.rb
@@ -64,7 +64,7 @@ class Admin::BadgesController < Admin::AdminController
 
     head :ok
   rescue CSV::MalformedCSVError
-    raise Discourse::InvalidParameters
+    render_json_error I18n.t('badges.mass_award.errors.invalid_csv'), status: 400
   end
 
   def badge_types
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index b21568c59f..75c51c64ac 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -4128,6 +4128,9 @@ en:
       This document is CC-BY-SA. It was last updated May 31, 2013.
 
   badges:
+    mass_award:
+      errors:
+        invalid_csv: We couldn't read that CSV file. Please confirm it has one email per line.
     editor:
       name: Editor
       description: First post edit

GitHub sha: d3091edc

1 Like