From 108c00df08b4a53427832871dd0b5d0ab276a1b1 Mon Sep 17 00:00:00 2001 From: Razvan Rauta <40596596+RazvanRauta@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:11:00 +0200 Subject: [PATCH] feat: added 2nd display banner for Nurse user and a banner for Coordinator user (#202) --- .../CoordDashboardActivityNotification.php | 83 +++++++++++++++++++ .../NurseDashboardActivityNotification.php | 29 +++++-- resources/svg/danger.svg | 9 ++ .../widgets/dashboard-notification.blade.php | 6 +- 4 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 app/Filament/Widgets/DashboardNotifications/CoordDashboardActivityNotification.php create mode 100644 resources/svg/danger.svg diff --git a/app/Filament/Widgets/DashboardNotifications/CoordDashboardActivityNotification.php b/app/Filament/Widgets/DashboardNotifications/CoordDashboardActivityNotification.php new file mode 100644 index 00000000..54656fec --- /dev/null +++ b/app/Filament/Widgets/DashboardNotifications/CoordDashboardActivityNotification.php @@ -0,0 +1,83 @@ +user()->isCoordinator(); + } + + public function isCoordinator(): bool + { + return auth()->user()->isCoordinator(); + } + + public function getNotification(): string|null + { + + $countOfUsersWithoutActivity = User::query() + ->onlyNurses() + ->activatesInCounty(auth()->user()->county_id) + ->whereNotIn('id', function ($query) { + $query->select('subject_id') + ->from('activity_log') + ->where('subject_type', 'intervention') + ->whereBetween('created_at', [now()->subMonth()->startOfMonth(), now()->subMonth()->endOfMonth()]) + ->whereNot('event', 'dismissed'); + }) + ->count(); + + if ($countOfUsersWithoutActivity === 1) { + return $this->singleNotificationText; + } + + if ($countOfUsersWithoutActivity > 1) { + return $countOfUsersWithoutActivity . $this->pluralNotificationText; + } + + return null; + + } + + public function getNotificationIcon(): string + { + return 'resources/svg/danger.svg'; + + } + + public function dismissNotification(): void + { + // NOT sure about this part + Activity::create([ + 'subject_id' => auth()->id(), + 'causer_id' => auth()->id(), + 'event' => 'dismissed', + 'log_name' => 'default', + 'subject_type' => 'intervention', + 'causer_type' => 'user', + 'description' => 'dismissed notification', + 'properties' => ['notification' => $this->notificationText] + ]); + + } + +} + + diff --git a/app/Filament/Widgets/DashboardNotifications/NurseDashboardActivityNotification.php b/app/Filament/Widgets/DashboardNotifications/NurseDashboardActivityNotification.php index acc72f44..d8942f66 100644 --- a/app/Filament/Widgets/DashboardNotifications/NurseDashboardActivityNotification.php +++ b/app/Filament/Widgets/DashboardNotifications/NurseDashboardActivityNotification.php @@ -12,8 +12,9 @@ class NurseDashboardActivityNotification extends Widget protected static string $view = 'filament.widgets.dashboard-notification'; protected int|string|array $columnSpan = 'full'; - - private ?string $notificationText = 'Nu ați introdus activitate în platformă de mai mult de o săptămână!'; + private ?string $oneWeekNotification = 'Nu ați introdus activitate în platformă de mai mult de o săptămână!'; + private ?string $oneMonthNotification = 'Mai aveți 5 zile pentru a introduce activitatea pentru luna precedentă! Dacă nu introduceți la timp activitatea, nu veți mai avea posibilitatea să o introduceți și veți suferi consecințe!'; + public bool $hideDismissButton = false; public static function canView(): bool { @@ -21,9 +22,27 @@ public static function canView(): bool return auth()->user()->isNurse(); } + public function getNotification(): string|null { + $lastMonthActivityCount = Activity::query() + ->where('subject_id', auth()->id()) + ->where('subject_type', 'intervention') + ->whereBetween('created_at', [now()->subMonth()->startOfMonth(), now()->subMonth()->endOfMonth()]) + ->whereNot('event', 'dismissed') + ->count(); + + /** + * Checks if the user has no activity in the last month, and it's within the first 5 days of the current month. + * If true, hides the dismiss button and returns the one-month notification. + */ + if ($lastMonthActivityCount < 1 && now()->day <= 5) { + $this->hideDismissButton = true; + return $this->oneMonthNotification; + } + + $latestActivity = Activity::latest() ->where('subject_id', auth()->id()) ->where('subject_type', 'intervention') @@ -36,6 +55,7 @@ public function getNotification(): string|null ->where('event', 'dismissed') ->first(); + // Notification was already dismissed if ($notificationDismissed && $notificationDismissed->created_at->gt($latestActivity->created_at)) { return null; @@ -43,8 +63,7 @@ public function getNotification(): string|null // No activity in the last 7 days if ($latestActivity && $latestActivity->created_at->lt(now()->subDays(7))) { - - return $this->notificationText; + return $this->oneWeekNotification; } return null; @@ -67,7 +86,7 @@ public function dismissNotification(): void 'subject_type' => 'intervention', 'causer_type' => 'user', 'description' => 'dismissed notification', - 'properties' => ['notification' => $this->notificationText] + 'properties' => ['notification' => $this->oneWeekNotification] ]); } diff --git a/resources/svg/danger.svg b/resources/svg/danger.svg new file mode 100644 index 00000000..4a8d031c --- /dev/null +++ b/resources/svg/danger.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/resources/views/filament/widgets/dashboard-notification.blade.php b/resources/views/filament/widgets/dashboard-notification.blade.php index bc355ff7..39d3225f 100644 --- a/resources/views/filament/widgets/dashboard-notification.blade.php +++ b/resources/views/filament/widgets/dashboard-notification.blade.php @@ -6,16 +6,20 @@
warning icon

{{$this->getNotification()}}

+ @if(auth()->user()->isCoordinator()) + Vezi lista → + @endif
+ @if(!auth()->user()->isCoordinator() && !$this->hideDismissButton)
+ @endif @else @endif -