refactor: update class session form to use Filament Schema builder pattern
This commit is contained in:
parent
16bcba3ef3
commit
2a8412ff60
@ -22,7 +22,9 @@ protected function setUp(): void
|
|||||||
->icon('heroicon-o-pencil')
|
->icon('heroicon-o-pencil')
|
||||||
->link()
|
->link()
|
||||||
->record(fn (array $arguments) => ClassSession::find($arguments['session'], ['*']))
|
->record(fn (array $arguments) => ClassSession::find($arguments['session'], ['*']))
|
||||||
->schema(fn ($livewire) => $livewire->schema())
|
->schema(function ($schema, $livewire) {
|
||||||
|
return $livewire->form($schema);
|
||||||
|
})
|
||||||
->modalWidth(Width::TwoExtraLarge);
|
->modalWidth(Width::TwoExtraLarge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
use Filament\Forms\Contracts\HasForms;
|
use Filament\Forms\Contracts\HasForms;
|
||||||
use Filament\Resources\Pages\Page;
|
use Filament\Resources\Pages\Page;
|
||||||
use Filament\Schemas\Components\Grid;
|
use Filament\Schemas\Components\Grid;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
use Filament\Support\Enums\Width;
|
use Filament\Support\Enums\Width;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
@ -74,45 +75,46 @@ public function sessions(): Collection
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function form(): array
|
public function form(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return [
|
return $schema
|
||||||
Grid::make(['default' => 2])
|
->schema([
|
||||||
->schema([
|
Grid::make(['default' => 2])
|
||||||
TextInput::make('session_number')
|
->schema([
|
||||||
->label('Pertemuan Ke-')
|
TextInput::make('session_number')
|
||||||
->placeholder('1')
|
->label('Pertemuan Ke-')
|
||||||
->numeric()
|
->placeholder('1')
|
||||||
->required()
|
->numeric()
|
||||||
->minValue(1)
|
->required()
|
||||||
->maxValue(16)
|
->minValue(1)
|
||||||
->autocomplete(false),
|
->maxValue(16)
|
||||||
|
->autocomplete(false),
|
||||||
|
|
||||||
DatePicker::make('date')
|
DatePicker::make('date')
|
||||||
->label('Tanggal')
|
->label('Tanggal')
|
||||||
->placeholder('Pilih Tanggal')
|
->placeholder('Pilih Tanggal')
|
||||||
->required()
|
->required()
|
||||||
->native(false)
|
->native(false)
|
||||||
->displayFormat('l, d F Y')
|
->displayFormat('l, d F Y')
|
||||||
->default(now()->toDateString()),
|
->default(now()->toDateString()),
|
||||||
|
|
||||||
TimePicker::make('start_time')
|
TimePicker::make('start_time')
|
||||||
->label('Waktu Mulai')
|
->label('Waktu Mulai')
|
||||||
->placeholder('08:00')
|
->placeholder('08:00')
|
||||||
->native(false)
|
->native(false)
|
||||||
->displayFormat('H:i')
|
->displayFormat('H:i')
|
||||||
->seconds(false)
|
->seconds(false)
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
TimePicker::make('end_time')
|
TimePicker::make('end_time')
|
||||||
->label('Waktu Selesai')
|
->label('Waktu Selesai')
|
||||||
->placeholder('10:00')
|
->placeholder('10:00')
|
||||||
->native(false)
|
->native(false)
|
||||||
->displayFormat('H:i')
|
->displayFormat('H:i')
|
||||||
->seconds(false)
|
->seconds(false)
|
||||||
->required(),
|
->required(),
|
||||||
]),
|
]),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
@ -139,7 +141,7 @@ protected function getHeaderActions(): array
|
|||||||
->modalHeading('Tambah Sesi')
|
->modalHeading('Tambah Sesi')
|
||||||
->modalSubmitActionLabel('Simpan')
|
->modalSubmitActionLabel('Simpan')
|
||||||
->modalCancelActionLabel('Batal')
|
->modalCancelActionLabel('Batal')
|
||||||
->schema($this->form())
|
->schema(fn (Schema $schema) => $this->form($schema))
|
||||||
->mutateDataUsing(function (array $data): array {
|
->mutateDataUsing(function (array $data): array {
|
||||||
$data['course_id'] = $this->courseId;
|
$data['course_id'] = $this->courseId;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user