From 60b66540df241e2e0025b4c054a05029208eb15d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 7 Jun 2018 18:09:35 +1000 Subject: [PATCH] Add resend email button to admin user form Fixes https://github.com/openfoodfoundation/openfoodnetwork/issues/1589 --- .../resend_user_email_confirmation.js.coffee | 19 +++++++++++++++++++ .../admin/openfoodnetwork.css.scss | 8 ++++++++ .../admin/users/_email_confirmation.html.haml | 4 +++- config/locales/en.yml | 5 +++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/admin/users/directives/resend_user_email_confirmation.js.coffee diff --git a/app/assets/javascripts/admin/users/directives/resend_user_email_confirmation.js.coffee b/app/assets/javascripts/admin/users/directives/resend_user_email_confirmation.js.coffee new file mode 100644 index 0000000000..b6361ec7ae --- /dev/null +++ b/app/assets/javascripts/admin/users/directives/resend_user_email_confirmation.js.coffee @@ -0,0 +1,19 @@ +angular.module("admin.users").directive "resendUserEmailConfirmation", ($http) -> + scope: + email: "@resendUserEmailConfirmation" + link: (scope, element, attrs) -> + sent = false + text = element.text() + sending = " " + t "js.admin.resend_user_email_confirmation.sending" + done = " " + t "js.admin.resend_user_email_confirmation.done" + failed = " " + t "js.admin.resend_user_email_confirmation.failed" + + element.bind "click", -> + return if sent + element.text(text + sending) + $http.post("/user/spree_user/confirmation", {spree_user: {email: scope.email}}).success (data) -> + sent = true + element.addClass "action--disabled" + element.text text + done + .error (data) -> + element.text text + failed diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index d10ca748d0..348b85820a 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -71,6 +71,14 @@ a { cursor:pointer; } +a.action--disabled { + cursor: default; + + &:hover { + color: #5498da; + } +} + form.order_cycle { h2 { margin-top: 2em; diff --git a/app/views/spree/admin/users/_email_confirmation.html.haml b/app/views/spree/admin/users/_email_confirmation.html.haml index 65be495337..fb2fd75232 100644 --- a/app/views/spree/admin/users/_email_confirmation.html.haml +++ b/app/views/spree/admin/users/_email_confirmation.html.haml @@ -1,2 +1,4 @@ -%p.alert-box +%p.alert-box{"ng-app" => "admin.users"} = t(".confirmation_pending", address: @user.email) + %a{"resend-user-email-confirmation" => @user.email} + = t(".resend") \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 8b06972e95..675ea554a5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2435,6 +2435,10 @@ See the %{link} to find out more about %{sitename}'s features and to start using resolve: Resolve new_tag_rule_dialog: select_rule_type: "Select a rule type:" + resend_user_email_confirmation: + sending: "..." + done: "done ✓" + failed: "failed ✗" out_of_stock: reduced_stock_available: Reduced stock available out_of_stock_text: > @@ -2588,6 +2592,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using users: email_confirmation: confirmation_pending: "Email confirmation is pending. We've sent a confirmation email to %{address}." + resend: "Resend" variants: autocomplete: producer_name: Producer