2026-04-03 05:18:34 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\Posts\Tables;
|
|
|
|
|
|
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-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
|
|
|
|
|
{
|
|
|
|
|
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',
|
|
|
|
|
'pending' => 'warning',
|
|
|
|
|
'rejected' => 'danger',
|
|
|
|
|
default => 'gray',
|
|
|
|
|
}),
|
2026-04-03 05:18:34 +07:00
|
|
|
TextColumn::make('author.name')->label('Penulis'),
|
|
|
|
|
TextColumn::make('published_at')->label('Dipublikasi')
|
2026-04-03 06:48:06 +07:00
|
|
|
->dateTime('d M Y')->default('-')->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',
|
|
|
|
|
'published' => 'Diterbitkan',
|
|
|
|
|
'rejected' => 'Ditolak',
|
2026-04-03 05:18:34 +07:00
|
|
|
]),
|
|
|
|
|
])
|
2026-04-03 06:48:06 +07:00
|
|
|
->recordActions([
|
|
|
|
|
Action::make('publish')
|
|
|
|
|
->label('Terbitkan')
|
|
|
|
|
->icon('heroicon-o-check-circle')
|
|
|
|
|
->color('success')
|
|
|
|
|
->requiresConfirmation()
|
|
|
|
|
->visible(fn ($record) => $record->status === 'pending')
|
|
|
|
|
->action(fn ($record) => $record->update([
|
|
|
|
|
'status' => 'published',
|
|
|
|
|
'published_at' => now(),
|
|
|
|
|
'reviewed_by' => auth()->id(),
|
|
|
|
|
])),
|
|
|
|
|
Action::make('reject')
|
|
|
|
|
->label('Tolak')
|
|
|
|
|
->icon('heroicon-o-x-circle')
|
|
|
|
|
->color('danger')
|
|
|
|
|
->visible(fn ($record) => $record->status === 'pending')
|
|
|
|
|
->form([
|
|
|
|
|
Textarea::make('rejection_reason')->label('Alasan Penolakan')->required(),
|
|
|
|
|
])
|
|
|
|
|
->action(fn ($record, array $data) => $record->update([
|
|
|
|
|
'status' => 'rejected',
|
|
|
|
|
'reviewed_by' => auth()->id(),
|
|
|
|
|
'rejection_reason' => $data['rejection_reason'],
|
|
|
|
|
])),
|
|
|
|
|
EditAction::make(),
|
|
|
|
|
])
|
2026-04-03 05:18:34 +07:00
|
|
|
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
|
|
|
|
}
|
|
|
|
|
}
|