Skip to content

Commit

Permalink
chore[Op#56496]: Collapase mixin into a single module
Browse files Browse the repository at this point in the history
"OpModal::" is not really a shared namespace, so no need to nesting here
  • Loading branch information
akabiru committed Sep 30, 2024
1 parent fc92b6d commit 39040c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ApplicationController < ActionController::Base
include AdditionalUrlHelpers
include OpenProjectErrorHelper
include Security::DefaultUrlOptions
include OpModal::Flashable
include OpModalFlashable

layout "base"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@
# See COPYRIGHT and LICENSE files for more details.
#++

module OpModal
module Flashable
extend ActiveSupport::Concern
module OpModalFlashable
extend ActiveSupport::Concern

included do
add_flash_types :op_modal
end
included do
add_flash_types :op_modal
end

def flash_op_modal(component:, parameters: {})
flash[:op_modal] = { component: component.name, parameters: }
end
def flash_op_modal(component:, parameters: {})
flash[:op_modal] = { component: component.name, parameters: }
end

def store_callback_op_modal_flash(component:, parameters: {})
session[:callback_op_modal] = { component: component.name, parameters: }
end
def store_callback_op_modal_flash(component:, parameters: {})
session[:callback_op_modal] = { component: component.name, parameters: }
end

def retrieve_callback_op_modal_flash
session.delete(:callback_op_modal) if session[:callback_op_modal].present?
end
def retrieve_callback_op_modal_flash
session.delete(:callback_op_modal) if session[:callback_op_modal].present?
end
end
2 changes: 1 addition & 1 deletion lookbook/docs/patterns/09-flash-modal.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Internally, the `FlashMessagesHelper#render_flash_messages` will select flash me

### Flash a modal on callback from external service

When you want to display a modal after a callback request from an external service, store the op modal component directly in the `session` in the controller action that performs by calling `OpModal::Flashable#store_callback_op_modal_flash` bofore the open redirect and then extract them in the controller action that handles the callback via `OpTurbo::Flashable#retrieve_callback_op_modal_flash`.
When you want to display a modal after a callback request from an external service, store the op modal component directly in the `session` in the controller action that performs by calling `OpModalFlashable#store_callback_op_modal_flash` bofore the open redirect and then extract them in the controller action that handles the callback via `OpTurbo::Flashable#retrieve_callback_op_modal_flash`.

Ex.

Expand Down

0 comments on commit 39040c6

Please sign in to comment.