Skip to content

Commit e5930a6

Browse files
authored
Merge pull request #6294 from chaimann/admin-form-builder
[Admin] Solidus form builder
2 parents 907bf8a + 31952bb commit e5930a6

File tree

61 files changed

+391
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+391
-261
lines changed

admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<%= turbo_frame_tag :resource_form, target: "_top" do %>
22
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3-
<%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
3+
<%= solidus_form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
44
<div class="flex flex-col gap-6 pb-4">
5-
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6-
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
7-
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
8-
<%= checkbox.with_label(text: Spree::AdjustmentReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
9-
<%= checkbox.with_hint(text: t(".hints.active")) %>
10-
<% end %>
5+
<%= f.text_field(:name, class: "required") %>
6+
<%= f.text_field(:code, class: "required") %>
7+
<%= f.checkbox(:active, hint: t(".hints.active")) %>
118
</div>
129
<% modal.with_actions do %>
1310
<form method="dialog">
1411
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
1512
</form>
16-
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
13+
<%= f.submit %>
1714
<% end %>
1815
<% end %>
1916
<% end %>

admin/app/components/solidus_admin/adjustment_reasons/edit/component.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
en:
44
title: "Edit Adjustment Reason"
55
cancel: "Cancel"
6-
submit: "Update Adjustment Reason"
76
hints:
87
active: "When checked, this adjustment reason will be available for selection when adding adjustments to orders."

admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<%= turbo_frame_tag :resource_form, target: "_top" do %>
22
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3-
<%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
3+
<%= solidus_form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
44
<div class="flex flex-col gap-6 pb-4">
5-
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6-
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
7-
<%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %>
8-
<%= checkbox.with_label(text: Spree::AdjustmentReason.human_attribute_name(:active), weight: :semibold, size: :xs, classes: 'ml-2') %>
9-
<%= checkbox.with_hint(text: t(".hints.active")) %>
10-
<% end %>
5+
<%= f.text_field(:name, class: "required") %>
6+
<%= f.text_field(:code, class: "required") %>
7+
<%= f.checkbox(:active, hint: t(".hints.active")) %>
118
</div>
129
<% modal.with_actions do %>
1310
<form method="dialog">
1411
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
1512
</form>
16-
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
13+
<%= f.submit %>
1714
<% end %>
1815
<% end %>
1916
<% end %>

admin/app/components/solidus_admin/adjustment_reasons/new/component.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
en:
44
title: "New Adjustment Reason"
55
cancel: "Cancel"
6-
submit: "Add Adjustment Reason"
76
hints:
87
active: "When checked, this adjustment reason will be available for selection when adding adjustments to orders."

admin/app/components/solidus_admin/base_component.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class BaseComponent < ViewComponent::Base
99
include SolidusAdmin::ComponentsHelper
1010
include SolidusAdmin::StimulusHelper
1111
include SolidusAdmin::VoidElementsHelper
12+
include SolidusAdmin::SolidusFormHelper
1213
include Turbo::FramesHelper
1314

1415
def icon_tag(name, **attrs)

admin/app/components/solidus_admin/orders/cart/component.html.erb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@
3737
) %>
3838
</td>
3939
<td class="px-6 py-4">
40-
<%= form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), html: {
40+
<%= solidus_form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), html: {
4141
"data-controller": "readonly-when-submitting"
4242
}) do |f| %>
43-
<%= render component("ui/forms/input").new(
44-
name: "#{f.object_name}[quantity]",
43+
<%= f.input(
44+
:quantity,
4545
type: :number,
46-
value: line_item.quantity,
4746
"aria-label": "Quantity",
4847
min: 0,
4948
class: "!w-16 inline-block",
5049
"data-action": "input->#{stimulus_id}#updateLineItem",
5150
) %>
52-
<% render component("ui/button").new(type: :submit, text: "Update", class: "inline-block") %>
51+
<% f.submit(class: "inline-block") %>
5352
<% end %>
5453
</td>
5554
<td class="px-6 py-4">

admin/app/components/solidus_admin/orders/cart/result/component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<%= render component('ui/forms/search/result').new do %>
2-
<%= form_for(@order.line_items.build(variant: @variant), url: solidus_admin.order_line_items_path(@order), method: :post, html: {
2+
<%= solidus_form_for(@order.line_items.build(variant: @variant), url: solidus_admin.order_line_items_path(@order), method: :post, html: {
33
"data-controller": "readonly-when-submitting",
44
class: "flex items-center",
55
}) do |f| %>
6-
<%= hidden_field_tag("#{f.object_name}[variant_id]", @variant.id) %>
6+
<%= f.hidden_field(:variant_id) %>
77
<div class="flex gap-2 grow">
88
<%= render component("ui/thumbnail").new(
99
src: @image&.url(:small),

admin/app/components/solidus_admin/orders/show/address/component.html.erb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="<%= stimulus_id %>" data-controller="<%= stimulus_id %>">
22
<%= turbo_frame_tag "edit_order_#{params[:type]}_address_modal" do %>
33
<%= render component("ui/modal").new(title: t(".title.#{@type}")) do |modal| %>
4-
<%= form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
4+
<%= solidus_form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
55
<div class="w-full flex flex-col mb-4">
66
<div class="flex justify-between items-center mb-4 relative">
77
<h2 class="text-sm font-semibold">
@@ -32,13 +32,11 @@
3232
<% end %>
3333
</div>
3434

35-
<%= render component("ui/forms/checkbox").new(
36-
object_name: form.object_name,
37-
method: use_attribute,
38-
checked: @address == (@type == 'ship' ? @order.bill_address : @order.ship_address)
39-
) do |checkbox| %>
40-
<%= checkbox.with_label(text: t(".use_this_address.#{@type}"), size: :xs) %>
41-
<% end %>
35+
<%= form.checkbox(use_attribute,
36+
checked: @address == (@type == 'ship' ? @order.bill_address : @order.ship_address),
37+
label: t(".use_this_address.#{@type}"),
38+
label_options: { size: :xs })
39+
%>
4240
</div>
4341
<% end %>
4442

admin/app/components/solidus_admin/orders/show/customer_search/result/component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<%= render component('ui/forms/search/result').new do %>
22
<% if @customer %>
3-
<%= form_for(@order, url: solidus_admin.order_path(@order), html: {
3+
<%= solidus_form_for(@order, url: solidus_admin.order_path(@order), html: {
44
"data-controller": "readonly-when-submitting",
55
class: "flex items-center",
66
}) do |f| %>
7-
<%= hidden_field_tag("#{f.object_name}[user_id]", @customer.id) %>
7+
<%= f.hidden_field(:user_id, value: @customer.id) %>
88
<button type="submit" class="flex gap-2 grow items-center">
99
<%= render component("ui/icon").new(name: "user-line", class: 'w-5 h-5 m-2') %>
1010
<div class="flex-col text-left">

admin/app/components/solidus_admin/orders/show/email/component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="<%= stimulus_id %>">
22
<%= turbo_frame_tag "edit_order_email_modal" do %>
33
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
4-
<%= form_for @order, url: solidus_admin.order_path(@order), html: { id: form_id } do |f| %>
5-
<%= render component("ui/forms/field").text_field(f, :email) %>
4+
<%= solidus_form_for @order, url: solidus_admin.order_path(@order), html: { id: form_id } do |f| %>
5+
<%= f.text_field(:email) %>
66
<label class="font-normal text-sm mt-4 block">
77
<%= t('.guest_checkout') %>:
88
<output class="font-semibold text-sm"><%= @order.user ? t('.no') : t('.yes') %></output>

0 commit comments

Comments
 (0)