Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin stock locations form #6160

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<label class="flex gap-2 items-center">
<%= hidden_field_tag "#{f.object_name}[active]", "0" %>
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[active]",
value: "1",
checked: f.object.active
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::AdjustmentReason.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::AdjustmentReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<label class="flex gap-2 items-center">
<%= hidden_field_tag "#{f.object_name}[active]", "0" %>
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[active]",
value: "1",
checked: f.object.active
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::AdjustmentReason.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::AdjustmentReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
8 changes: 1 addition & 7 deletions admin/app/components/solidus_admin/layout/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ def page_header_actions(&block)
end

def page_header_back(back_path)
render component("ui/button").new(
tag: :a,
title: t(".back"),
icon: "arrow-left-line",
scheme: :secondary,
href: back_path
)
render component("ui/button").back(path: back_path)
end

def page_header_title(title, &block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,17 @@

<div class="w-full flex gap-4">
<%= turbo_frame_tag address_frame_id do %>
<%= render component('ui/forms/address').new(address: @address, name: "order[#{@type}_address_attributes]") %>
<%= render component('ui/forms/address').new(addressable: @address, fieldset_name: "order[#{@type}_address_attributes]") %>
<% end %>
</div>

<label class="flex gap-2 items-center">
<%= form.hidden_field use_attribute, value: '0', id: false %>

<%= render component("ui/forms/checkbox").new(
name: "#{form.object_name}[#{use_attribute}]",
checked: @address == (@type == 'ship' ? @order.bill_address : @order.ship_address),
value: '1'
) %>

<span class="font-normal text-xs">
<%= t(".use_this_address.#{@type}") %>
</span>
</label>
<%= render component("ui/forms/checkbox").new(
object_name: form.object_name,
method: use_attribute,
checked: @address == (@type == 'ship' ? @order.bill_address : @order.ship_address)
) do |checkbox| %>
<%= checkbox.with_caption(text: t(".use_this_address.#{@type}"), size: :xs) %>
<% end %>
</div>
<% end %>

Expand All @@ -56,11 +50,7 @@
) %>
</form>

<%= render component("ui/button").new(
tag: :button,
text: t(".save"),
form: form_id
) %>
<%= render component("ui/button").save(form: form_id) %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
en:
save: Save
cancel: Cancel
back: Back
select_address: Select address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<%= page_header_back(solidus_admin.orders_path) %>
<%= page_header_title(t('.title', number: @order.number)) %>
<%= page_header_actions do %>
<%= render component("ui/button").new(tag: :button, scheme: :secondary, text: t(".discard"), form: form_id) %>
<%= render component("ui/button").new(tag: :button, text: t(".save"), form: form_id) %>
<%= render component("ui/button").discard(path: solidus_admin.orders_path) %>
<%= render component("ui/button").save(form: form_id) %>
<% end %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
en:
save: Save
discard: Discard
title: "Order %{number}"
customer: Customer
no_name: No name available
order_email: Order contact email
back: Back to orders
same_as_shipping: Same as shipping address

edit_email: "Edit order email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
target: :_blank,
scheme: :ghost
) %>
<%= render component("ui/button").new(tag: :button, text: t(".save"), form: form_id) %>
<%= render component("ui/button").save(form: form_id) %>
<% end %>
<% end %>

Expand Down Expand Up @@ -120,14 +120,10 @@
type: :date,
value: f.object.discontinue_on&.to_date
) %>
<label class="flex gap-2 items-center">
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[promotionable]",
checked: f.object.promotionable
) %>
<span class="font-normal text-xs"><%= Spree::Product.human_attribute_name :promotionable %></span>
<%= render component("ui/toggletip").new(text: t(".hints.promotionable_html")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :promotionable, checked: f.object.promotionable) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::Product.human_attribute_name(:promotionable), size: :xs) %>
<%= checkbox.with_hint(text: t(".hints.promotionable_html")) %>
<% end %>
<% end %>

<%= render component('ui/panel').new(title: "Product organization") do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
en:
save: "Save"
back: "Back"
duplicate: "Duplicate"
view: "View online"
delete: "Delete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<label class="flex gap-2 items-center">
<%= hidden_field_tag "#{f.object_name}[active]", "0" %>
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[active]",
value: "1",
checked: f.object.active
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::RefundReason.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::RefundReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<label class="flex gap-2 items-center">
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[active]",
value: "1",
checked: f.object.active
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::RefundReason.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::RefundReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
<%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<label class="flex gap-2 items-center">
<%= hidden_field_tag "#{f.object_name}[active]", "0" %>
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[active]",
value: "1",
checked: f.object.active
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::ReturnReason.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::ReturnReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
<%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<label class="flex gap-2 items-center">
<%= hidden_field_tag "#{f.object_name}[active]", "0" %>
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[active]",
value: "1",
checked: f.object.active
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::ReturnReason.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::ReturnReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
</div>
<% modal.with_actions do %>
<form method="dialog">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= page do %>
<%= page_header do %>
<%= page_header_back(back_url) %>
<%= page_header_title(@stock_location.name) %>
<%= page_header_actions do %>
<%= render component("ui/button").discard(path: back_url) %>
<%= render component("ui/button").save(form: form_id) %>
<% end %>
<% end %>

<%= render component("stock_locations/form").new(stock_location: @stock_location, url: form_url, id: form_id) %>

<%= page_footer do %>
<%= render component("ui/button").save(form: form_id) %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class SolidusAdmin::StockLocations::Edit::Component < SolidusAdmin::Resources::Edit::Component
include SolidusAdmin::Layout::PageHelpers
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<%= form_for @stock_location, url: @url, data: { turbo: false }, html: { id: @id } do |f| %>
<%= page_with_sidebar do %>
<%= page_with_sidebar_main do %>
<%= render component('ui/panel').new do %>
<div class="flex gap-4 w-full">
<%= render component("ui/forms/field").text_field(f, :name, class: "required", width: :half) %>
<%= render component("ui/forms/field").text_field(f, :admin_name, width: :half) %>
</div>
<%= render component("ui/forms/field").text_field(f, :code) %>
<% end %>

<%= render component('ui/panel').new(title: t('.address')) do %>
<%= render component('ui/forms/address').new(addressable: @stock_location, fieldset_name: 'stock_location', include_name_field: false) %>
<% end %>
<% end %>

<%= page_with_sidebar_aside do %>
<%= render component('ui/panel').new(title: t('.availability')) do %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:active)) %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
<% end %>

<%= render component('ui/panel').new(title: t('.setup')) do %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :default, checked: f.object.default) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:default)) %>
<% end %>

<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :backorderable_default, checked: f.object.backorderable_default) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:backorderable_default)) %>
<%= checkbox.with_hint(text: t(".hints.backorderable_default")) %>
<% end %>

<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :propagate_all_variants, checked: f.object.propagate_all_variants) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:propagate_all_variants)) %>
<%= checkbox.with_hint(text: t(".hints.propagate_all_variants")) %>
<% end %>

<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :restock_inventory, checked: f.object.restock_inventory) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:restock_inventory)) %>
<%= checkbox.with_hint(text: t(".hints.restock_inventory")) %>
<% end %>

<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :fulfillable, checked: f.object.fulfillable) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:fulfillable)) %>
<%= checkbox.with_hint(text: t(".hints.fulfillable")) %>
<% end %>

<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :check_stock_on_transfer, checked: f.object.check_stock_on_transfer) do |checkbox| %>
<%= checkbox.with_caption(text: Spree::StockLocation.human_attribute_name(:check_stock_on_transfer)) %>
<%= checkbox.with_hint(text: t(".hints.check_stock_on_transfer")) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class SolidusAdmin::StockLocations::Form::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(stock_location:, id:, url:)
@stock_location = stock_location
@id = id
@url = url
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
en:
address: "Address"
availability: "Availability"
hints:
active: "This determines whether stock from this location can be used when building packages"
backorderable_default: "When checked, stock items in this location will default to allowing backorders"
check_stock_on_transfer: "When checked, inventory levels will be checked when performing stock transfers"
fulfillable: "When unchecked, this indicates that items in this location don't require actual fulfilment. Stock will not be checked when shipping and emails will not be sent"
propagate_all_variants: "When checked, this will create a stock item for each variant in this stock location"
restock_inventory: "When checked, returned inventory can be added back to this location's stock levels"
setup: "Setup"
Loading