From 7a1a1286d2d482a15ea55c030f2952897877d2ce Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 27 Jan 2023 15:49:36 +0100 Subject: [PATCH] Factorize two reflexes into one: BulkActionsInOrdersListReflex --- .../bulk_actions_in_orders_list_reflex.rb | 23 +++++++++++++++++++ .../resend_confirmation_email_reflex.rb | 13 ----------- app/reflexes/send_invoice_reflex.rb | 13 ----------- .../resend_confirmation_email_controller.js | 2 +- .../controllers/send_invoice_controller.js | 2 +- 5 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 app/reflexes/bulk_actions_in_orders_list_reflex.rb delete mode 100644 app/reflexes/resend_confirmation_email_reflex.rb delete mode 100644 app/reflexes/send_invoice_reflex.rb diff --git a/app/reflexes/bulk_actions_in_orders_list_reflex.rb b/app/reflexes/bulk_actions_in_orders_list_reflex.rb new file mode 100644 index 0000000000..54501049e7 --- /dev/null +++ b/app/reflexes/bulk_actions_in_orders_list_reflex.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class BulkActionsInOrdersListReflex < ApplicationReflex + def resend_confirmation_email(order_ids) + Spree::Order.where(id: order_ids).find_each do |o| + Spree::OrderMailer.confirm_email_for_customer(o.id, true).deliver_later if can? :resend, o + end + + flash[:success] = I18n.t("admin.resend_confirmation_emails_feedback", count: order_ids.count) + cable_ready.dispatch_event(name: "modal:close") + morph "#flashes", render(partial: "shared/flashes", locals: { flashes: flash }) + end + + def send_invoice(order_ids) + Spree::Order.where(id: order_ids).find_each do |o| + Spree::OrderMailer.invoice_email(o.id).deliver_later unless o.distributor.can_invoice? + end + + flash[:success] = I18n.t("admin.send_invoice_feedback", count: order_ids.count) + cable_ready.dispatch_event(name: "modal:close") + morph "#flashes", render(partial: "shared/flashes", locals: { flashes: flash }) + end +end diff --git a/app/reflexes/resend_confirmation_email_reflex.rb b/app/reflexes/resend_confirmation_email_reflex.rb deleted file mode 100644 index d43ef5f05a..0000000000 --- a/app/reflexes/resend_confirmation_email_reflex.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class ResendConfirmationEmailReflex < ApplicationReflex - def confirm(order_ids) - Spree::Order.where(id: order_ids).find_each do |o| - Spree::OrderMailer.confirm_email_for_customer(o.id, true).deliver_later if can? :resend, o - end - - flash[:success] = I18n.t("admin.resend_confirmation_emails_feedback", count: order_ids.count) - cable_ready.dispatch_event(name: "modal:close") - morph "#flashes", render(partial: "shared/flashes", locals: { flashes: flash }) - end -end diff --git a/app/reflexes/send_invoice_reflex.rb b/app/reflexes/send_invoice_reflex.rb deleted file mode 100644 index 8f75ac185c..0000000000 --- a/app/reflexes/send_invoice_reflex.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class SendInvoiceReflex < ApplicationReflex - def confirm(order_ids) - Spree::Order.where(id: order_ids).find_each do |o| - Spree::OrderMailer.invoice_email(o.id).deliver_later unless o.distributor.can_invoice? - end - - flash[:success] = I18n.t("admin.send_invoice_feedback", count: order_ids.count) - cable_ready.dispatch_event(name: "modal:close") - morph "#flashes", render(partial: "shared/flashes", locals: { flashes: flash }) - end -end diff --git a/app/webpacker/controllers/resend_confirmation_email_controller.js b/app/webpacker/controllers/resend_confirmation_email_controller.js index 81e88ee70f..ea48c61416 100644 --- a/app/webpacker/controllers/resend_confirmation_email_controller.js +++ b/app/webpacker/controllers/resend_confirmation_email_controller.js @@ -6,6 +6,6 @@ export default class extends BulkActionsController { } confirm() { - super.confirm("ResendConfirmationEmailReflex#confirm"); + super.confirm("BulkActionsInOrdersList#resend_confirmation_email"); } } diff --git a/app/webpacker/controllers/send_invoice_controller.js b/app/webpacker/controllers/send_invoice_controller.js index 37c80d01c7..747735f0ee 100644 --- a/app/webpacker/controllers/send_invoice_controller.js +++ b/app/webpacker/controllers/send_invoice_controller.js @@ -6,6 +6,6 @@ export default class extends BulkActionsController { } confirm() { - super.confirm("SendInvoiceReflex#confirm"); + super.confirm("BulkActionsInOrdersList#send_invoice"); } }