Skip to content

Commit 463861f

Browse files
wip
1 parent eacd01a commit 463861f

File tree

5 files changed

+310
-490
lines changed

5 files changed

+310
-490
lines changed

app/Filament/Admin/Schemas/InstitutionResourceSchema.php

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@
44

55
namespace App\Filament\Admin\Schemas;
66

7+
use App\Enums\AreaType;
8+
use App\Enums\OrganizationType;
9+
use App\Forms\Components\Repeater;
10+
use App\Forms\Components\Select;
11+
use App\Models\City;
12+
use App\Models\County;
713
use App\Models\Institution;
814
use Filament\Actions\ViewAction;
15+
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
16+
use Filament\Forms\Components\TextInput;
17+
use Filament\Schemas\Components\Grid;
18+
use Filament\Schemas\Components\Section;
19+
use Filament\Schemas\Components\Utilities\Get;
20+
use Filament\Schemas\Components\Utilities\Set;
921
use Filament\Schemas\Schema;
1022
use Filament\Tables\Columns\TextColumn;
1123
use Filament\Tables\Table;
@@ -40,106 +52,138 @@ public static function table(Table $table): Table
4052
public static function getFormSchemaForDetails(): array
4153
{
4254
return [
43-
\Filament\Schemas\Components\Section::make()
55+
Section::make()
4456
->maxWidth('3xl')
4557
->columns()
4658
->schema([
47-
\Filament\Forms\Components\TextInput::make('name')
59+
TextInput::make('name')
4860
->label(__('organization.field.name'))
4961
->placeholder(__('organization.placeholders.name'))
5062
->maxLength(200)
5163
->required(),
5264

53-
\Filament\Forms\Components\TextInput::make('short_name')
65+
TextInput::make('short_name')
5466
->label(__('organization.field.short_name'))
5567
->placeholder(__('organization.placeholders.short_name'))
5668
->maxLength(50),
5769

58-
\App\Forms\Components\Select::make('type')
70+
Select::make('type')
5971
->label(__('organization.field.type'))
6072
->placeholder(__('organization.placeholders.type'))
61-
->options(\App\Enums\OrganizationType::options())
62-
->enum(\App\Enums\OrganizationType::class)
73+
->options(OrganizationType::options())
74+
->enum(OrganizationType::class)
6375
->required(),
6476

65-
\Filament\Forms\Components\TextInput::make('cif')
77+
TextInput::make('cif')
6678
->label(__('organization.field.cif'))
6779
->placeholder(__('organization.placeholders.cif'))
6880
->required(),
6981

70-
\Filament\Forms\Components\TextInput::make('main_activity')
82+
TextInput::make('main_activity')
7183
->label(__('organization.field.main_activity'))
7284
->placeholder(__('organization.placeholders.main_activity'))
7385
->maxLength(200)
7486
->required(),
7587

76-
\App\Forms\Components\Select::make('area')
88+
Select::make('area')
7789
->label(__('organization.field.area'))
7890
->placeholder(__('organization.placeholders.area'))
79-
->options(\App\Enums\AreaType::options())
91+
->options(AreaType::options())
8092
->required(),
8193

82-
\App\Forms\Components\Location::make()
83-
->city()
84-
->address()
85-
->countyLabel(__('organization.field.county'))
86-
->cityLabel(__('organization.field.city'))
87-
->addressLabel(__('organization.field.address'))
88-
->addressMaxLength(200)
89-
->addressColumnSpanFull()
94+
Select::make('county_id')
95+
->label(__('organization.field.county'))
96+
->placeholder(__('organization.placeholders.county'))
97+
->searchable()
98+
->getSearchResultsUsing(fn (string $search): array => County::query()
99+
->where('name', 'like', "%{$search}%")
100+
->limit(50)
101+
->get()
102+
->pluck('name', 'id')
103+
->toArray())
104+
->required()
105+
->live()
106+
->afterStateUpdated(fn (Set $set) => $set('city_id', null)),
107+
108+
Select::make('city_id')
109+
->label(__('organization.field.city'))
110+
->placeholder(__('placeholder.city'))
111+
->searchable()
112+
->required()
113+
->disabled(fn (Get $get) => ! $get('county_id'))
114+
->getSearchResultsUsing(function (string $search, Get $get): array {
115+
if (! $get('county_id')) {
116+
return [];
117+
}
118+
119+
return City::query()
120+
->where('county_id', (int) $get('county_id'))
121+
->where('name', 'like', "%{$search}%")
122+
->limit(50)
123+
->get()
124+
->pluck('name_with_uat', 'id')
125+
->toArray();
126+
})
127+
->live(),
128+
129+
TextInput::make('address')
130+
->label(__('organization.field.address'))
131+
->placeholder(__('placeholder.address'))
132+
->maxLength(200)
133+
->columnSpanFull()
90134
->required(),
91135

92-
\Filament\Schemas\Components\Grid::make()
136+
Grid::make()
93137
->schema([
94-
\Filament\Forms\Components\TextInput::make('representative_person.name')
138+
TextInput::make('representative_person.name')
95139
->label(__('organization.field.representative_name'))
96140
->placeholder(__('organization.placeholders.representative_name'))
97141
->maxLength(50)
98142
->required(),
99143

100-
\Filament\Forms\Components\TextInput::make('representative_person.email')
144+
TextInput::make('representative_person.email')
101145
->label(__('organization.field.representative_email'))
102146
->placeholder(__('organization.placeholders.representative_email'))
103147
->maxLength(50)
104148
->email(),
105149

106-
\Filament\Forms\Components\TextInput::make('representative_person.phone')
150+
TextInput::make('representative_person.phone')
107151
->label(__('organization.field.representative_phone'))
108152
->placeholder(__('organization.placeholders.representative_phone'))
109153
->maxLength(13)
110154
->tel(),
111155
])->columnSpanFull(),
112156

113-
\Filament\Schemas\Components\Grid::make()
157+
Grid::make()
114158
->schema([
115-
\Filament\Forms\Components\TextInput::make('contact_person.name')
159+
TextInput::make('contact_person.name')
116160
->label(__('organization.field.contact_person'))
117161
->placeholder(__('organization.placeholders.contact_person'))
118162
->maxLength(50)
119163
->required(),
120164

121-
\Filament\Forms\Components\TextInput::make('contact_person.email')
165+
TextInput::make('contact_person.email')
122166
->label(__('organization.field.contact_person_email'))
123167
->placeholder(__('organization.placeholders.contact_person_email'))
124168
->maxLength(50)
125169
->required()
126170
->email(),
127171

128-
\Filament\Forms\Components\TextInput::make('contact_person.phone')
172+
TextInput::make('contact_person.phone')
129173
->label(__('organization.field.contact_person_phone'))
130174
->placeholder(__('organization.placeholders.contact_person_phone'))
131175
->maxLength(13)
132176
->tel()
133177
->required(),
134178
])->columnSpanFull(),
135179

136-
\Filament\Forms\Components\TextInput::make('website')
180+
TextInput::make('website')
137181
->label(__('organization.field.website'))
138182
->placeholder(__('organization.placeholders.website'))
139183
->maxLength(200)
140184
->url(),
141185

142-
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('organization_status')
186+
SpatieMediaLibraryFileUpload::make('organization_status')
143187
->label(__('institution.labels.organization_status'))
144188
->maxSize(config('media-library.max_file_size'))
145189
->helperText(__('institution.helper_texts.organization_status'))
@@ -153,7 +197,7 @@ public static function getFormSchemaForDetails(): array
153197
->columnSpanFull()
154198
->required(),
155199

156-
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('social_service_provider_certificate')
200+
SpatieMediaLibraryFileUpload::make('social_service_provider_certificate')
157201
->label(__('institution.labels.social_service_provider_certificate'))
158202
->maxSize(config('media-library.max_file_size'))
159203
->helperText(__('institution.helper_texts.social_service_provider_certificate'))
@@ -172,33 +216,33 @@ public static function getFormSchemaForDetails(): array
172216
public static function getFormSchemaForCenters(): array
173217
{
174218
return [
175-
\App\Forms\Components\Repeater::make('organizations')
219+
Repeater::make('organizations')
176220
->maxWidth('3xl')
177221
->hiddenLabel()
178222
->columns()
179223
->minItems(1)
180224
->relationship('organizations')
181225
->addActionLabel(__('institution.actions.add_organization'))
182226
->schema([
183-
\Filament\Forms\Components\TextInput::make('name')
227+
TextInput::make('name')
184228
->label(__('institution.labels.center_name'))
185229
->placeholder(__('organization.placeholders.center_name'))
186230
->maxLength(200)
187231
->required(),
188232

189-
\Filament\Forms\Components\TextInput::make('short_name')
233+
TextInput::make('short_name')
190234
->label(__('organization.field.short_name'))
191235
->placeholder(__('organization.placeholders.center_short_name'))
192236
->maxLength(50),
193237

194-
\Filament\Forms\Components\TextInput::make('main_activity')
238+
TextInput::make('main_activity')
195239
->label(__('organization.field.main_activity'))
196240
->placeholder(__('organization.placeholders.main_activity'))
197241
->columnSpanFull()
198242
->maxLength(200)
199243
->required(),
200244

201-
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('social_service_licensing_certificate')
245+
SpatieMediaLibraryFileUpload::make('social_service_licensing_certificate')
202246
->label(__('institution.labels.social_service_licensing_certificate'))
203247
->helperText(__('institution.helper_texts.social_service_licensing_certificate'))
204248
->maxSize(config('media-library.max_file_size'))
@@ -211,7 +255,7 @@ public static function getFormSchemaForCenters(): array
211255
])
212256
->columnSpanFull(),
213257

214-
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('logo')
258+
SpatieMediaLibraryFileUpload::make('logo')
215259
->label(__('institution.labels.logo_center'))
216260
->helperText(__('institution.helper_texts.logo'))
217261
->maxSize(config('media-library.max_file_size'))
@@ -223,7 +267,7 @@ public static function getFormSchemaForCenters(): array
223267
])
224268
->columnSpanFull(),
225269

226-
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('organization_header')
270+
SpatieMediaLibraryFileUpload::make('organization_header')
227271
->label(__('institution.labels.organization_header'))
228272
->helperText(__('institution.helper_texts.organization_header'))
229273
->maxSize(config('media-library.max_file_size'))

0 commit comments

Comments
 (0)