TenantAtlas/app/Notifications/OperationRunCompleted.php

47 lines
1.2 KiB
PHP

<?php
namespace App\Notifications;
use App\Models\OperationRun;
use App\Models\Tenant;
use App\Support\OperationRunLinks;
use Filament\Notifications\Notification as FilamentNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class OperationRunCompleted extends Notification
{
use Queueable;
public function __construct(
public OperationRun $run
) {}
public function via(object $notifiable): array
{
return ['database'];
}
public function toDatabase(object $notifiable): array
{
$tenant = $this->run->tenant;
$status = match ((string) $this->run->outcome) {
'succeeded' => 'success',
'partially_succeeded' => 'warning',
default => 'danger',
};
return FilamentNotification::make()
->title('Operation completed')
->body("{$this->run->type} ({$this->run->outcome})")
->status($status)
->actions([
\Filament\Actions\Action::make('view')
->label('View run')
->url($tenant instanceof Tenant ? OperationRunLinks::view($this->run, $tenant) : null),
])
->getDatabaseMessage();
}
}