Skip to content

Commit c9791ca

Browse files
committed
Use modal UI for solidus_promotions index/add/edit
Introduces changes to new solidus promotions UI based on solidusio#6046. Had to override few methods in controller and components due to differences in routing and naming in solidus_promotions. Copied capybara driver setup from legacy_promotions.
1 parent 55891cc commit c9791ca

File tree

19 files changed

+175
-48
lines changed

19 files changed

+175
-48
lines changed

bin/rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LIBS = %w[
99
core
1010
sample
1111
legacy_promotions
12+
promotions
1213
]
1314

1415
# Ignore line info, e.g. foo/bar.rb:123 would become foo/bar.rb

promotions/MIGRATING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bundle exec rails solidus_promotions:migrate_existing_promotions
4444

4545
This will create equivalents of the legacy promotion configuration in SolidusPromotions.
4646

47-
Now, change `config/initializers/solidus_promotions.rb` to use your new promotion configuration:
47+
Now, change `config/initializers/spree.rb` to use your new promotion configuration:
4848

4949
## Change store behavior to use SolidusPromotions
5050

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
en:
2+
solidus_admin:
3+
promotion_categories:
4+
title: "Promotion Categories"
25
solidus_promotions:
36
promotion_categories:
47
title: "Promotion Categories"
8+
create:
9+
success: "Promotion Category was successfully created."
10+
update:
11+
success: "Promotion Category was successfully updated."
512
destroy:
613
success: "Promotion Categories were successfully removed."

promotions/config/locales/promotions.en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
en:
2+
solidus_admin:
3+
promotions:
4+
title: "Promotions"
25
solidus_promotions:
36
promotions:
47
title: "Promotions"

promotions/config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}) do
1313
scope :admin do
1414
scope :solidus do
15-
admin_resources :promotion_categories, only: [:index, :destroy]
15+
admin_resources :promotion_categories, except: [:show]
1616
admin_resources :promotions, only: [:index, :destroy]
1717
end
1818
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
2+
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3+
<%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
4+
<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+
</div>
8+
<% modal.with_actions do %>
9+
<form method="dialog">
10+
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
11+
</form>
12+
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
13+
<% end %>
14+
<% end %>
15+
<% end %>
16+
<% end %>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
class SolidusPromotions::PromotionCategories::Edit::Component < SolidusAdmin::BaseComponent
4+
def initialize(record)
5+
super
6+
@promotion_category = record
7+
end
8+
9+
def form_id
10+
dom_id(@promotion_category, "#{stimulus_id}_edit_promotion_category_form")
11+
end
12+
13+
def form_url
14+
solidus_promotions.promotion_category_path(@promotion_category, **search_filter_params)
15+
end
16+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
en:
2+
title: "Edit Promotion Category"
3+
cancel: "Cancel"
4+
submit: "Update Promotion Category"

promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ def model_class
55
SolidusPromotions::PromotionCategory
66
end
77

8-
def row_url(promotion_category)
9-
solidus_promotions.edit_admin_promotion_category_path(promotion_category)
8+
def title
9+
t('solidus_promotions.promotion_categories.title')
10+
end
11+
12+
def edit_path(record)
13+
solidus_promotions.edit_promotion_category_path(record, **search_filter_params)
14+
end
15+
16+
def turbo_frames
17+
%w[resource_modal]
1018
end
1119

1220
def page_actions
1321
render component("ui/button").new(
1422
tag: :a,
1523
text: t(".add"),
16-
href: solidus_promotions.new_admin_promotion_category_path,
24+
href: solidus_promotions.new_promotion_category_path(**search_filter_params),
25+
data: { turbo_frame: :resource_modal },
1726
icon: "add-line"
1827
)
1928
end
@@ -22,7 +31,7 @@ def batch_actions
2231
[
2332
{
2433
label: t(".batch_actions.delete"),
25-
action: solidus_promotions.promotion_categories_path,
34+
action: solidus_promotions.promotion_categories_path(**search_filter_params),
2635
method: :delete,
2736
icon: "delete-bin-7-line"
2837
}
@@ -39,17 +48,21 @@ def columns
3948
def name_column
4049
{
4150
header: :name,
42-
data: ->(promotion_category) do
43-
content_tag :div, promotion_category.name
51+
data: ->(record) do
52+
link_to record.name, edit_path(record),
53+
data: { turbo_frame: :resource_modal },
54+
class: 'body-link'
4455
end
4556
}
4657
end
4758

4859
def code_column
4960
{
5061
header: :code,
51-
data: ->(promotion_category) do
52-
content_tag :div, promotion_category.code
62+
data: ->(record) do
63+
link_to record.code, edit_path(record),
64+
data: { turbo_frame: :resource_modal },
65+
class: 'body-link'
5366
end
5467
}
5568
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
2+
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3+
<%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
4+
<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+
</div>
8+
<% modal.with_actions do %>
9+
<form method="dialog">
10+
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
11+
</form>
12+
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
13+
<% end %>
14+
<% end %>
15+
<% end %>
16+
<% end %>

0 commit comments

Comments
 (0)