Skip to content

Commit

Permalink
feat: added 2nd display banner for Nurse user and a banner for Coordi…
Browse files Browse the repository at this point in the history
…nator user (code4romania#202)
  • Loading branch information
RazvanRauta committed Oct 28, 2024
1 parent 4823614 commit 108c00d
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

namespace App\Filament\Widgets\DashboardNotifications;

use App\Models\Activity;
use App\Models\User;
use Filament\Widgets\Widget;

class CoordDashboardActivityNotification extends Widget
{
protected static string $view = 'filament.widgets.dashboard-notification';

protected int|string|array $columnSpan = 'full';


private ?string $pluralNotificationText = ' utilizatori nu au introdus activitate pentru luna precedentă!';
private ?string $singleNotificationText = '1 utilizator nu a introdus activitate pentru luna precedentă!';

public static function canView(): bool
{

return auth()->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]
]);

}

}


Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,37 @@ 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
{

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')
Expand All @@ -36,15 +55,15 @@ public function getNotification(): string|null
->where('event', 'dismissed')
->first();


// Notification was already dismissed
if ($notificationDismissed && $notificationDismissed->created_at->gt($latestActivity->created_at)) {
return 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;
Expand All @@ -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]
]);

}
Expand Down
Loading

0 comments on commit 108c00d

Please sign in to comment.