fix: ganti throw Exception di ActivityObserver dengan Filament Notification, guard creator null
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Observers;
|
|||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Models\ActivityLog;
|
use App\Models\ActivityLog;
|
||||||
use App\Services\NotificationService;
|
use App\Services\NotificationService;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class ActivityObserver
|
class ActivityObserver
|
||||||
@@ -22,12 +23,18 @@ class ActivityObserver
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (isset($allowed[$old]) && ! in_array($new, $allowed[$old])) {
|
if (isset($allowed[$old]) && ! in_array($new, $allowed[$old])) {
|
||||||
throw new \Exception("Transisi status dari {$old} ke {$new} tidak diizinkan.");
|
Notification::make()->title('Transisi tidak diizinkan')
|
||||||
|
->body("Status tidak bisa diubah dari {$old} ke {$new}.")
|
||||||
|
->danger()->send();
|
||||||
|
$activity->status = $old;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wajib isi executed_at & execution_notes jika sudah approved dan mau ditandai selesai
|
|
||||||
if ($new === 'approved' && $activity->wasChanged('executed_at') && empty($activity->execution_notes)) {
|
if ($new === 'approved' && $activity->wasChanged('executed_at') && empty($activity->execution_notes)) {
|
||||||
throw new \Exception('Catatan pelaksanaan wajib diisi.');
|
Notification::make()->title('Catatan pelaksanaan wajib diisi')
|
||||||
|
->danger()->send();
|
||||||
|
$activity->executed_at = null;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivityLog::create([
|
ActivityLog::create([
|
||||||
@@ -44,7 +51,7 @@ class ActivityObserver
|
|||||||
route('filament.admin.resources.activities.edit', $activity));
|
route('filament.admin.resources.activities.edit', $activity));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($new, ['approved', 'rejected'])) {
|
if (in_array($new, ['approved', 'rejected']) && $activity->creator) {
|
||||||
NotificationService::send(
|
NotificationService::send(
|
||||||
$activity->creator,
|
$activity->creator,
|
||||||
$new === 'approved' ? 'Kegiatan Disetujui' : 'Kegiatan Ditolak',
|
$new === 'approved' ? 'Kegiatan Disetujui' : 'Kegiatan Ditolak',
|
||||||
|
|||||||
Reference in New Issue
Block a user