|
4 | 4 |
|
5 | 5 | namespace App\Filament\Resources\ProfileResource\Pages; |
6 | 6 |
|
7 | | -use App\Enums\Employer\Funding; |
8 | | -use App\Enums\Employer\Type; |
9 | | -use App\Forms\Components\Location; |
10 | | -use App\Forms\Components\Repeater; |
11 | | -use App\Forms\Components\Subsection; |
12 | | -use Filament\Forms\Components\Checkbox; |
13 | | -use Filament\Forms\Components\DatePicker; |
14 | | -use Filament\Forms\Components\Group; |
15 | | -use Filament\Forms\Components\Section; |
16 | | -use Filament\Forms\Components\Select; |
17 | | -use Filament\Forms\Components\TextInput; |
| 7 | +use App\Filament\Resources\ProfileResource\Schemas\EmployersForm; |
18 | 8 | use Filament\Forms\Form; |
19 | 9 |
|
20 | 10 | class EditEmployers extends EditRecord |
21 | 11 | { |
22 | 12 | public function form(Form $form): Form |
23 | 13 | { |
24 | 14 | return $form |
25 | | - ->columns(1) |
26 | | - ->schema(static::getSchema()); |
27 | | - } |
28 | | - |
29 | | - public static function getSchema(): array |
30 | | - { |
31 | | - return [ |
32 | | - Repeater::make('employers') |
33 | | - ->relationship('employers') |
34 | | - ->label(__('employer.label.plural')) |
35 | | - ->createItemButtonLabel(__('employer.action.create')) |
36 | | - ->minItems(1) |
37 | | - ->schema([ |
38 | | - Subsection::make() |
39 | | - ->icon('heroicon-o-building-office') |
40 | | - ->columns(2) |
41 | | - ->schema([ |
42 | | - TextInput::make('name') |
43 | | - ->label(__('field.employer_name')) |
44 | | - ->placeholder(__('placeholder.employer_name')) |
45 | | - ->maxLength(200) |
46 | | - ->required(), |
47 | | - |
48 | | - Select::make('type') |
49 | | - ->label(__('field.employer_type')) |
50 | | - ->placeholder(__('placeholder.choose')) |
51 | | - ->options(Type::options()) |
52 | | - ->enum(Type::class) |
53 | | - ->required(), |
54 | | - |
55 | | - Select::make('funding') |
56 | | - ->label(__('field.funding')) |
57 | | - ->placeholder(__('placeholder.choose')) |
58 | | - ->options(Funding::options()) |
59 | | - ->enum(Funding::class), |
60 | | - |
61 | | - Group::make() |
62 | | - ->extraAttributes(['class' => 'flex h-full justify-end items-center']) |
63 | | - ->schema([ |
64 | | - Checkbox::make('is_project_based') |
65 | | - ->label(__('field.employer_project_based')) |
66 | | - ->live() |
67 | | - ->afterStateUpdated(function (callable $set) { |
68 | | - $set('project', null); |
69 | | - }), |
70 | | - ]), |
71 | | - |
72 | | - Section::make() |
73 | | - ->columnSpanFull() |
74 | | - ->pointer('right') |
75 | | - ->hidden(fn (callable $get) => $get('is_project_based') === false) |
76 | | - ->schema([ |
77 | | - TextInput::make('project') |
78 | | - ->label(__('field.employer_project')) |
79 | | - ->placeholder(__('placeholder.employer_project')) |
80 | | - ->live() |
81 | | - ->maxLength(200) |
82 | | - ->afterStateHydrated(function (callable $set, $state) { |
83 | | - $set('is_project_based', $state !== null); |
84 | | - }), |
85 | | - ]), |
86 | | - |
87 | | - Location::make(), |
88 | | - |
89 | | - TextInput::make('email') |
90 | | - ->label(__('field.employer_email')) |
91 | | - ->placeholder(__('placeholder.email')) |
92 | | - ->maxLength(200) |
93 | | - ->email(), |
94 | | - |
95 | | - TextInput::make('phone') |
96 | | - ->label(__('field.employer_phone')) |
97 | | - ->placeholder(__('placeholder.phone')) |
98 | | - ->tel() |
99 | | - ->maxLength(15), |
100 | | - |
101 | | - DatePicker::make('start_date') |
102 | | - ->label(__('field.start_date')) |
103 | | - ->placeholder(__('placeholder.date')), |
104 | | - |
105 | | - Group::make() |
106 | | - ->schema([ |
107 | | - DatePicker::make('end_date') |
108 | | - ->label(__('field.end_date')) |
109 | | - ->placeholder(__('placeholder.date')) |
110 | | - ->afterOrEqual('start_date') |
111 | | - ->disabled(function (callable $get) { |
112 | | - return $get('is_ongoing') === true; |
113 | | - }) |
114 | | - ->afterStateHydrated(function (callable $set, $state) { |
115 | | - $set('is_ongoing', $state === null); |
116 | | - }), |
117 | | - |
118 | | - Group::make() |
119 | | - ->extraAttributes(['class' => 'flex justify-end']) |
120 | | - ->columnSpanFull() |
121 | | - ->schema([ |
122 | | - Checkbox::make('is_ongoing') |
123 | | - ->label(__('field.employer_ongoing')) |
124 | | - ->live() |
125 | | - ->afterStateUpdated(function (callable $set) { |
126 | | - $set('end_date', null); |
127 | | - }), |
128 | | - ]), |
129 | | - ]), |
130 | | - |
131 | | - Checkbox::make('has_gp_agreement') |
132 | | - ->label(__('field.has_gp_agreement')) |
133 | | - ->live() |
134 | | - ->afterStateUpdated(function (callable $set) { |
135 | | - $set('end_date', null); |
136 | | - }), |
137 | | - |
138 | | - Section::make() |
139 | | - ->columnSpanFull() |
140 | | - ->hidden(fn (callable $get) => $get('has_gp_agreement') === false) |
141 | | - ->columns() |
142 | | - ->pointer() |
143 | | - ->schema([ |
144 | | - TextInput::make('gp_name') |
145 | | - ->label(__('field.gp_name')) |
146 | | - ->placeholder(__('placeholder.gp_name')) |
147 | | - ->maxLength(200) |
148 | | - ->columnSpanFull(), |
149 | | - |
150 | | - TextInput::make('gp_email') |
151 | | - ->label(__('field.gp_email')) |
152 | | - ->placeholder(__('placeholder.email')) |
153 | | - ->maxLength(200) |
154 | | - ->email(), |
155 | | - |
156 | | - TextInput::make('gp_phone') |
157 | | - ->label(__('field.gp_phone')) |
158 | | - ->placeholder(__('placeholder.phone')) |
159 | | - ->tel() |
160 | | - ->maxLength(15), |
161 | | - ]), |
162 | | - ]), |
163 | | - ]), |
164 | | - ]; |
| 15 | + ->schema(EmployersForm::getSchema()); |
165 | 16 | } |
166 | 17 | } |
0 commit comments