Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dae6322
Update input component to support type: :hidden
chaimann Jun 23, 2025
7002d63
Create custom form builder
chaimann Jun 19, 2025
3e4d53b
Update product form to use new form builder
chaimann Jun 19, 2025
85ad098
Update order page to use new form builder
chaimann Jun 19, 2025
cff70f2
Update roles form to use new form builder
chaimann Jun 19, 2025
34bb79a
Update adjustment reasons to use new form builder
chaimann Jun 23, 2025
a62e7d6
Update store credits form to use new form builder
chaimann Jun 23, 2025
efdd2e3
Update properties form to use new form builder
chaimann Jun 23, 2025
71b468d
Update refund reasons form to use new form builder
chaimann Jun 23, 2025
ff1462b
Update return reasons form to use new form builder
chaimann Jun 23, 2025
3b3a166
Update shipping categories form to use new form builder
chaimann Jun 23, 2025
00c09f6
Update tax categories form to use new form builder
chaimann Jun 23, 2025
a24deee
Update store credit reasons form to use new form builder
chaimann Jun 23, 2025
40898c8
Update zones form to use new form builder
chaimann Jun 23, 2025
f725f4b
Update users form to use new form builder
chaimann Jun 23, 2025
0def0b4
Update stock items form to use new form builder
chaimann Jun 23, 2025
732c4a6
Update promotion categories form to use new form builder
chaimann Jun 23, 2025
7481844
Standardize usage of Form builder #submit method
chaimann Jun 23, 2025
b17e0b1
Update builder#switch_field to expect default label
chaimann Jun 26, 2025
d9e726e
Simplify ternary statement
chaimann Jun 26, 2025
9239413
Assume switch field wants to include hidden by default
chaimann Jun 26, 2025
31952bb
Put checkbox label and hint definition in builder
chaimann Jun 30, 2025
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
@@ -1,19 +1,16 @@
<%= turbo_frame_tag :resource_form, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
<%= solidus_form_for @adjustment_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") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_label(text: Spree::AdjustmentReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
<%= f.text_field(:name, class: "required") %>
<%= f.text_field(:code, class: "required") %>
<%= f.checkbox(:active, hint: t(".hints.active")) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<%= f.submit %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
en:
title: "Edit Adjustment Reason"
cancel: "Cancel"
submit: "Update Adjustment Reason"
hints:
active: "When checked, this adjustment reason will be available for selection when adding adjustments to orders."
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<%= turbo_frame_tag :resource_form, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
<%= solidus_form_for @adjustment_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") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_label(text: Spree::AdjustmentReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
<%= f.text_field(:name, class: "required") %>
<%= f.text_field(:code, class: "required") %>
<%= f.checkbox(:active, hint: t(".hints.active")) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<%= f.submit %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
en:
title: "New Adjustment Reason"
cancel: "Cancel"
submit: "Add Adjustment Reason"
hints:
active: "When checked, this adjustment reason will be available for selection when adding adjustments to orders."
1 change: 1 addition & 0 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BaseComponent < ViewComponent::Base
include SolidusAdmin::ComponentsHelper
include SolidusAdmin::StimulusHelper
include SolidusAdmin::VoidElementsHelper
include SolidusAdmin::SolidusFormHelper
include Turbo::FramesHelper

def icon_tag(name, **attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,18 @@
) %>
</td>
<td class="px-6 py-4">
<%= form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), html: {
<%= solidus_form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), html: {
"data-controller": "readonly-when-submitting"
}) do |f| %>
<%= render component("ui/forms/input").new(
name: "#{f.object_name}[quantity]",
<%= f.input(
:quantity,
type: :number,
value: line_item.quantity,
"aria-label": "Quantity",
min: 0,
class: "!w-16 inline-block",
"data-action": "input->#{stimulus_id}#updateLineItem",
) %>
<% render component("ui/button").new(type: :submit, text: "Update", class: "inline-block") %>
<% f.submit(class: "inline-block") %>
<% end %>
</td>
<td class="px-6 py-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= render component('ui/forms/search/result').new do %>
<%= form_for(@order.line_items.build(variant: @variant), url: solidus_admin.order_line_items_path(@order), method: :post, html: {
<%= solidus_form_for(@order.line_items.build(variant: @variant), url: solidus_admin.order_line_items_path(@order), method: :post, html: {
"data-controller": "readonly-when-submitting",
class: "flex items-center",
}) do |f| %>
<%= hidden_field_tag("#{f.object_name}[variant_id]", @variant.id) %>
<%= f.hidden_field(:variant_id) %>
<div class="flex gap-2 grow">
<%= render component("ui/thumbnail").new(
src: @image&.url(:small),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="<%= stimulus_id %>" data-controller="<%= stimulus_id %>">
<%= turbo_frame_tag "edit_order_#{params[:type]}_address_modal" do %>
<%= render component("ui/modal").new(title: t(".title.#{@type}")) do |modal| %>
<%= form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
<%= solidus_form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
<div class="w-full flex flex-col mb-4">
<div class="flex justify-between items-center mb-4 relative">
<h2 class="text-sm font-semibold">
Expand Down Expand Up @@ -32,13 +32,11 @@
<% end %>
</div>

<%= 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_label(text: t(".use_this_address.#{@type}"), size: :xs) %>
<% end %>
<%= form.checkbox(use_attribute,
checked: @address == (@type == 'ship' ? @order.bill_address : @order.ship_address),
label: t(".use_this_address.#{@type}"),
label_options: { size: :xs })
%>
</div>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%= render component('ui/forms/search/result').new do %>
<% if @customer %>
<%= form_for(@order, url: solidus_admin.order_path(@order), html: {
<%= solidus_form_for(@order, url: solidus_admin.order_path(@order), html: {
"data-controller": "readonly-when-submitting",
class: "flex items-center",
}) do |f| %>
<%= hidden_field_tag("#{f.object_name}[user_id]", @customer.id) %>
<%= f.hidden_field(:user_id, value: @customer.id) %>
<button type="submit" class="flex gap-2 grow items-center">
<%= render component("ui/icon").new(name: "user-line", class: 'w-5 h-5 m-2') %>
<div class="flex-col text-left">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="<%= stimulus_id %>">
<%= turbo_frame_tag "edit_order_email_modal" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @order, url: solidus_admin.order_path(@order), html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :email) %>
<%= solidus_form_for @order, url: solidus_admin.order_path(@order), html: { id: form_id } do |f| %>
<%= f.text_field(:email) %>
<label class="font-normal text-sm mt-4 block">
<%= t('.guest_checkout') %>:
<output class="font-semibold text-sm"><%= @order.user ? t('.no') : t('.yes') %></output>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,21 @@
<% end %>
<% end %>

<%= form_for @product, url: solidus_admin.product_path(@product), html: { id: form_id } do |f| %>
<%= solidus_form_for @product, url: solidus_admin.product_path(@product), html: { id: form_id } do |f| %>
<%= page_with_sidebar do %>
<%= page_with_sidebar_main do %>
<%= render component("ui/panel").new do %>
<%= render component("ui/forms/field").text_field(f, :name) %>
<%= render component("ui/forms/field").text_field(f, :slug) %>
<%= render component("ui/forms/field").text_area(f, :description) %>
<%= f.text_field(:name) %>
<%= f.text_field(:slug) %>
<%= f.text_area(:description) %>
<% end %>

<%= render component("ui/panel").new(title: t(".seo")) do %>
<%= render component("ui/forms/field").text_field(f, :meta_title) %>
<%= render component("ui/forms/field").text_field(f, :meta_description) %>
<%= render component("ui/forms/field").text_area(f, :meta_keywords) %>
<%= render component("ui/forms/field").text_field(f, :gtin) %>
<%= render component("ui/forms/field").select(
f,
:condition,
condition_options,
include_blank: t("spree.unset"),
) %>
<%= f.text_field(:meta_title) %>
<%= f.text_field(:meta_description) %>
<%= f.text_area(:meta_keywords) %>
<%= f.text_field(:gtin) %>
<%= f.select(:condition, condition_options, include_blank: t("spree.unset")) %>
<% end %>
<%= render component("ui/panel").new(title: t(".media")) do |panel| %>
<% panel.with_action(
Expand All @@ -52,15 +47,15 @@
<% end %>

<%= render component("ui/panel").new(title: t(".pricing")) do %>
<%= render component("ui/forms/field").text_field(f, :price) %>
<%= f.text_field(:price) %>
<div class="flex gap-4 justify-items-stretch">
<%= render component("ui/forms/field").text_field(f, :cost_price) %>
<%= render component("ui/forms/field").text_field(f, :cost_currency) %>
<%= f.text_field(:cost_price) %>
<%= f.text_field(:cost_currency) %>
</div>
<% end %>

<%= render component("ui/panel").new(title: t(".stock")) do |panel| %>
<%= render component("ui/forms/field").text_field(f, :sku) %>
<%= f.text_field(:sku) %>

<% panel.with_action(
name: t(".manage_stock"),
Expand All @@ -69,28 +64,20 @@
<% end %>

<%= render component("ui/panel").new(title: t(".shipping")) do %>
<%= render component("ui/forms/field").select(
f,
<%= f.select(
:shipping_category_id,
[[t(".none"), nil]] + Spree::ShippingCategory.order(:name).pluck(:name, :id),
tip: t(".hints.shipping_category_html")
) %>
<%= render component("ui/forms/field").select(
f,
<%= f.select(
:tax_category_id,
[[t(".none"), nil]] + Spree::TaxCategory.order(:name).pluck(:name, :id),
tip: t(".hints.tax_category_html")
) %>
<% end %>

<%= render component("ui/panel").new(title: t(".options")) do %>
<%= render component("ui/forms/field").select(
f,
:option_type_ids,
option_type_options,
multiple: true,
"size" => option_type_options.size,
) %>
<%= f.select(:option_type_ids, option_type_options, multiple: true) %>
<% end %>

<%= render component("ui/panel").new(title: t(".specifications")) do |panel| %>
Expand All @@ -103,34 +90,23 @@

<%= page_with_sidebar_aside do %>
<%= render component("ui/panel").new(title: t(".publishing")) do %>
<%= render component("ui/forms/field").text_field(
f,
<%= f.text_field(
:available_on,
hint: t(".hints.available_on_html"),
type: :date,
value: f.object.available_on&.to_date
) %>
<%= render component("ui/forms/field").text_field(
f,
<%= f.text_field(
:discontinue_on,
hint: t(".hints.discontinue_on_html"),
type: :date,
value: f.object.discontinue_on&.to_date
) %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :promotionable, checked: f.object.promotionable) do |checkbox| %>
<%= checkbox.with_label(text: Spree::Product.human_attribute_name(:promotionable), size: :xs) %>
<%= checkbox.with_hint(text: t(".hints.promotionable_html")) %>
<% end %>
<%= f.checkbox(:promotionable, hint: t(".hints.promotionable_html")) %>
<% end %>

<%= render component("ui/panel").new(title: t(".product_organization")) do %>
<%= render component("ui/forms/field").select(
f,
:taxon_ids,
taxon_options,
multiple: true,
"size" => taxon_options.size, # use a string key to avoid setting the size of the component
) %>
<%= f.select(:taxon_ids, taxon_options, multiple: true) %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<%= turbo_frame_tag :resource_form, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
<%= solidus_form_for @property, 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") %>
<%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %>
<%= f.text_field(:name, class: "required") %>
<%= f.text_field(:presentation, class: "required") %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<%= f.submit(text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<%= turbo_frame_tag :resource_form, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
<%= solidus_form_for @property, 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") %>
<%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %>
<%= f.text_field(:name, class: "required") %>
<%= f.text_field(:presentation, class: "required") %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<%= f.submit(text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<%= turbo_frame_tag :resource_form, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
<%= solidus_form_for @refund_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") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_label(text: Spree::RefundReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
<%= f.text_field(:name, class: "required") %>
<%= f.text_field(:code, class: "required") %>
<%= f.checkbox(:active, hint: t(".hints.active")) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<%= f.submit %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
en:
title: "Edit Refund Reason"
cancel: "Cancel"
submit: "Update Refund Reason"
hints:
active: "When checked, this refund reason will be available for selection when adding refunds to orders."
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<%= turbo_frame_tag :resource_form, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
<%= solidus_form_for @refund_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") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
<%= checkbox.with_label(text: Spree::RefundReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
<%= checkbox.with_hint(text: t(".hints.active")) %>
<% end %>
<%= f.text_field(:name, class: "required") %>
<%= f.text_field(:code, class: "required") %>
<%= f.checkbox(:active, hint: t(".hints.active")) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<%= f.submit %>
<% end %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
en:
title: "New Refund Reason"
cancel: "Cancel"
submit: "Add Refund Reason"
hints:
active: "When checked, this refund reason will be available for selection when refunding orders."
Loading
Loading