diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0ca885593..88a398cd7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -36,9 +36,15 @@ module ApplicationHelper end end - def flash_class(sticky: false, fixed: false) + def flash_class(level, sticky: false, fixed: false) class_names = [] + case level + when 'notice' + class_names << 'alert-success' + when 'alert', 'error' + class_names << 'alert-danger' + end if sticky class_names << 'sticky' end diff --git a/app/views/layouts/_flash_messages.html.haml b/app/views/layouts/_flash_messages.html.haml index f8b280447..d2e0eff4c 100644 --- a/app/views/layouts/_flash_messages.html.haml +++ b/app/views/layouts/_flash_messages.html.haml @@ -1,22 +1,13 @@ -#flash_messages{ tabindex: '-1' } +#flash_messages{ tabindex: '-1', data: { turbo_force: :server } } #flash_message.center{ class: defined?(unique_classname) ? unique_classname : '' } - if flash.any? - flash.each do |key, value| - sticky = defined?(sticky) ? sticky : false - fixed = defined?(fixed) ? fixed : false - - if flash_role(key) == 'status' - .alert.alert-success{ role: 'status', class: flash_class(sticky: sticky, fixed: fixed), tabindex: '-1', data: { controller: 'autofocus' } } - - if value.class == Array - - value.each do |message| - = sanitize_with_link(message) - %br - - elsif value.present? - = sanitize_with_link(value) - - elsif flash_role(key) == 'alert' - .alert.alert-danger{ role: 'alert', class: flash_class(sticky: sticky, fixed: fixed), tabindex: '-1', data: { controller: 'autofocus' } } - - if value.class == Array - - value.each do |message| - = sanitize_with_link(message) - %br - - elsif value.present? - = sanitize_with_link(value) + .alert{ role: flash_role(key), class: flash_class(key, sticky: sticky, fixed: fixed) } + - if value.class == Array + - value.each do |message| + = sanitize_with_link(message) + %br + - elsif value.present? + = sanitize_with_link(value) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6b70a8097..44416c4b8 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -71,8 +71,10 @@ describe ApplicationHelper do end describe "#flash_class" do - it { expect(flash_class(sticky: true)).to eq 'sticky' } - it { expect(flash_class(fixed: true)).to eq 'alert-fixed' } + it { expect(flash_class('notice')).to eq 'alert-success' } + it { expect(flash_class('alert', sticky: true, fixed: true)).to eq 'alert-danger sticky alert-fixed' } + it { expect(flash_class('error')).to eq 'alert-danger' } + it { expect(flash_class('unknown-level')).to eq '' } end describe "#try_format_date" do