-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
|
||
describe "StoreCredits", :js, type: :feature do | ||
let(:admin) { create(:admin_user, email: "[email protected]") } | ||
let!(:store_credit_reason) { create(:store_credit_reason, name: "credit given in error") } | ||
let!(:store_credit_category) { create(:store_credit_category, name: "Gift Card") } | ||
let!(:store_credit_type) { create(:primary_credit_type) } | ||
|
||
before do | ||
sign_in admin | ||
|
@@ -27,11 +30,40 @@ | |
it "shows the appropriate content" do | ||
expect(page).to have_content("No Store Credits found.") | ||
end | ||
|
||
it "allows creation of a new store credit" do | ||
click_on "Create One" | ||
|
||
expect(page).to have_selector("dialog", wait: 5) | ||
expect(page).to have_content("New Store Credit") | ||
|
||
within("dialog") do | ||
fill_in "Amount", with: "" | ||
select "Gift Card", from: "store_credit[category_id]" | ||
click_on "Create" | ||
expect(page).to have_content("must be greater than 0") | ||
click_on "Cancel" | ||
end | ||
|
||
click_on "Create One" | ||
|
||
expect(page).to have_selector("dialog", wait: 5) | ||
expect(page).to have_content("New Store Credit") | ||
|
||
within("dialog") do | ||
fill_in "Amount", with: "666.66" | ||
select "Gift Card", from: "store_credit[category_id]" | ||
fill_in "Memo", with: "A brand new store credit, how nice!" | ||
click_on "Create" | ||
end | ||
|
||
expect(page).to have_content("Store credit was successfully created.") | ||
expect(page).to have_content("Current balance: $666.66") | ||
end | ||
end | ||
|
||
context "when a user has store credits" do | ||
let!(:store_credit) { create(:store_credit, amount: 199.00, currency: "USD") } | ||
let!(:store_credit_reason) { create(:store_credit_reason, name: "credit given in error") } | ||
|
||
before do | ||
store_credit.user.update(email: "[email protected]") | ||
|
@@ -61,8 +93,6 @@ | |
end | ||
|
||
context "when clicking through to a single store credit" do | ||
let!(:store_credit_reason) { create(:store_credit_reason, name: "credit given in error") } | ||
|
||
before do | ||
stub_authorization!(admin) | ||
find_row("$199.00").click | ||
|
Oops, something went wrong.