forked from code4romania/asistent-medical-comunitar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added display banner for Nurse user (code4romania#202)
- Loading branch information
1 parent
e8af181
commit b119949
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
app/Filament/Widgets/DashboardNotifications/NurseDashboardActivityNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Widgets\DashboardNotifications; | ||
|
||
use App\Models\Activity; | ||
use Filament\Widgets\Widget; | ||
|
||
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ă!'; | ||
|
||
public static function canView(): bool | ||
{ | ||
|
||
return auth()->user()->isNurse(); | ||
} | ||
|
||
public function getNotification(): string|null | ||
{ | ||
|
||
$latestActivity = Activity::latest() | ||
->where('subject_id', auth()->id()) | ||
->where('subject_type', 'intervention') | ||
->whereNot('event', 'dismissed') | ||
->first(); | ||
|
||
$notificationDismissed = Activity::latest() | ||
->where('subject_id', auth()->id()) | ||
->where('subject_type', 'intervention') | ||
->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 null; | ||
} | ||
|
||
public function getNotificationIcon(): string | ||
{ | ||
return 'resources/svg/warning.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] | ||
]); | ||
|
||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.