Skip to content

Commit

Permalink
feat: added display banner for Nurse user (code4romania#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanRauta committed Oct 28, 2024
1 parent e8af181 commit b119949
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
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]
]);

}

}


4 changes: 3 additions & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import.meta.glob([
'../images/**'
'../images/**',
'../svg/**',
]);

window.setEventContents = ({ event, timeText }) => {
Expand All @@ -15,3 +16,4 @@ window.setEventContents = ({ event, timeText }) => {

return { html };
};

3 changes: 3 additions & 0 deletions resources/svg/dismiss.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions resources/svg/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b119949

Please sign in to comment.