Skip to content

Commit b36ef26

Browse files
wip
1 parent a5f8163 commit b36ef26

28 files changed

+1069
-357
lines changed

app/Concerns/BelongsToOrganization.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
use Filament\Facades\Filament;
1010
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1111

12+
/**
13+
* Ensures the model is scoped by tenant (centru) and organization.
14+
* In this app tenant = Organization (centru); all queries are limited to the current tenant.
15+
*/
1216
trait BelongsToOrganization
1317
{
1418
public function initializeBelongsToOrganization(): void

app/Filament/Admin/Resources/Institutions/Pages/CreateInstitution.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use App\Filament\Admin\Resources\Institutions\Schemas\InstitutionFormSchema;
99
use App\Models\User;
1010
use Filament\Forms\Components\Hidden;
11-
use Filament\Forms\Components\Placeholder;
1211
use Filament\Forms\Components\Repeater;
1312
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
1413
use Filament\Forms\Components\TextInput;
14+
use Filament\Infolists\Components\TextEntry;
1515
use Filament\Resources\Pages\CreateRecord;
1616
use Filament\Resources\Pages\CreateRecord\Concerns\HasWizard;
1717
use Filament\Schemas\Components\Section;
@@ -42,16 +42,16 @@ protected function getSteps(): array
4242
->schema($this->getInstitutionDetailsSchema()),
4343
Step::make(__('institution.headings.center_details'))
4444
->schema([
45-
Placeholder::make('center_details')
45+
TextEntry::make('center_details')
4646
->hiddenLabel()
47-
->content(__('institution.placeholders.center_details')),
47+
->state(__('institution.placeholders.center_details')),
4848
...$this->getCentersSchema(),
4949
]),
5050
Step::make(__('institution.headings.ngo_admin'))
5151
->schema([
52-
Placeholder::make('ngo_admins')
52+
TextEntry::make('ngo_admins')
5353
->hiddenLabel()
54-
->content(__('institution.placeholders.ngo_admins')),
54+
->state(__('institution.placeholders.ngo_admins')),
5555
...$this->getAdminsSchema(),
5656
]),
5757
];

app/Filament/Admin/Resources/Institutions/Schemas/InstitutionForm.php

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
use App\Enums\AreaType;
88
use App\Enums\OrganizationType;
9-
use App\Models\City;
9+
use App\Forms\Components\CountyCitySelect;
1010
use Filament\Forms\Components\Select;
1111
use Filament\Forms\Components\TextInput;
1212
use Filament\Schemas\Components\Grid;
1313
use Filament\Schemas\Components\Section;
14-
use Filament\Schemas\Components\Utilities\Get;
15-
use Filament\Schemas\Components\Utilities\Set;
1614
use Filament\Schemas\Schema;
1715

1816
class InstitutionForm
@@ -61,35 +59,14 @@ public static function configure(Schema $schema): Schema
6159
->enum(AreaType::class)
6260
->required(),
6361

64-
Select::make('county_id')
65-
->label(__('organization.field.county'))
66-
->placeholder(__('organization.placeholders.county'))
67-
->relationship('county', 'name')
68-
->searchable()
69-
->preload()
62+
...CountyCitySelect::make()
63+
->countyLabel(__('organization.field.county'))
64+
->cityLabel(__('organization.field.city'))
65+
->countyPlaceholder(__('organization.placeholders.county'))
66+
->cityPlaceholder(__('placeholder.city'))
7067
->required()
71-
->live()
72-
->afterStateUpdated(fn (Set $set) => $set('city_id', null)),
73-
74-
Select::make('city_id')
75-
->label(__('organization.field.city'))
76-
->placeholder(__('placeholder.city'))
77-
->options(function (Get $get): array {
78-
$countyId = $get('county_id');
79-
80-
if (! $countyId) {
81-
return [];
82-
}
83-
84-
return City::query()
85-
->where('county_id', $countyId)
86-
->get()
87-
->mapWithKeys(fn (City $city) => [$city->id => $city->name_with_uat ?? $city->name])
88-
->toArray();
89-
})
90-
->searchable()
91-
->required()
92-
->disabled(fn (Get $get) => ! $get('county_id')),
68+
->useRelationship()
69+
->schema(),
9370

9471
TextInput::make('address')
9572
->label(__('organization.field.address'))

app/Filament/Admin/Resources/Institutions/Schemas/InstitutionFormSchema.php

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66

77
use App\Enums\AreaType;
88
use App\Enums\OrganizationType;
9-
use App\Models\City;
9+
use App\Forms\Components\CountyCitySelect;
1010
use Filament\Forms\Components\Select;
1111
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
1212
use Filament\Forms\Components\TextInput;
1313
use Filament\Schemas\Components\Grid;
1414
use Filament\Schemas\Components\Section;
15-
use Filament\Schemas\Components\Utilities\Get;
16-
use Filament\Schemas\Components\Utilities\Set;
1715

1816
class InstitutionFormSchema
1917
{
@@ -63,35 +61,14 @@ public static function getSchema(): array
6361
->enum(AreaType::class)
6462
->required(),
6563

66-
Select::make('county_id')
67-
->label(__('organization.field.county'))
68-
->placeholder(__('organization.placeholders.county'))
69-
->relationship('county', 'name')
70-
->searchable()
71-
->preload()
64+
...CountyCitySelect::make()
65+
->countyLabel(__('organization.field.county'))
66+
->cityLabel(__('organization.field.city'))
67+
->countyPlaceholder(__('organization.placeholders.county'))
68+
->cityPlaceholder(__('placeholder.city'))
7269
->required()
73-
->live()
74-
->afterStateUpdated(fn (Set $set) => $set('city_id', null)),
75-
76-
Select::make('city_id')
77-
->label(__('organization.field.city'))
78-
->placeholder(__('placeholder.city'))
79-
->options(function (Get $get): array {
80-
$countyId = $get('county_id');
81-
82-
if (! $countyId) {
83-
return [];
84-
}
85-
86-
return City::query()
87-
->where('county_id', $countyId)
88-
->get()
89-
->mapWithKeys(fn (City $city) => [$city->id => $city->name_with_uat ?? $city->name])
90-
->toArray();
91-
})
92-
->searchable()
93-
->required()
94-
->disabled(fn (Get $get) => ! $get('county_id')),
70+
->useRelationship()
71+
->schema(),
9572

9673
TextInput::make('address')
9774
->label(__('organization.field.address'))

0 commit comments

Comments
 (0)