-
-
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.
Merge pull request #6031 from MadelineCollier/admin-user-store-credit…
…-refactor [Admin][Users] Add new admin store credits edit_amount flow
- Loading branch information
Showing
14 changed files
with
333 additions
and
33 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
23 changes: 23 additions & 0 deletions
23
admin/app/components/solidus_admin/users/store_credits/edit_amount/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,23 @@ | ||
<%= turbo_frame_tag :edit_amount_modal do %> | ||
<%= render component("ui/modal").new(title: t(".title")) do |modal| %> | ||
<%= form_for @store_credit, url: solidus_admin.update_amount_user_store_credit_path(@user, @store_credit), method: :put, 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, | ||
:store_credit_reason_id, | ||
store_credit_reasons_select_options.html_safe, | ||
include_blank: t('spree.choose_reason'), | ||
html: { required: true } | ||
) %> | ||
</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/show").new(user: @user, store_credit: @store_credit, events: @store_credit_events) %> |
19 changes: 19 additions & 0 deletions
19
admin/app/components/solidus_admin/users/store_credits/edit_amount/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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Users::StoreCredits::EditAmount::Component < SolidusAdmin::BaseComponent | ||
def initialize(user:, store_credit:, events:, reasons:) | ||
@user = user | ||
@store_credit = store_credit | ||
@store_credit_events = events | ||
@store_credit_reasons = reasons | ||
end | ||
|
||
def form_id | ||
dom_id(@store_credit, "#{stimulus_id}_edit_amount_form") | ||
end | ||
|
||
def store_credit_reasons_select_options | ||
# Placeholder + Store Credit Reasons | ||
"<option value>#{t('.choose_reason')}</option>" + options_from_collection_for_select(@store_credit_reasons, :id, :name) | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
admin/app/components/solidus_admin/users/store_credits/edit_amount/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: Edit Store Credit | ||
cancel: Cancel | ||
submit: Update Store Credit | ||
choose_reason: Choose Reason For Changing Amount |
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
15 changes: 15 additions & 0 deletions
15
admin/app/components/solidus_admin/users/store_credits/show/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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
en: | ||
solidus_admin: | ||
store_credits: | ||
title: "Store Credits" | ||
destroy: | ||
success: "Store credit was successfully removed." | ||
create: | ||
success: "Store credit was successfully created." | ||
update_amount: | ||
success: "Store credit was successfully updated." |
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 |
---|---|---|
|
@@ -310,14 +310,17 @@ | |
|
||
before do | ||
stub_authorization!(admin) | ||
find_row("$199.00").click | ||
end | ||
|
||
it "shows individual store credit details" do | ||
find_row("$199.00").click | ||
expect(page).to have_content("Users / [email protected] / Store Credit / $199.00") | ||
expect(page).to have_content("Store Credit History") | ||
expect(page).to have_content("Action") | ||
expect(page).to have_content("Added") | ||
end | ||
|
||
it "allows invalidating of the store credit" do | ||
click_on "Invalidate" | ||
select "credit given in error", from: "store_credit_reason_id" | ||
click_on "Invalidate" | ||
|
@@ -328,6 +331,57 @@ | |
expect(page).to have_content("Reason for updating") | ||
expect(page).to have_content("credit given in error") | ||
end | ||
|
||
context "when editing the store credit amount" do | ||
context "with invalid amount" do | ||
it "shows the appropriate error message" do | ||
click_on "Edit Amount" | ||
expect(page).to have_selector("dialog", wait: 5) | ||
expect(page).to have_content("Edit Store Credit") | ||
|
||
within("dialog") do | ||
fill_in "Amount", with: "" | ||
click_on "Update Store Credit" | ||
expect(page).to have_content("must be greater than 0") | ||
click_on "Cancel" | ||
end | ||
end | ||
end | ||
|
||
context "without a valid reason" do | ||
it "shows the appropriate error message" do | ||
click_on "Edit Amount" | ||
expect(page).to have_selector("dialog", wait: 5) | ||
expect(page).to have_content("Edit Store Credit") | ||
|
||
within("dialog") do | ||
fill_in "Amount", with: "100" | ||
click_on "Update Store Credit" | ||
expect(page).to have_content("Store Credit reason must be provided") | ||
click_on "Cancel" | ||
end | ||
end | ||
end | ||
|
||
context "with valid params" do | ||
it "allows editing of the store credit amount" do | ||
click_on "Edit Amount" | ||
expect(page).to have_selector("dialog", wait: 5) | ||
expect(page).to have_content("Edit Store Credit") | ||
|
||
# Invalid amount | ||
within("dialog") do | ||
fill_in "Amount", with: "666" | ||
select "credit given in error", from: "store_credit[store_credit_reason_id]" | ||
click_on "Update Store Credit" | ||
end | ||
|
||
expect(page).to have_content("Users / [email protected] / Store Credit / $666.00") | ||
expect(page).to have_content("Adjustment") | ||
expect(page).to have_content("credit given in error") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.