2026-04-03 05:18:34 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\Posts\Tables;
|
|
|
|
|
|
2026-04-03 07:57:40 +07:00
|
|
|
use App\Services\NotificationService;
|
2026-04-03 06:48:06 +07:00
|
|
|
use Filament\Actions\Action;
|
2026-04-03 05:18:34 +07:00
|
|
|
use Filament\Actions\BulkActionGroup;
|
|
|
|
|
use Filament\Actions\DeleteBulkAction;
|
|
|
|
|
use Filament\Actions\EditAction;
|
2026-04-05 06:21:16 +07:00
|
|
|
use Filament\Forms\Components\DateTimePicker;
|
2026-04-03 06:48:06 +07:00
|
|
|
use Filament\Forms\Components\Textarea;
|
2026-04-03 05:18:34 +07:00
|
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
|
|
|
|
|
class PostsTable
|
|
|
|
|
{
|
|
|
|
|
public static function configure(Table $table): Table
|
|
|
|
|
{
|
2026-05-11 18:56:59 +00:00
|
|
|
$canReview = auth()->user()?->can('Publish:Post') ?? false;
|
|
|
|
|
$canPublish = $canReview;
|
2026-04-03 07:01:46 +07:00
|
|
|
|
2026-04-03 05:18:34 +07:00
|
|
|
return $table
|
|
|
|
|
->columns([
|
|
|
|
|
TextColumn::make('title')->label('Judul')->searchable()->sortable(),
|
|
|
|
|
TextColumn::make('category')->label('Kategori')->badge()
|
|
|
|
|
->color(fn ($state) => match ($state) {
|
|
|
|
|
'pengumuman' => 'warning',
|
|
|
|
|
'berita' => 'info',
|
|
|
|
|
default => 'gray',
|
|
|
|
|
}),
|
2026-04-03 06:48:06 +07:00
|
|
|
TextColumn::make('status')->badge()
|
|
|
|
|
->color(fn ($state) => match ($state) {
|
|
|
|
|
'published' => 'success',
|
2026-04-05 06:21:16 +07:00
|
|
|
'approved' => 'info',
|
2026-04-03 06:48:06 +07:00
|
|
|
'pending' => 'warning',
|
|
|
|
|
'rejected' => 'danger',
|
|
|
|
|
default => 'gray',
|
2026-04-05 06:21:16 +07:00
|
|
|
})
|
|
|
|
|
->formatStateUsing(fn ($state) => match ($state) {
|
|
|
|
|
'draft' => 'Draft',
|
|
|
|
|
'pending' => 'Menunggu',
|
|
|
|
|
'approved' => 'Disetujui',
|
|
|
|
|
'published' => 'Diterbitkan',
|
|
|
|
|
'rejected' => 'Ditolak',
|
|
|
|
|
default => $state,
|
2026-04-03 06:48:06 +07:00
|
|
|
}),
|
2026-04-05 06:21:16 +07:00
|
|
|
TextColumn::make('author.name')->label('Penulis')->visible($canReview),
|
2026-04-03 05:18:34 +07:00
|
|
|
TextColumn::make('published_at')->label('Dipublikasi')
|
2026-04-05 06:21:16 +07:00
|
|
|
->dateTime('d M Y')->placeholder('-')->sortable(),
|
2026-04-03 05:18:34 +07:00
|
|
|
])
|
|
|
|
|
->filters([
|
2026-04-03 06:48:06 +07:00
|
|
|
SelectFilter::make('status')->options([
|
|
|
|
|
'draft' => 'Draft',
|
|
|
|
|
'pending' => 'Menunggu',
|
2026-04-05 06:21:16 +07:00
|
|
|
'approved' => 'Disetujui',
|
2026-04-03 06:48:06 +07:00
|
|
|
'published' => 'Diterbitkan',
|
|
|
|
|
'rejected' => 'Ditolak',
|
2026-04-03 05:18:34 +07:00
|
|
|
]),
|
|
|
|
|
])
|
2026-04-03 06:48:06 +07:00
|
|
|
->recordActions([
|
2026-04-05 06:21:16 +07:00
|
|
|
// Member: ajukan artikel
|
2026-04-03 07:01:46 +07:00
|
|
|
Action::make('submit')
|
|
|
|
|
->label('Ajukan')
|
|
|
|
|
->icon('heroicon-o-paper-airplane')
|
|
|
|
|
->color('info')
|
|
|
|
|
->requiresConfirmation()
|
2026-04-05 06:21:16 +07:00
|
|
|
->visible(fn ($record) => ! $canReview && in_array($record->status, ['draft', 'rejected']))
|
2026-04-03 07:57:40 +07:00
|
|
|
->action(function ($record): void {
|
|
|
|
|
$record->update(['status' => 'pending', 'rejection_reason' => null]);
|
2026-04-05 06:21:16 +07:00
|
|
|
NotificationService::toRole('editor', 'Artikel Menunggu Persetujuan',
|
2026-04-03 07:57:40 +07:00
|
|
|
"\"{$record->title}\" oleh {$record->author->name} menunggu persetujuan.", 'warning',
|
|
|
|
|
route('filament.admin.resources.posts.edit', $record));
|
|
|
|
|
}),
|
2026-04-03 07:01:46 +07:00
|
|
|
|
2026-04-05 06:21:16 +07:00
|
|
|
// Editor: approve
|
|
|
|
|
Action::make('approve')
|
|
|
|
|
->label('Setujui')
|
2026-04-03 06:48:06 +07:00
|
|
|
->icon('heroicon-o-check-circle')
|
|
|
|
|
->color('success')
|
|
|
|
|
->requiresConfirmation()
|
2026-04-05 06:21:16 +07:00
|
|
|
->visible(fn ($record) => $canReview && $record->status === 'pending')
|
2026-04-03 07:57:40 +07:00
|
|
|
->action(fn ($record) => tap($record->update([
|
2026-04-05 06:21:16 +07:00
|
|
|
'status' => 'approved',
|
|
|
|
|
'approved_by' => auth()->id(),
|
|
|
|
|
'approved_at' => now(),
|
|
|
|
|
'reviewed_by' => auth()->id(),
|
2026-04-03 07:57:40 +07:00
|
|
|
]), fn () => NotificationService::send(
|
2026-04-05 06:21:16 +07:00
|
|
|
$record->author, 'Artikel Disetujui',
|
|
|
|
|
"Artikel \"{$record->title}\" Anda telah disetujui dan akan segera diterbitkan.", 'success',
|
2026-04-03 07:57:40 +07:00
|
|
|
route('filament.admin.resources.posts.edit', $record)
|
|
|
|
|
))),
|
2026-04-03 07:01:46 +07:00
|
|
|
|
2026-04-05 06:21:16 +07:00
|
|
|
// Editor: tolak
|
2026-04-03 06:48:06 +07:00
|
|
|
Action::make('reject')
|
|
|
|
|
->label('Tolak')
|
|
|
|
|
->icon('heroicon-o-x-circle')
|
|
|
|
|
->color('danger')
|
2026-04-05 06:21:16 +07:00
|
|
|
->visible(fn ($record) => $canReview && $record->status === 'pending')
|
|
|
|
|
->form([Textarea::make('rejection_reason')->label('Alasan Penolakan')->required()])
|
2026-04-03 07:57:40 +07:00
|
|
|
->action(fn ($record, array $data) => tap($record->update([
|
2026-04-05 06:21:16 +07:00
|
|
|
'status' => 'draft',
|
2026-04-03 06:48:06 +07:00
|
|
|
'reviewed_by' => auth()->id(),
|
|
|
|
|
'rejection_reason' => $data['rejection_reason'],
|
2026-04-03 07:57:40 +07:00
|
|
|
]), fn () => NotificationService::send(
|
|
|
|
|
$record->author, 'Artikel Ditolak',
|
|
|
|
|
"Artikel \"{$record->title}\" ditolak: {$data['rejection_reason']}", 'danger',
|
|
|
|
|
route('filament.admin.resources.posts.edit', $record)
|
|
|
|
|
))),
|
2026-04-03 07:01:46 +07:00
|
|
|
|
2026-04-05 06:21:16 +07:00
|
|
|
// Editor: publish (approved → published)
|
|
|
|
|
Action::make('publish')
|
|
|
|
|
->label('Terbitkan')
|
|
|
|
|
->icon('heroicon-o-globe-alt')
|
|
|
|
|
->color('success')
|
|
|
|
|
->visible(fn ($record) => $canPublish && $record->status === 'approved')
|
|
|
|
|
->form([
|
|
|
|
|
DateTimePicker::make('published_at')->label('Tanggal Publikasi')
|
|
|
|
|
->default(now())->required(),
|
|
|
|
|
])
|
|
|
|
|
->action(fn ($record, array $data) => $record->update([
|
|
|
|
|
'status' => 'published',
|
|
|
|
|
'published_at' => $data['published_at'],
|
|
|
|
|
])),
|
|
|
|
|
|
|
|
|
|
// Editor: unpublish
|
|
|
|
|
Action::make('unpublish')
|
|
|
|
|
->label('Batalkan Publikasi')
|
|
|
|
|
->icon('heroicon-o-eye-slash')
|
|
|
|
|
->color('warning')
|
|
|
|
|
->requiresConfirmation()
|
|
|
|
|
->visible(fn ($record) => $canPublish && $record->status === 'published')
|
|
|
|
|
->action(fn ($record) => $record->update([
|
|
|
|
|
'status' => 'approved',
|
|
|
|
|
'published_at' => null,
|
|
|
|
|
])),
|
|
|
|
|
|
2026-04-03 07:01:46 +07:00
|
|
|
EditAction::make()
|
2026-04-05 06:21:16 +07:00
|
|
|
->visible(fn ($record) => $canReview || in_array($record->status, ['draft', 'rejected'])),
|
2026-04-03 06:48:06 +07:00
|
|
|
])
|
2026-04-03 05:18:34 +07:00
|
|
|
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
|
|
|
|
}
|
|
|
|
|
}
|