From 3474c60f4c1de2d1be0f86b9e06be5e71aef6870 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Thu, 15 Aug 2024 05:23:29 +0500 Subject: [PATCH] 12596 - fix annoying oc warning display - such that it only displays once per user session --- app/controllers/spree/admin/base_controller.rb | 15 ++++++++++++--- spec/system/admin/overview_spec.rb | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index f926612ef0..6489292bb4 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -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 diff --git a/spec/system/admin/overview_spec.rb b/spec/system/admin/overview_spec.rb index 47df19512e..a6ca4d1ed3 100644 --- a/spec/system/admin/overview_spec.rb +++ b/spec/system/admin/overview_spec.rb @@ -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