mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
12596 - fix annoying oc warning display
- such that it only displays once per user session
This commit is contained in:
@@ -19,15 +19,18 @@ module Spree
|
||||
|
||||
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 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
|
||||
@@ -81,6 +84,12 @@ module Spree
|
||||
|
||||
private
|
||||
|
||||
def page_load_request?
|
||||
return false if request.format.include?('turbo')
|
||||
|
||||
html_request?
|
||||
end
|
||||
|
||||
def html_request?
|
||||
request.format.html?
|
||||
end
|
||||
|
||||
@@ -117,6 +117,24 @@ RSpec.describe '
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user