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
|
|
|
|
|
{
|
2026-04-03 07:01:46 +07:00
|
|
|
$isAdmin = auth()->user()?->hasAnyRole(['super_admin', 'ketua']);
|
|
|
|
|
|
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',
|
|
|
|
|
'pending' => 'warning',
|
|
|
|
|
'rejected' => 'danger',
|
|
|
|
|
default => 'gray',
|
|
|
|
|
}),
|
2026-04-03 07:01:46 +07:00
|
|
|
TextColumn::make('author.name')->label('Penulis')->visible($isAdmin),
|
|
|
|
|
TextColumn::make('rejection_reason')->label('Alasan Penolakan')
|
|
|
|
|
->limit(40)->default('-')
|
|
|
|
|
->visible(fn ($record) => $record?->status === 'rejected'),
|
2026-04-03 05:18:34 +07:00
|
|
|
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([
|
2026-04-03 07:01:46 +07:00
|
|
|
// Untuk anggota/pengurus/bendahara: ajukan artikel
|
|
|
|
|
Action::make('submit')
|
|
|
|
|
->label('Ajukan')
|
|
|
|
|
->icon('heroicon-o-paper-airplane')
|
|
|
|
|
->color('info')
|
|
|
|
|
->requiresConfirmation()
|
|
|
|
|
->visible(fn ($record) => ! $isAdmin && in_array($record->status, ['draft', 'rejected']))
|
|
|
|
|
->action(fn ($record) => $record->update(['status' => 'pending', 'rejection_reason' => null])),
|
|
|
|
|
|
|
|
|
|
// Untuk admin: approve
|
2026-04-03 06:48:06 +07:00
|
|
|
Action::make('publish')
|
|
|
|
|
->label('Terbitkan')
|
|
|
|
|
->icon('heroicon-o-check-circle')
|
|
|
|
|
->color('success')
|
|
|
|
|
->requiresConfirmation()
|
2026-04-03 07:01:46 +07:00
|
|
|
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
2026-04-03 06:48:06 +07:00
|
|
|
->action(fn ($record) => $record->update([
|
2026-04-03 07:01:46 +07:00
|
|
|
'status' => 'published',
|
2026-04-03 06:48:06 +07:00
|
|
|
'published_at' => now(),
|
2026-04-03 07:01:46 +07:00
|
|
|
'reviewed_by' => auth()->id(),
|
2026-04-03 06:48:06 +07:00
|
|
|
])),
|
2026-04-03 07:01:46 +07:00
|
|
|
|
|
|
|
|
// Untuk admin: tolak
|
2026-04-03 06:48:06 +07:00
|
|
|
Action::make('reject')
|
|
|
|
|
->label('Tolak')
|
|
|
|
|
->icon('heroicon-o-x-circle')
|
|
|
|
|
->color('danger')
|
2026-04-03 07:01:46 +07:00
|
|
|
->visible(fn ($record) => $isAdmin && $record->status === 'pending')
|
2026-04-03 06:48:06 +07:00
|
|
|
->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'],
|
|
|
|
|
])),
|
2026-04-03 07:01:46 +07:00
|
|
|
|
|
|
|
|
EditAction::make()
|
|
|
|
|
->visible(fn ($record) => $isAdmin || 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()])]);
|
|
|
|
|
}
|
|
|
|
|
}
|