Skip to content

Commit

Permalink
Refactor confirm modal conponent to handle forms
Browse files Browse the repository at this point in the history
  • Loading branch information
wandji20 committed Oct 23, 2024
1 parent 7af0ac6 commit 74ebcb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 40 deletions.
4 changes: 2 additions & 2 deletions app/components/confirm_modal_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(
controller: nil,
message: nil,
confirm_actions: nil,
confirm_reflexes: nil,
form_url: nil,
confirm_button_class: :primary,
confirm_button_text: I18n.t('js.admin.modals.confirm'),
cancel_button_text: I18n.t('js.admin.modals.cancel'),
Expand All @@ -17,7 +17,7 @@ def initialize(
super(id:, close_button: true)
@confirm_actions = confirm_actions
@reflex = reflex
@confirm_reflexes = confirm_reflexes
@form_url = form_url
@controller = controller
@message = message
@confirm_button_class = confirm_button_class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
%div{ id: @id, "data-controller": "modal #{@controller}", "data-action": "keyup@document->modal#closeIfEscapeKey", "data-#{@controller}-reflex-value": @reflex }
.reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" }
.reveal-modal.fade.tiny.modal-component{ "data-modal-target": "modal" }
= content
- if @confirm_actions
= content

= render @message if @message
= render @message if @message

%div{ class: "modal-actions #{@actions_alignment_class}" }
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: @cancel_button_text, "data-action": "click->modal#close" }
%input{ id: 'modal-confirm-button', class: "button icon-plus #{@confirm_button_class}", type: 'button', value: @confirm_button_text, "data-action": @confirm_actions, "data-reflex": @confirm_reflexes }
%div{ class: "modal-actions #{@actions_alignment_class}" }
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: @cancel_button_text, "data-action": "click->modal#close" }
%input{ id: 'modal-confirm-button', class: "button icon-plus #{@confirm_button_class}", type: 'button', value: @confirm_button_text, "data-action": @confirm_actions }
- elsif @form_url
= form_with(url: @form_url, method: :post, data: { turbo: true, controller: 'bulk-actions' }) do
= content
%p{ class: "modal-actions #{@actions_alignment_class}" }
%button.button.secondary{ type: "button", 'data-action': 'click->modal#close' }
= @cancel_button_text
%button.button.primary{ type: 'submit' }
= @confirm_button_text
46 changes: 13 additions & 33 deletions app/views/spree/admin/orders/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,16 @@
= render 'spree/admin/shared/custom-confirm'
= render ModalComponent.new(id: "resend_confirmation", modal_class: 'tiny', close_button: false) do
= form_with(url: resend_confirmation_emails_admin_orders_path, method: :post, data: { turbo: true, controller: 'bulk-actions' }) do
.margin-bottom-30
= t('.resend_confirmation_confirm_html')
%p.modal-actions.justify-space-around
%button.button.secondary{ type: "button", 'data-action': 'click->modal#close' }
= t('js.admin.modals.cancel')
%button.button.primary{ type: 'submit' }
= t('js.admin.modals.confirm')
= render ModalComponent.new(id: "send_invoice", modal_class: 'tiny', close_button: false) do
= form_with(url: send_invoices_admin_orders_path, method: :post, data: { turbo: true, controller: 'bulk-actions' }) do
.margin-bottom-30
= t('.send_invoice_confirm_html')
%p.modal-actions.justify-space-around
%button.button.secondary{ type: "button", 'data-action': 'click->modal#close' }
= t('js.admin.modals.cancel')
%button.button.primary{ type: 'submit' }
= t('js.admin.modals.confirm')
= render ModalComponent.new(id: "cancel_orders", modal_class: 'tiny', close_button: false) do
= form_with(url: cancel_orders_admin_orders_path, method: :post, data: { turbo: true, controller: 'bulk-actions' }) do
.margin-bottom-30
= t("js.admin.orders.cancel_the_order_html")
.margin-bottom-30
= render partial: "spree/admin/orders/messages/cancel_orders"
%p.modal-actions.justify-space-around
%button.button.secondary{ type: "button", 'data-action': 'click->modal#close' }
= t('js.admin.modals.cancel')
%button.button.primary{ type: 'submit' }
= t('js.admin.modals.confirm')
= render ConfirmModalComponent.new(id: "resend_confirmation", form_url: resend_confirmation_emails_admin_orders_path) do
.margin-bottom-30
= t('.resend_confirmation_confirm_html')
= render ConfirmModalComponent.new(id: "send_invoice", form_url: send_invoices_admin_orders_path) do
.margin-bottom-30
= t('.send_invoice_confirm_html')
= render ConfirmModalComponent.new(id: "cancel_orders", form_url: cancel_orders_admin_orders_path) do
.margin-bottom-30
= t("js.admin.orders.cancel_the_order_html")
.margin-bottom-30
= render partial: "spree/admin/orders/messages/cancel_orders"

0 comments on commit 74ebcb2

Please sign in to comment.