Warn about calls closing and content coming off the site
A dashboard widget lists what expires in the next two weeks, and a daily command reminds whoever edits it a week and a day ahead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
50
app/Notifications/ExpiringSoon.php
Normal file
50
app/Notifications/ExpiringSoon.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification as FilamentNotification;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* A digest: what this person looks after that is about to close or come off
|
||||
* the site.
|
||||
*/
|
||||
class ExpiringSoon extends Notification
|
||||
{
|
||||
/**
|
||||
* @param Collection<int, array<string, mixed>> $items
|
||||
*/
|
||||
public function __construct(public readonly Collection $items) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
}
|
||||
|
||||
public function toDatabase(object $notifiable): array
|
||||
{
|
||||
$first = $this->items->first();
|
||||
|
||||
return FilamentNotification::make()
|
||||
->title(trans_choice('panel.expiring.notification.title', $this->items->count(), ['count' => $this->items->count()]))
|
||||
->body($this->items
|
||||
->map(fn (array $item) => $item['title'].' — '.__('panel.expiring.events.'.$item['event'], [
|
||||
'when' => $item['at']->diffForHumans(),
|
||||
'date' => $item['at']->isoFormat('LL'),
|
||||
]))
|
||||
->implode("\n"))
|
||||
->icon('heroicon-o-clock')
|
||||
->iconColor('warning')
|
||||
->actions($this->items->count() === 1 ? [
|
||||
Action::make('open')
|
||||
->label(__('panel.expiring.notification.open'))
|
||||
->url($first['url'])
|
||||
->markAsRead(),
|
||||
] : [])
|
||||
->getDatabaseMessage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user