Skip to content

Commit

Permalink
Add new refund reason modal form
Browse files Browse the repository at this point in the history
The form for creating a new refund reason opens in a modal by
leveraging Turbo frames.
  • Loading branch information
spaghetticode committed Mar 12, 2024
1 parent aea7119 commit 4b346d0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ def row_url(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason)
end

def actions
def turbo_frames
%w[new_refund_reason_modal]
end

def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: spree.new_admin_refund_reason_path,
href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal },
icon: "add-line",
class: "align-self-end w-full",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= turbo_frame_tag :new_refund_reason_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @refund_reason, url: solidus_admin.refund_reasons_path, 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") %>
<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::TaxCategory.human_attribute_name :active %></span>
<%= render component("ui/toggletip").new(text: t(".hints.active")) %>
</label>
</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')) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= render component("refund_reasons/index").new(page: @page) %>
12 changes: 12 additions & 0 deletions admin/app/components/solidus_admin/refund_reasons/new/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
@refund_reason = refund_reason
end

def form_id
dom_id(@refund_reason, "#{stimulus_id}_new_refund_reason_form")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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."
2 changes: 1 addition & 1 deletion admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
admin_resources :stock_locations, only: [:index, :destroy]
admin_resources :stores, only: [:index, :destroy]
admin_resources :zones, only: [:index, :destroy]
admin_resources :refund_reasons, only: [:index, :destroy]
admin_resources :refund_reasons, only: [:index, :new, :destroy]
admin_resources :reimbursement_types, only: [:index]
admin_resources :return_reasons, only: [:index, :destroy]
admin_resources :adjustment_reasons, only: [:index, :destroy]
Expand Down

0 comments on commit 4b346d0

Please sign in to comment.