Skip to content

Commit

Permalink
Update update_flash_component to be reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmir committed Sep 6, 2024
1 parent f649ca9 commit 46d6b9a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
<%=
component_wrapper do
flex_layout do |flex|
flex.with_row(classes: "op-toast--wrapper") do
render(Primer::Alpha::Banner.new(
full: false,
icon: 'info',
scheme: :default,
data: {
singleton: true
}
)) do |component|
component.with_action_button(
tag: :a,
href: meeting_path(@meeting),
data: { turbo: false },
size: :medium) { I18n.t("label_meeting_reload") }
I18n.t("notice_meeting_updated")
if @button
flex_layout do |flex|
flex.with_row(classes: "op-toast--wrapper") do
render(Primer::Alpha::Banner.new(
full: @full,
icon: @icon,
scheme: @scheme,
data: {
singleton: true
}
)) do |component|
component.with_action_button(
tag: :a,
href: meeting_path(@meeting),
data: { turbo: false },
size: :medium) { @button_message }
@message
end
end
end
else
flex_layout do |flex|
flex.with_row(classes: "op-toast--wrapper") do
render(Primer::Alpha::Banner.new(
full: @full,
icon: @icon,
scheme: @scheme,
data: {
singleton: true
}
)) do
@message
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ class UpdateFlashComponent < ApplicationComponent
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers

def initialize(meeting:)
def initialize(meeting:, message:, full: false, icon: "info", scheme: :default, button: false, button_message: nil)
super

@meeting = meeting
@message = message
@full = full
@icon = icon
@scheme = scheme
@button = button
@button_message = button_message
end
end
end
7 changes: 6 additions & 1 deletion modules/meeting/app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ def check_for_updates
if params[:reference] == @meeting.changed_hash
head :no_content
else
respond_with_flash(Meetings::UpdateFlashComponent.new(meeting: @meeting))
respond_with_flash(Meetings::UpdateFlashComponent.new(
meeting: @meeting,
message: I18n.t("notice_meeting_updated"),
button: true,
button_message: I18n.t("label_meeting_reload")
))
end
end

Expand Down

0 comments on commit 46d6b9a

Please sign in to comment.