Skip to content

Commit 50b5c54

Browse files
committed
refactor vacations
1 parent f09c618 commit 50b5c54

5 files changed

Lines changed: 100 additions & 78 deletions

File tree

app/Concerns/HasConditionalTableEmptyState.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77
use Filament\Tables\Concerns\HasEmptyState;
88

9+
/**
10+
* @deprecated Override the `table()` method to configure the table.
11+
*/
912
trait HasConditionalTableEmptyState
1013
{
1114
use HasEmptyState;
1215

16+
/**
17+
* @deprecated Override the `table()` method to configure the table.
18+
*/
1319
public function hasAlteredTableQuery(): bool
1420
{
1521
return $this->getTableSearchQuery() || filled(request()->query('tableFilters'));

app/Filament/Resources/VacationResource.php

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
namespace App\Filament\Resources;
66

7-
use App\Enums\VacationType;
87
use App\Filament\Resources\VacationResource\Pages;
9-
use App\Forms\Components\Value;
8+
use App\Filament\Resources\VacationResource\Schemas\VacationForm;
9+
use App\Filament\Resources\VacationResource\Schemas\VacationInfolist;
1010
use App\Models\County;
1111
use App\Models\Vacation;
1212
use App\Tables\Columns\TextColumn;
13-
use Filament\Forms\Components\DatePicker;
14-
use Filament\Forms\Components\Grid;
15-
use Filament\Forms\Components\Select;
16-
use Filament\Forms\Components\Textarea;
1713
use Filament\Forms\Form;
14+
use Filament\Infolists\Infolist;
1815
use Filament\Resources\Resource;
1916
use Filament\Tables;
2017
use Filament\Tables\Filters\SelectFilter;
@@ -49,7 +46,13 @@ public static function getPluralModelLabel(): string
4946
public static function form(Form $form): Form
5047
{
5148
return $form
52-
->schema(static::getEditFormSchema());
49+
->schema(VacationForm::getSchema());
50+
}
51+
52+
public static function infolist(Infolist $infolist): Infolist
53+
{
54+
return $infolist
55+
->schema(VacationInfolist::getSchema());
5356
}
5457

5558
public static function table(Table $table): Table
@@ -126,89 +129,21 @@ public static function table(Table $table): Table
126129
])
127130
->actions([
128131
Tables\Actions\ViewAction::make()
129-
->form(static::getViewFormSchema())
130132
->iconButton(),
131133

132134
Tables\Actions\EditAction::make()
133-
->form(static::getEditFormSchema())
134135
->iconButton(),
135136

136137
Tables\Actions\DeleteAction::make()
137138
->iconButton(),
138139
])
139-
->bulkActions([
140-
//
141-
])
142140
->defaultSort('id', 'desc');
143141
}
144142

145-
public static function getRelations(): array
146-
{
147-
return [
148-
//
149-
];
150-
}
151-
152143
public static function getPages(): array
153144
{
154145
return [
155146
'index' => Pages\ManageVacations::route('/'),
156147
];
157148
}
158-
159-
public static function getEditFormSchema(): array
160-
{
161-
return [
162-
Select::make('type')
163-
->label(__('field.type'))
164-
->options(VacationType::options())
165-
->enum(VacationType::class)
166-
->required(),
167-
168-
Grid::make()
169-
->schema([
170-
DatePicker::make('start_date')
171-
->label(__('field.start_date'))
172-
->required(),
173-
174-
DatePicker::make('end_date')
175-
->label(__('field.end_date'))
176-
->afterOrEqual('start_date')
177-
->required(),
178-
])
179-
->columnSpanFull(),
180-
181-
Textarea::make('notes')
182-
->label(__('field.notes'))
183-
->autosize(false)
184-
->rows(4)
185-
->columnSpanFull()
186-
->extraInputAttributes([
187-
'class' => 'resize-none',
188-
])
189-
->columnSpanFull(),
190-
];
191-
}
192-
193-
public static function getViewFormSchema(): array
194-
{
195-
return [
196-
Value::make('type')
197-
->label(__('field.type')),
198-
199-
Grid::make()
200-
->schema([
201-
Value::make('start_date')
202-
->label(__('field.start_date')),
203-
204-
Value::make('end_date')
205-
->label(__('field.end_date')),
206-
])
207-
->columnSpanFull(),
208-
209-
Value::make('notes')
210-
->label(__('field.notes'))
211-
->columnSpanFull(),
212-
];
213-
}
214149
}

app/Filament/Resources/VacationResource/Pages/ManageVacations.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use App\Concerns\HasConditionalTableEmptyState;
88
use App\Filament\Resources\VacationResource;
99
use App\Models\Vacation;
10-
use Filament\Pages;
10+
use Filament\Actions\CreateAction;
1111
use Filament\Resources\Pages\ManageRecords;
1212
use Filament\Tables;
1313

@@ -20,7 +20,7 @@ class ManageVacations extends ManageRecords
2020
protected function getHeaderActions(): array
2121
{
2222
return [
23-
Pages\Actions\CreateAction::make()
23+
CreateAction::make()
2424
->using(function (array $data) {
2525
$data['nurse_id'] = auth()->id();
2626

@@ -60,7 +60,6 @@ protected function getTableEmptyStateActions(): array
6060
{
6161
return [
6262
Tables\Actions\CreateAction::make()
63-
->form(VacationResource::getEditFormSchema())
6463
->using(function (array $data) {
6564
$data['nurse_id'] = auth()->id();
6665

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\VacationResource\Schemas;
6+
7+
use App\Enums\VacationType;
8+
use App\Forms\Components\Select;
9+
use Filament\Forms\Components\DatePicker;
10+
use Filament\Forms\Components\Grid;
11+
use Filament\Forms\Components\Textarea;
12+
13+
class VacationForm
14+
{
15+
public static function getSchema(): array
16+
{
17+
return [
18+
Select::make('type')
19+
->label(__('field.type'))
20+
->options(VacationType::options())
21+
->enum(VacationType::class)
22+
->required(),
23+
24+
Grid::make()
25+
->columnSpanFull()
26+
->schema([
27+
DatePicker::make('start_date')
28+
->label(__('field.start_date'))
29+
->required(),
30+
31+
DatePicker::make('end_date')
32+
->label(__('field.end_date'))
33+
->afterOrEqual('start_date')
34+
->required(),
35+
]),
36+
37+
Textarea::make('notes')
38+
->label(__('field.notes'))
39+
->columnSpanFull()
40+
->autosize(false)
41+
->rows(4)
42+
->extraInputAttributes([
43+
'class' => 'resize-none',
44+
]),
45+
];
46+
}
47+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\VacationResource\Schemas;
6+
7+
use Filament\Infolists\Components\Grid;
8+
use Filament\Infolists\Components\TextEntry;
9+
10+
class VacationInfolist
11+
{
12+
public static function getSchema(): array
13+
{
14+
return [
15+
TextEntry::make('type')
16+
->label(__('field.type')),
17+
18+
Grid::make()
19+
->columnSpanFull()
20+
->schema([
21+
TextEntry::make('start_date')
22+
->label(__('field.start_date'))
23+
->date(),
24+
25+
TextEntry::make('end_date')
26+
->label(__('field.end_date'))
27+
->date(),
28+
]),
29+
30+
TextEntry::make('notes')
31+
->label(__('field.notes'))
32+
->columnSpanFull(),
33+
];
34+
}
35+
}

0 commit comments

Comments
 (0)