feat: tambah database notifications dan widget activity log di dashboard
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Posts\Tables;
|
||||
|
||||
use App\Services\NotificationService;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
@@ -56,7 +57,12 @@ class PostsTable
|
||||
->color('info')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => ! $isAdmin && in_array($record->status, ['draft', 'rejected']))
|
||||
->action(fn ($record) => $record->update(['status' => 'pending', 'rejection_reason' => null])),
|
||||
->action(function ($record): void {
|
||||
$record->update(['status' => 'pending', 'rejection_reason' => null]);
|
||||
NotificationService::toRole('ketua', 'Artikel Menunggu Persetujuan',
|
||||
"\"{$record->title}\" oleh {$record->author->name} menunggu persetujuan.", 'warning',
|
||||
route('filament.admin.resources.posts.edit', $record));
|
||||
}),
|
||||
|
||||
// Untuk admin: approve
|
||||
Action::make('publish')
|
||||
@@ -65,11 +71,15 @@ class PostsTable
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
||||
->action(fn ($record) => $record->update([
|
||||
->action(fn ($record) => tap($record->update([
|
||||
'status' => 'published',
|
||||
'published_at' => now(),
|
||||
'reviewed_by' => auth()->id(),
|
||||
])),
|
||||
]), fn () => NotificationService::send(
|
||||
$record->author, 'Artikel Diterbitkan',
|
||||
"Artikel \"{$record->title}\" Anda telah diterbitkan.", 'success',
|
||||
route('filament.admin.resources.posts.edit', $record)
|
||||
))),
|
||||
|
||||
// Untuk admin: tolak
|
||||
Action::make('reject')
|
||||
@@ -80,11 +90,15 @@ class PostsTable
|
||||
->form([
|
||||
Textarea::make('rejection_reason')->label('Alasan Penolakan')->required(),
|
||||
])
|
||||
->action(fn ($record, array $data) => $record->update([
|
||||
->action(fn ($record, array $data) => tap($record->update([
|
||||
'status' => 'rejected',
|
||||
'reviewed_by' => auth()->id(),
|
||||
'rejection_reason' => $data['rejection_reason'],
|
||||
])),
|
||||
]), fn () => NotificationService::send(
|
||||
$record->author, 'Artikel Ditolak',
|
||||
"Artikel \"{$record->title}\" ditolak: {$data['rejection_reason']}", 'danger',
|
||||
route('filament.admin.resources.posts.edit', $record)
|
||||
))),
|
||||
|
||||
EditAction::make()
|
||||
->visible(fn ($record) => $isAdmin || in_array($record->status, ['draft', 'rejected'])),
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ActivityLogWidget extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 2;
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
protected static ?string $heading = 'Aktivitas Terbaru';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(ActivityLog::with('user')->latest()->limit(15))
|
||||
->columns([
|
||||
TextColumn::make('created_at')->label('Waktu')
|
||||
->dateTime('d M Y H:i')->sortable(),
|
||||
TextColumn::make('user.name')->label('Oleh')->default('Sistem'),
|
||||
TextColumn::make('action')->label('Aksi')->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'created' => 'success',
|
||||
'verified' => 'info',
|
||||
'approved' => 'success',
|
||||
'rejected' => 'danger',
|
||||
'status_changed' => 'warning',
|
||||
'voted' => 'info',
|
||||
default => 'gray',
|
||||
}),
|
||||
TextColumn::make('description')->label('Keterangan')->wrap(),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user