11 changed files with 65 additions and 33 deletions
@ -1,15 +0,0 @@
|
||||
<div class="app-unread-notification"> |
||||
<div class="govuk-width-container"> |
||||
<br> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters govuk-body"> |
||||
<p class="govuk-!-font-weight-bold"><%= oldest_unread_notification.title %></p> |
||||
<%= govuk_link_to oldest_unread_notification.link_text, notification_path(oldest_unread_notification), class: "govuk-link--inverse govuk-!-font-weight-bold"%> |
||||
</div> |
||||
<p class="govuk-grid-column-one-quarter govuk-!-text-align-right "> |
||||
<%= govuk_link_to "Dismiss", notification_dismiss_path(oldest_unread_notification), class: "govuk-link--inverse"%> |
||||
</p> |
||||
</div> |
||||
<br> |
||||
</div> |
||||
</div> |
||||
@ -1,12 +0,0 @@
|
||||
class UnreadNotification < ViewComponent::Base |
||||
attr_reader :current_user |
||||
|
||||
def initialize(current_user:) |
||||
@current_user = current_user |
||||
super |
||||
end |
||||
|
||||
def oldest_unread_notification |
||||
Notification.unread_by(@current_user).first |
||||
end |
||||
end |
||||
@ -1,8 +1,17 @@
|
||||
class NotificationsController < ApplicationController |
||||
|
||||
def dismiss |
||||
Notification.find(params[:notification_id]).mark_as_read! for: current_user |
||||
current_user.oldest_active_unread_notification.mark_as_read! for: current_user |
||||
|
||||
redirect_to root_path |
||||
redirect_back(fallback_location: root_path) |
||||
end |
||||
|
||||
def show |
||||
@notification = current_user.oldest_active_unread_notification |
||||
if @notification&.page_content |
||||
render "show" |
||||
else |
||||
redirect_back(fallback_location: root_path) |
||||
end |
||||
end |
||||
end |
||||
|
||||
@ -0,0 +1,21 @@
|
||||
<div class="app-unread-notification"> |
||||
<div class="govuk-width-container"> |
||||
<br> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-three-quarters"> |
||||
<% if current_user.active_unread_notifications.count > 1 %> |
||||
<p>Notification 1 of <%= current_user.active_unread_notifications.count %></p> |
||||
<% end %> |
||||
<p class="govuk-!-font-weight-bold"><%= current_user.oldest_active_unread_notification.title %></p> |
||||
<% if current_user.oldest_active_unread_notification.page_content.present? %> |
||||
<div class ="govuk-body"> |
||||
<%= govuk_link_to current_user.oldest_active_unread_notification.link_text, notifications_path, class: "govuk-link--inverse govuk-!-font-weight-bold"%> |
||||
</div> |
||||
<% end %> |
||||
</div> |
||||
<p class="govuk-grid-column-one-quarter govuk-!-text-align-right "> |
||||
<%= govuk_link_to "Dismiss", dismiss_notifications_path, class: "govuk-link--inverse"%> |
||||
</p> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
@ -0,0 +1,15 @@
|
||||
<% content_for :title, "Notification" %> |
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link(href: :back) %> |
||||
<% end %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<h1 class="govuk-heading-xl"><%= @notification.title %></h1> |
||||
<%= @notification.page_content %> |
||||
</div> |
||||
</div> |
||||
<br> |
||||
<div> |
||||
<%= govuk_button_link_to "Back to Home", root_path %> |
||||
</div> |
||||
Loading…
Reference in new issue