mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Factorize two reflexes into one: BulkActionsInOrdersListReflex
This commit is contained in:
23
app/reflexes/bulk_actions_in_orders_list_reflex.rb
Normal file
23
app/reflexes/bulk_actions_in_orders_list_reflex.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -6,6 +6,6 @@ export default class extends BulkActionsController {
|
||||
}
|
||||
|
||||
confirm() {
|
||||
super.confirm("ResendConfirmationEmailReflex#confirm");
|
||||
super.confirm("BulkActionsInOrdersList#resend_confirmation_email");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ export default class extends BulkActionsController {
|
||||
}
|
||||
|
||||
confirm() {
|
||||
super.confirm("SendInvoiceReflex#confirm");
|
||||
super.confirm("BulkActionsInOrdersList#send_invoice");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user