forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new admin store credits create flow
- Loading branch information
1 parent
e8593a8
commit 0517f29
Showing
10 changed files
with
303 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
admin/app/components/solidus_admin/users/store_credits/index/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
actionButtonClicked(event) { | ||
const url = new URL(event.params.url, "http://dummy.com") | ||
const params = new URLSearchParams(url.search) | ||
const frameId = params.get('_turbo_frame') | ||
const frame = frameId ? { frame: frameId } : {} | ||
// remove the custom _turbo_frame param from url search: | ||
params.delete('_turbo_frame') | ||
url.search = params.toString() | ||
|
||
window.Turbo.visit(url.pathname + url.search, frame) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,12 @@ def tabs | |
] | ||
end | ||
|
||
def turbo_frames | ||
%w[ | ||
new_store_credit_modal | ||
] | ||
end | ||
|
||
def rows | ||
@store_credits | ||
end | ||
|
31 changes: 31 additions & 0 deletions
31
admin/app/components/solidus_admin/users/store_credits/new/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%= turbo_frame_tag :new_store_credit_modal do %> | ||
<%= render component("ui/modal").new(title: t(".title")) do |modal| %> | ||
<%= form_for @store_credit, url: solidus_admin.user_store_credits_path(@user), method: :post, html: { id: form_id } do |f| %> | ||
<div class="flex flex-col gap-6 pb-4"> | ||
<%= render component("ui/forms/field").text_field(f, :amount, class: "required") %> | ||
<%= render component("ui/forms/field").select( | ||
f, | ||
:currency, | ||
currency_select_options.html_safe, | ||
include_blank: t("spree.currency"), | ||
html: { required: true } | ||
) %> | ||
<%= render component("ui/forms/field").select( | ||
f, | ||
:category_id, | ||
store_credit_categories_select_options.html_safe, | ||
include_blank: t("spree.category"), | ||
html: { required: true } | ||
) %> | ||
<%= render component("ui/forms/field").text_field(f, :memo) %> | ||
</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("users/store_credits/index").new(user: @user, store_credits: @store_credits) %> |
23 changes: 23 additions & 0 deletions
23
admin/app/components/solidus_admin/users/store_credits/new/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Users::StoreCredits::New::Component < SolidusAdmin::BaseComponent | ||
def initialize(user:, store_credit:, categories:) | ||
@user = user | ||
@store_credit = store_credit | ||
@store_credit_categories = categories | ||
@store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc) | ||
end | ||
|
||
def form_id | ||
dom_id(@store_credit, "#{stimulus_id}_new_form") | ||
end | ||
|
||
def currency_select_options | ||
options_from_collection_for_select(Spree::Config.available_currencies, :iso_code, :iso_code, Spree::Config.currency) | ||
end | ||
|
||
def store_credit_categories_select_options | ||
# Placeholder + Store Credit Categories | ||
"<option value>#{t('.choose_category')}</option>" + options_from_collection_for_select(@store_credit_categories, :id, :name) | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
admin/app/components/solidus_admin/users/store_credits/new/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
en: | ||
title: New Store Credit | ||
cancel: Cancel | ||
submit: Create | ||
choose_category: Choose Store Credit Category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.