Handle single order actions with turbo_stream

This commit is contained in:
wandji20
2024-10-19 22:59:45 +01:00
parent 82ee0ab45e
commit f2d8b382a1
8 changed files with 38 additions and 20 deletions

View File

@@ -1,8 +1,15 @@
= render ConfirmModalComponent.new(id: dom_id(@order, :ship), confirm_reflexes: "click->Admin::OrdersReflex#ship", controller: "orders", reflex: "Admin::Orders#ship") do
%div{class: "margin-bottom-30"}
%p= t('spree.admin.orders.shipment.mark_as_shipped_message_html')
%div{class: "margin-bottom-30"}
= hidden_field_tag :id, @order.id
= label_tag do
= check_box_tag :send_shipment_email, "1", true
= t('spree.admin.orders.shipment.mark_as_shipped_label_message')
= render ModalComponent.new(id: dom_id(@order, :ship), modal_class: 'tiny', close_button: false) do
= form_with(url: helpers.ship_admin_order_url(@order), method: :post, data: { turbo: true }) do
%div{class: "margin-bottom-30"}
%p= t('spree.admin.orders.shipment.mark_as_shipped_message_html')
%div{class: "margin-bottom-30"}
= hidden_field_tag :id, @order.id
= hidden_field_tag :current_page, @current_page
= label_tag do
= check_box_tag :send_shipment_email, "1", true
= t('spree.admin.orders.shipment.mark_as_shipped_label_message')
%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')

View File

@@ -1,7 +1,8 @@
# frozen_string_literal: true
class ShipOrderComponent < ViewComponent::Base
def initialize(order:)
def initialize(order:, current_page:)
@order = order
@current_page = current_page
end
end

View File

@@ -1,8 +1,8 @@
%div{ "data-controller": "tooltip" }
- if local_assigns[:shipment]
%button{class: button_class,"data-controller": "modal-link", "data-action": "click->modal-link#open", "data-modal-link-target-value": "ship_order_#{reflex_data_id}", "data-id": reflex_data_id, "data-tooltip-target": "element" }
%button{class: button_class,"data-controller": "modal-link", "data-action": "click->modal-link#open", "data-modal-link-target-value": "ship_order_#{data_id}", "data-id": data_id, "data-tooltip-target": "element" }
- else
%button{class: button_class, "data-reflex": button_reflex, "data-id": reflex_data_id, "data-tooltip-target": "element" }
%button{class: button_class, "data-id": data_id, "data-tooltip-target": "element" }
.tooltip-container
.tooltip{"data-tooltip-target": "tooltip"}
= sanitize tooltip_text

View File

@@ -10,8 +10,7 @@
= "-"
%button{"class": "ship button icon-arrow-right","data-controller": "modal-link",
"data-action": "click->modal-link#open", "data-modal-link-target-value": dom_id(order, :ship)}= t(:ship)
%form
= render ShipOrderComponent.new(order: order)
= render ShipOrderComponent.new(order: order, current_page: :edit)
%table.stock-contents.index
%colgroup

View File

@@ -47,9 +47,9 @@
%i.success.icon-ok-sign{"data-controller": "ephemeral"}
= render AdminTooltipComponent.new(text: t('spree.admin.orders.index.edit'), link_text: "", link: edit_admin_order_path(order), link_class: "icon_link with-tip icon-edit no-text")
- if order.ready_to_ship?
%form
= render ShipOrderComponent.new(order: order)
= render partial: 'admin/shared/tooltip_button', locals: {button_class: "icon-road icon_link with-tip no-text", reflex_data_id: order.id.to_s, tooltip_text: t('spree.admin.orders.index.ship'), shipment: true}
= render ShipOrderComponent.new(order: order, current_page: :index)
= render partial: 'admin/shared/tooltip_button', locals: {button_class: "icon-road icon_link with-tip no-text", data_id: order.id.to_s, tooltip_text: t('spree.admin.orders.index.ship'), shipment: true}
- if order.payment_required? && order.pending_payments.reject(&:requires_authorization?).any?
= render partial: 'admin/shared/tooltip_button', locals: {button_class: "icon-capture icon_link no-text", button_reflex: "click->Admin::OrdersReflex#capture", reflex_data_id: order.id.to_s, tooltip_text: t('spree.admin.orders.index.capture')}
= link_to capture_admin_order_path(order), data: { turbo: true, turbo_method: :post } do
= render partial: 'admin/shared/tooltip_button', locals: {button_class: "icon-capture icon_link no-text", data_id: order.id.to_s, tooltip_text: t('spree.admin.orders.index.capture')}

View File

@@ -0,0 +1,6 @@
- if @saved
= turbo_stream.replace dom_id(@order) do
= render partial: "spree/admin/orders/table_row", locals: { order: @order.reload, success: true }
- else
= turbo_stream.append "flashes" do
= render(partial: 'admin/shared/flashes', locals: { flashes: flash })

View File

@@ -0,0 +1,6 @@
- if @shipped
= turbo_stream.replace dom_id(@order) do
= render partial: "spree/admin/orders/table_row", locals: { order: @order.reload, success: true }
- else
= turbo_stream.append "flashes" do
= render(partial: 'admin/shared/flashes', locals: { flashes: flash })

View File

@@ -13,12 +13,11 @@
%i{ class: link[:icon] }
%span=link[:name]
- else
%a.menu_item{ href: link[:url], target: link[:target] || "_self", data: { method: link[:method], "ujs-navigate": link[:method] ? "false" : "undefined", confirm: link[:confirm] } }
%a.menu_item{ href: link[:url], target: link[:target] || "_self", data: { method: link[:method], confirm: link[:confirm] } }
%span
%i{ class: link[:icon] }
%span=link[:name]
= render 'spree/admin/shared/custom-confirm'
- if order_shipment_ready?(@order)
%form
= render ShipOrderComponent.new(order: @order)
= render ShipOrderComponent.new(order: @order, current_page: :edit)