refactor: reimplement course schedule edit and delete actions using Filament action objects directly in the view with enhanced UI.

This commit is contained in:
Yoga Pangestu 2026-03-12 10:08:20 +07:00
parent bcdbbacf5c
commit f6681cc5aa
4 changed files with 25 additions and 17 deletions

View File

@ -4,6 +4,7 @@
use App\Filament\Actions\Cheerful\DeleteAction;
use App\Models\CourseSchedule;
use Filament\Support\Icons\Heroicon;
class DeleteScheduleAction extends DeleteAction
{
@ -19,6 +20,11 @@ protected function setUp(): void
$this->record(function (array $arguments): CourseSchedule {
return CourseSchedule::findOrFail($arguments['schedule']);
})
->label('Hapus')
->icon(Heroicon::OutlinedTrash)
->color('danger')
->iconButton()
->tooltip('Hapus')
->modalHeading('Hapus Jadwal Kuliah')
->modalDescription('Apakah Anda yakin ingin menghapus jadwal ini? Tindakan ini tidak dapat dibatalkan.')
->modalSubmitActionLabel('Hapus')

View File

@ -5,6 +5,7 @@
use App\Filament\Actions\Cheerful\EditAction;
use App\Models\CourseSchedule;
use Filament\Support\Enums\Width;
use Filament\Support\Icons\Heroicon;
class EditScheduleAction extends EditAction
{
@ -17,9 +18,15 @@ protected function setUp(): void
{
parent::setUp();
$this->record(function (array $arguments): CourseSchedule {
return CourseSchedule::findOrFail($arguments['schedule']);
})
$this
->label('Ubah')
->icon(Heroicon::OutlinedPencilSquare)
->color('warning')
->iconButton()
->tooltip('Ubah')
->record(function (array $arguments): CourseSchedule {
return CourseSchedule::findOrFail($arguments['schedule']);
})
->modalHeading('Ubah Jadwal Kuliah')
->modalSubmitActionLabel('Simpan')
->modalCancelActionLabel('Batal')

View File

@ -81,13 +81,13 @@ protected function getHeaderActions(): array
];
}
protected function editScheduleAction(): Action
public function editScheduleAction(): Action
{
return EditScheduleAction::make()
->visible(fn () => auth()->user()->can('Update:CourseSchedule'));
}
protected function deleteScheduleAction(): Action
public function deleteScheduleAction(): Action
{
return DeleteScheduleAction::make()
->visible(fn () => auth()->user()->can('Delete:CourseSchedule'));

View File

@ -106,19 +106,14 @@ class="text-[11px] font-semibold tracking-wide text-gray-400 uppercase">
</span>
</div>
<div
class="flex items-center justify-end gap-1 pt-3 border-t border-gray-100 dark:border-gray-800">
<x-filament::button size="xs" color="warning" tooltip="Ubah"
variant="primary"
wire:click="mountAction('editSchedule', { schedule: {{ $schedule->id }} })">
<x-heroicon-m-pencil-square class="w-4 h-4" />
</x-filament::button>
@canAny(['Update:CourseSchedule', 'Delete:CourseSchedule'])
<div
class="flex items-center justify-end gap-1 pt-3 border-t border-gray-100 dark:border-gray-800">
{{ ($this->editScheduleAction)(['schedule' => $schedule->id]) }}
<x-filament::button size="xs" color="danger" tooltip="Hapus"
wire:click="mountAction('deleteSchedule', { schedule: {{ $schedule->id }} })">
<x-heroicon-m-trash class="w-4 h-4" />
</x-filament::button>
</div>
{{ ($this->deleteScheduleAction)(['schedule' => $schedule->id]) }}
</div>
@endcanAny
</div>
</div>
@endforeach