diff --git a/admin/app/components/solidus_admin/layout/flashes/alerts/component.html.erb b/admin/app/components/solidus_admin/layout/flashes/alerts/component.html.erb
new file mode 100644
index 00000000000..816626a867f
--- /dev/null
+++ b/admin/app/components/solidus_admin/layout/flashes/alerts/component.html.erb
@@ -0,0 +1,7 @@
+
+
+ <% alerts.each do |key, text| %>
+ <%= render component("ui/alert").new(title: text[:title], message: text[:message], scheme: key.to_sym) %>
+ <% end %>
+
+
diff --git a/admin/app/components/solidus_admin/layout/flashes/alerts/component.rb b/admin/app/components/solidus_admin/layout/flashes/alerts/component.rb
new file mode 100644
index 00000000000..7fbdb102c79
--- /dev/null
+++ b/admin/app/components/solidus_admin/layout/flashes/alerts/component.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class SolidusAdmin::Layout::Flashes::Alerts::Component < SolidusAdmin::BaseComponent
+ attr_reader :alerts
+
+ # Construct alert flashes like:
+ # flash[:alert] = { : { title: "", message: "" } }
+ # See +SolidusAdmin::UI::Alert::Component::SCHEMES+ for available alert types.
+ #
+ # If a string is passed to flash[:alert], we treat it is a body of the alert message and fall back to +danger+ type
+ # and default title (see +SolidusAdmin::UI::Alert::Component+).
+ def initialize(alerts:)
+ if alerts.is_a?(String)
+ alerts = { danger: { message: alerts } }
+ end
+
+ @alerts = alerts.slice(*SolidusAdmin::UI::Alert::Component::SCHEMES.keys)
+ end
+end
diff --git a/admin/app/components/solidus_admin/layout/flashes/toasts/component.html.erb b/admin/app/components/solidus_admin/layout/flashes/toasts/component.html.erb
new file mode 100644
index 00000000000..14ea6c06657
--- /dev/null
+++ b/admin/app/components/solidus_admin/layout/flashes/toasts/component.html.erb
@@ -0,0 +1,5 @@
+
+ <% toasts.each do |key, message| %>
+ <%= render component("ui/toast").new(text: message, scheme: key.to_sym == :error ? :error : :default) %>
+ <% end %>
+
diff --git a/admin/app/components/solidus_admin/layout/flashes/toasts/component.rb b/admin/app/components/solidus_admin/layout/flashes/toasts/component.rb
new file mode 100644
index 00000000000..3aecd62d0a0
--- /dev/null
+++ b/admin/app/components/solidus_admin/layout/flashes/toasts/component.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class SolidusAdmin::Layout::Flashes::Toasts::Component < SolidusAdmin::BaseComponent
+ attr_reader :toasts
+
+ def initialize(toasts:)
+ @toasts = toasts
+ end
+end
diff --git a/admin/app/components/solidus_admin/ui/alert/component.html.erb b/admin/app/components/solidus_admin/ui/alert/component.html.erb
index a6a892fd2ae..60a7dae1591 100644
--- a/admin/app/components/solidus_admin/ui/alert/component.html.erb
+++ b/admin/app/components/solidus_admin/ui/alert/component.html.erb
@@ -18,7 +18,7 @@
<%= @title %>
-
<%= @description.html_safe %>
+
<%= @message.html_safe %>
diff --git a/admin/app/components/solidus_admin/ui/alert/component.rb b/admin/app/components/solidus_admin/ui/alert/component.rb
index c183eaf8659..5605ce4b596 100644
--- a/admin/app/components/solidus_admin/ui/alert/component.rb
+++ b/admin/app/components/solidus_admin/ui/alert/component.rb
@@ -35,12 +35,16 @@ class SolidusAdmin::UI::Alert::Component < SolidusAdmin::BaseComponent
},
}
- def initialize(title:, description:, scheme: :success)
+ def initialize(title:, message:, scheme: :success)
@title = title
- @description = description
+ @message = message
@scheme = scheme
end
+ def before_render
+ @title = @title.presence || t(".defaults.titles")[@scheme.to_sym]
+ end
+
def icon
icon_tag(ICONS.dig(@scheme.to_sym, :name), class: "w-5 h-5 #{ICONS.dig(@scheme.to_sym, :class)}")
end
diff --git a/admin/app/components/solidus_admin/ui/alert/component.yml b/admin/app/components/solidus_admin/ui/alert/component.yml
index a97e4c40196..79f02ceb5e3 100644
--- a/admin/app/components/solidus_admin/ui/alert/component.yml
+++ b/admin/app/components/solidus_admin/ui/alert/component.yml
@@ -1,2 +1,8 @@
en:
- close: Close
+ close: "Close"
+ defaults:
+ titles:
+ danger: "Caution"
+ info: "Info"
+ success: "Success"
+ warning: "Warning"
diff --git a/admin/app/controllers/solidus_admin/adjustments_controller.rb b/admin/app/controllers/solidus_admin/adjustments_controller.rb
index 350bc3dee5d..f085652211e 100644
--- a/admin/app/controllers/solidus_admin/adjustments_controller.rb
+++ b/admin/app/controllers/solidus_admin/adjustments_controller.rb
@@ -20,7 +20,7 @@ def index
def lock
@adjustments = @order.all_adjustments.not_finalized.where(id: params[:id])
@adjustments.each(&:finalize!)
- flash[:success] = t('.success')
+ flash[:notice] = t('.success')
redirect_to order_adjustments_path(@order), status: :see_other
end
@@ -28,7 +28,7 @@ def lock
def unlock
@adjustments = @order.all_adjustments.finalized.where(id: params[:id])
@adjustments.each(&:unfinalize!)
- flash[:success] = t('.success')
+ flash[:notice] = t('.success')
redirect_to order_adjustments_path(@order), status: :see_other
end
@@ -36,7 +36,7 @@ def unlock
def destroy
@adjustments = @order.all_adjustments.where(id: params[:id])
@adjustments.destroy_all
- flash[:success] = t('.success')
+ flash[:notice] = t('.success')
redirect_to order_adjustments_path(@order), status: :see_other
end
diff --git a/admin/app/controllers/solidus_admin/base_controller.rb b/admin/app/controllers/solidus_admin/base_controller.rb
index bd7442f4eee..8854547389a 100644
--- a/admin/app/controllers/solidus_admin/base_controller.rb
+++ b/admin/app/controllers/solidus_admin/base_controller.rb
@@ -19,6 +19,7 @@ class BaseController < ApplicationController
helper 'solidus_admin/components'
helper 'solidus_admin/layout'
+ helper 'solidus_admin/flash'
private
diff --git a/admin/app/controllers/solidus_admin/customers_controller.rb b/admin/app/controllers/solidus_admin/customers_controller.rb
index af79d4d483a..b86ef95c1e6 100644
--- a/admin/app/controllers/solidus_admin/customers_controller.rb
+++ b/admin/app/controllers/solidus_admin/customers_controller.rb
@@ -13,7 +13,7 @@ def show
def destroy
if @order.update(user: nil)
- flash[:success] = t('.success')
+ flash[:notice] = t('.success')
else
flash[:error] = t('.error')
end
diff --git a/admin/app/controllers/solidus_admin/products_controller.rb b/admin/app/controllers/solidus_admin/products_controller.rb
index e5f22336ed3..4475d11cb47 100644
--- a/admin/app/controllers/solidus_admin/products_controller.rb
+++ b/admin/app/controllers/solidus_admin/products_controller.rb
@@ -43,7 +43,7 @@ def update
@product = Spree::Product.friendly.find(params[:id])
if @product.update(product_params)
- flash[:success] = t('spree.successfully_updated', resource: [
+ flash[:notice] = t('spree.successfully_updated', resource: [
Spree::Product.model_name.human,
@product.name.inspect,
].join(' '))
diff --git a/admin/app/controllers/solidus_admin/users_controller.rb b/admin/app/controllers/solidus_admin/users_controller.rb
index 7e7d181a1bd..04eaa09ac1e 100644
--- a/admin/app/controllers/solidus_admin/users_controller.rb
+++ b/admin/app/controllers/solidus_admin/users_controller.rb
@@ -37,7 +37,7 @@ def update_addresses
set_address_from_params
if @address.valid? && @user.update(user_params)
- flash[:success] = t(".#{@type}.success")
+ flash[:notice] = t(".#{@type}.success")
respond_to do |format|
format.turbo_stream { render turbo_stream: '' }
diff --git a/admin/app/helpers/solidus_admin/flash_helper.rb b/admin/app/helpers/solidus_admin/flash_helper.rb
new file mode 100644
index 00000000000..81e35651f4b
--- /dev/null
+++ b/admin/app/helpers/solidus_admin/flash_helper.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+# Reserve :alert for messages that should go in UI alert component. Everything else will be shown in UI toast.
+module SolidusAdmin
+ module FlashHelper
+ def toasts
+ flash.to_hash.with_indifferent_access.except(:alert)
+ end
+
+ def alerts
+ flash.to_hash.with_indifferent_access.fetch(:alert, {})
+ end
+ end
+end
diff --git a/admin/app/views/layouts/solidus_admin/application.html.erb b/admin/app/views/layouts/solidus_admin/application.html.erb
index 6755eea3c1d..5508ea9da15 100644
--- a/admin/app/views/layouts/solidus_admin/application.html.erb
+++ b/admin/app/views/layouts/solidus_admin/application.html.erb
@@ -31,10 +31,7 @@
-
- <% flash.each do |key, message| %>
- <%= render component("ui/toast").new(text: message, scheme: key.to_sym == :error ? :error : :default) %>
- <% end %>
-
+ <%= render component("layout/flashes/alerts").new(alerts:) %>
+ <%= render component("layout/flashes/toasts").new(toasts:) %>