Skip to content

Commit

Permalink
Merge pull request #12778 from chahmedejaz/bugfix/12596-fix-annoying-…
Browse files Browse the repository at this point in the history
…oc-warning-display

[BUU] Fix Messy flash notifications on new products page
  • Loading branch information
dacook authored Aug 16, 2024
2 parents 059dceb + 46e54f4 commit 9170799
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
15 changes: 12 additions & 3 deletions app/controllers/spree/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ class BaseController < ApplicationController

before_action :authorize_admin
before_action :set_locale
before_action :warn_invalid_order_cycles, if: :html_request?
before_action :warn_invalid_order_cycles, if: :page_load_request?

# Warn the user when they have an active order cycle with hubs that are not ready
# for checkout (ie. does not have valid shipping and payment methods).
def warn_invalid_order_cycles
return if flash[:notice].present?
return if flash[:notice].present? || session[:displayed_order_cycle_warning]

warning = OrderCycles::WarningService.new(spree_current_user).call
flash[:notice] = warning if warning.present?
return if warning.blank?

flash.now[:notice] = warning
session[:displayed_order_cycle_warning] = true
end

protected
Expand Down Expand Up @@ -81,6 +84,12 @@ def check_json_authenticity

private

def page_load_request?
return false if request.format.include?('turbo')

html_request?
end

def html_request?
request.format.html?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@
click_link 'Orders'
end

# Click dismiss on distributor warning
click_button 'Dismiss'

# Click cancel with unsaved changes
dismiss_confirm "" do
click_button 'Cancel'
Expand Down Expand Up @@ -168,9 +165,6 @@
# Go to incoming step
click_button 'Next'

# Click dismiss on distributor warning
click_button 'Dismiss'

# Go to outgoing step
click_button 'Next'

Expand All @@ -192,9 +186,6 @@
click_link 'Orders'
end

# Click dismiss on distributor warning
click_button 'Dismiss'

# Click cancel with unsaved changes
dismiss_confirm "" do
click_button 'Cancel'
Expand Down
5 changes: 0 additions & 5 deletions spec/system/admin/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ def new_order_with_distribution(distributor, order_cycle)
visit spree.edit_admin_order_path(order)

expect(page).not_to have_content different_shipping_method_for_distributor1.name
click_button 'Dismiss'

find('.edit-method').click

Expand Down Expand Up @@ -1099,8 +1098,6 @@ def new_order_with_distribution(distributor, order_cycle)
expect(page).to have_selector 'h1', text: 'Customer Details'
click_link "Order Details"

click_button 'Dismiss'

expect(page).to have_content 'Add Product'
select2_select product.name, from: 'add_variant_id', search: true

Expand All @@ -1111,8 +1108,6 @@ def new_order_with_distribution(distributor, order_cycle)
expect(page).to have_select2 'order_distributor_id', with_options: [distributor1.name]
expect(page).not_to have_select2 'order_distributor_id', with_options: [distributor2.name]

click_button 'Dismiss'

expect(page).to have_select2 'order_order_cycle_id',
with_options: ["#{order_cycle1.name} (open)"]
expect(page).not_to have_select2 'order_order_cycle_id',
Expand Down
18 changes: 18 additions & 0 deletions spec/system/admin/overview_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@
text: "MANAGE ORDER CYCLES"
end
end

context "with open order cycles of distributors not ready for checkout" do
let!(:order_cycle) { create(:simple_order_cycle, distributors: [d1]) }

it 'should only display the order cycle warning once after login' do
# First visit the page after login
visit spree.admin_dashboard_path
expected_oc_warning = I18n.t(
:active_distributors_not_ready_for_checkout_message_singular,
distributor_names: d1.name
)
expect(page).to have_content(expected_oc_warning)

# Reload the page
visit spree.admin_dashboard_path
expect(page).not_to have_content(expected_oc_warning)
end
end
end
end
end

0 comments on commit 9170799

Please sign in to comment.