Skip to content

Commit c8245cc

Browse files
refactor form schemas to replace Grid with Group components for improved layout flexibility
1 parent b36ef26 commit c8245cc

File tree

6 files changed

+178
-146
lines changed

6 files changed

+178
-146
lines changed

app/Filament/Organizations/Resources/Cases/Pages/CreateCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ protected function getSteps(): array
133133
->schema([
134134
...PersonalInfoFormSchema::getSchema(),
135135
Section::make(__('case.create.wizard.aggressor'))
136+
->maxWidth('3xl')
136137
->schema([
137138
Repeater::make('aggressors')
138139
->schema(AggressorFormSchema::getRepeaterItemSchema())
@@ -149,6 +150,7 @@ protected function getSteps(): array
149150
->defaultItems(1),
150151
]),
151152
Section::make(__('case.create.wizard.flow_presentation'))
153+
->maxWidth('3xl')
152154
->schema(FlowPresentationFormSchema::getSchemaForCreateWizard()),
153155
]),
154156

@@ -304,15 +306,13 @@ protected function afterCreate(): void
304306
}
305307
}
306308

307-
$selected = $this->pendingCaseTeamSelection;
308-
$roleIds = self::normalizeCaseTeamSelection($selected);
309-
if ($roleIds === null || $roleIds === []) {
310-
return;
311-
}
309+
310+
$roleIds=$state['case_team'] ?? [];
312311
$currentUserId = auth()->id();
313312
if (! $currentUserId) {
314313
return;
315314
}
315+
316316
foreach ($roleIds as $roleId) {
317317
$beneficiary->specialistsTeam()->create([
318318
'role_id' => $roleId,

app/Filament/Organizations/Resources/Cases/Schemas/AggressorFormSchema.php

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use App\Rules\MultipleIn;
2020
use Filament\Forms\Components\Textarea;
2121
use Filament\Forms\Components\TextInput;
22-
use Filament\Schemas\Components\Grid;
2322
use Filament\Schemas\Components\Group;
2423
use Filament\Schemas\Components\Utilities\Get;
2524

@@ -83,72 +82,75 @@ public static function getRepeaterItemSchema(): array
8382
->options(Occupation::options())
8483
->enum(Occupation::class),
8584

86-
Grid::make()
87-
->schema([
88-
Select::make('has_violence_history')
89-
->label(__('field.aggressor_has_violence_history'))
90-
->placeholder(__('placeholder.select_one'))
91-
->options(Ternary::options())
92-
->enum(Ternary::class)
93-
->live(),
94-
95-
Group::make([
85+
Group::make([
86+
Select::make('has_violence_history')
87+
->label(__('field.aggressor_has_violence_history'))
88+
->placeholder(__('placeholder.select_one'))
89+
->options(Ternary::options())
90+
->enum(Ternary::class)
91+
->live(),
92+
Group::make()
93+
->visible(fn (Get $get): bool => Ternary::isYes($get('has_violence_history')))
94+
->columns(1)
95+
->schema([
9696
Select::make('violence_types')
9797
->label(__('field.aggressor_violence_types'))
9898
->placeholder(__('placeholder.select_many'))
9999
->options(Violence::options())
100100
->rule(new MultipleIn(Violence::values()))
101101
->multiple(),
102-
])->visible(fn (Get $get): bool => Ternary::isYes($get('has_violence_history')))
103-
->columns(2)
104-
->columnSpanFull(),
105-
]),
106-
107-
Grid::make()
108-
->schema([
109-
Select::make('legal_history')
110-
->label(__('field.aggressor_legal_history'))
111-
->placeholder(__('placeholder.select_many'))
112-
->options(AggressorLegalHistory::options())
113-
->rule(new MultipleIn(AggressorLegalHistory::values()))
114-
->multiple()
115-
->live(),
116-
Textarea::make('legal_history_notes')
117-
->label(__('field.aggressor_legal_history_notes'))
118-
->placeholder(__('placeholder.input_text'))
119-
->maxLength(100),
120-
])->visible(fn (Get $get): bool => Ternary::isYes($get('has_violence_history'))),
121-
122-
Grid::make()
102+
Select::make('legal_history')
103+
->label(__('field.aggressor_legal_history'))
104+
->placeholder(__('placeholder.select_many'))
105+
->options(AggressorLegalHistory::options())
106+
->rule(new MultipleIn(AggressorLegalHistory::values()))
107+
->multiple()
108+
->live(),
109+
Textarea::make('legal_history_notes')
110+
->label(__('field.aggressor_legal_history_notes'))
111+
->placeholder(__('placeholder.input_text'))
112+
->maxLength(100),
113+
]),
114+
])->columnSpanFull()->columns(2),
115+
116+
Group::make()
123117
->schema([
124118
Select::make('has_protection_order')
125119
->label(__('field.has_protection_order'))
126120
->placeholder(__('placeholder.select_one'))
127121
->options(ProtectionOrder::options())
128122
->enum(ProtectionOrder::class)
129123
->live(),
130-
131-
Select::make('electronically_monitored')
132-
->label(__('field.electronically_monitored'))
133-
->placeholder(__('placeholder.select_one'))
134-
->options(Ternary::options())
135-
->enum(Ternary::class)
136-
->visible(
137-
fn (Get $get): bool => ProtectionOrder::ISSUED_BY_COURT->is($get('has_protection_order')) ||
138-
ProtectionOrder::TEMPORARY->is($get('has_protection_order'))
139-
),
140-
141-
TextInput::make('protection_order_notes')
142-
->label(__('field.protection_order_notes'))
143-
->placeholder(__('placeholder.input_text'))
144-
->visible(
145-
fn (Get $get): bool => ! ProtectionOrder::NO->is($get('has_protection_order')) &&
146-
! ProtectionOrder::UNKNOWN->is($get('has_protection_order'))
147-
)
148-
->maxLength(100),
149-
]),
150-
151-
Grid::make()
124+
Group::make()
125+
->columns(1)
126+
->schema([
127+
Select::make('electronically_monitored')
128+
->label(__('field.electronically_monitored'))
129+
->placeholder(__('placeholder.select_one'))
130+
->options(Ternary::options())
131+
->enum(Ternary::class)
132+
->visible(
133+
fn (Get $get): bool => ProtectionOrder::ISSUED_BY_COURT->is($get('has_protection_order')) ||
134+
ProtectionOrder::TEMPORARY->is($get('has_protection_order'))
135+
),
136+
137+
TextInput::make('protection_order_notes')
138+
->label(__('field.protection_order_notes'))
139+
->placeholder(__('placeholder.input_text'))
140+
->visible(
141+
fn (Get $get): bool => ! ProtectionOrder::NO->is($get('has_protection_order')) &&
142+
! ProtectionOrder::UNKNOWN->is($get('has_protection_order'))
143+
)
144+
->maxLength(100),
145+
]),
146+
147+
])
148+
->columnSpanFull()
149+
->columns(2),
150+
151+
Group::make()
152+
->columnSpanFull()
153+
->columns(2)
152154
->schema([
153155
Select::make('has_psychiatric_history')
154156
->label(__('field.aggressor_has_psychiatric_history'))
@@ -164,7 +166,9 @@ public static function getRepeaterItemSchema(): array
164166
->visible(fn (Get $get): bool => Ternary::isYes($get('has_psychiatric_history'))),
165167
]),
166168

167-
Grid::make()
169+
Group::make()
170+
->columnSpanFull()
171+
->columns(2)
168172
->schema([
169173
Select::make('has_drug_history')
170174
->label(__('field.aggressor_has_drug_history'))

app/Filament/Organizations/Resources/Cases/Schemas/ChildrenIdentityFormSchema.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static function getSchema(): array
6666
Grid::make()
6767
->disabled(fn (Get $get) => $get('doesnt_have_children'))
6868
->hidden(fn (Get $get) => $get('doesnt_have_children'))
69+
->columnSpanFull()
6970
->schema([
7071
TextInput::make('children_total_count')
7172
->label(__('field.children_total_count'))
@@ -160,14 +161,18 @@ function () use ($state) {
160161
->itemLabel(fn (array $state): ?string => $state['name'] ?? null)
161162
->collapsible(),
162163

163-
Textarea::make('children_notes')
164-
->label(__('field.children_notes'))
165-
->placeholder(__('placeholder.other_relevant_details'))
166-
->disabled(fn (Get $get) => $get('doesnt_have_children'))
167-
->hidden(fn (Get $get) => $get('doesnt_have_children'))
168-
->maxLength(500)
164+
Grid::make()
169165
->maxWidth('3xl')
170-
->columnSpanFull(),
166+
->hidden(fn (Get $get) => $get('doesnt_have_children'))
167+
->schema([
168+
Textarea::make('children_notes')
169+
->label(__('field.children_notes'))
170+
->placeholder(__('placeholder.other_relevant_details'))
171+
->disabled(fn (Get $get) => $get('doesnt_have_children'))
172+
->maxLength(500)
173+
->maxWidth('3xl')
174+
->columnSpanFull(),
175+
]),
171176
];
172177
}
173178
}

app/Filament/Organizations/Resources/Cases/Schemas/FlowPresentationFormSchema.php

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Rules\MultipleIn;
1515
use Filament\Forms\Components\TextInput;
1616
use Filament\Schemas\Components\Grid;
17+
use Filament\Schemas\Components\Group;
1718
use Filament\Schemas\Components\Utilities\Get;
1819

1920
class FlowPresentationFormSchema
@@ -32,66 +33,78 @@ public static function getSchemaForCreateWizard(): array
3233
->all();
3334

3435
return [
35-
Grid::make()
36+
Group::make()
3637
->statePath('flow_presentation')
3738
->maxWidth('3xl')
39+
->columns(2)
3840
->schema([
39-
Grid::make()
41+
Group::make()
42+
->columnSpanFull()
43+
->columns(2)
4044
->schema([
4145
Select::make('presentation_mode')
4246
->label(__('field.presentation_mode'))
4347
->placeholder(__('placeholder.select_one'))
4448
->options(PresentationMode::options())
4549
->enum(PresentationMode::class)
4650
->live(),
51+
Group::make()
52+
->schema([
53+
Select::make('referring_institution_id')
54+
->label(__('field.referring_institution'))
55+
->placeholder(__('placeholder.select_one'))
56+
->options($institutionOptions)
57+
->visible(fn (Get $get) => PresentationMode::isValue(
58+
$get('presentation_mode'),
59+
PresentationMode::FORWARDED
60+
))
61+
->nullable(),
4762

48-
Select::make('referring_institution_id')
49-
->label(__('field.referring_institution'))
50-
->placeholder(__('placeholder.select_one'))
51-
->options($institutionOptions)
52-
->visible(fn (Get $get) => PresentationMode::isValue(
53-
$get('presentation_mode'),
54-
PresentationMode::FORWARDED
55-
))
56-
->nullable(),
63+
Select::make('referral_mode')
64+
->label(__('field.referral_mode'))
65+
->placeholder(__('placeholder.select_one'))
66+
->options(ReferralMode::options())
67+
->enum(ReferralMode::class)
68+
->visible(fn (Get $get) => PresentationMode::isValue(
69+
$get('presentation_mode'),
70+
PresentationMode::FORWARDED
71+
))
72+
->nullable(),
73+
]),
5774

58-
Select::make('referral_mode')
59-
->label(__('field.referral_mode'))
60-
->placeholder(__('placeholder.select_one'))
61-
->options(ReferralMode::options())
62-
->enum(ReferralMode::class)
63-
->visible(fn (Get $get) => PresentationMode::isValue(
64-
$get('presentation_mode'),
65-
PresentationMode::FORWARDED
66-
))
67-
->nullable(),
6875
]),
6976

70-
Grid::make()
77+
Group::make()
78+
->columnSpanFull()
79+
->columns(2)
7180
->schema([
7281
Select::make('notifier')
7382
->label(__('field.notifier'))
7483
->placeholder(__('placeholder.select_one'))
7584
->options(Notifier::options())
7685
->enum(Notifier::class)
7786
->live(),
87+
Group::make()
88+
->schema([
7889

79-
Select::make('notification_mode')
80-
->label(__('field.notification_mode'))
81-
->placeholder(__('placeholder.select_one'))
82-
->options(NotificationMode::options())
83-
->enum(NotificationMode::class),
90+
Select::make('notification_mode')
91+
->label(__('field.notification_mode'))
92+
->placeholder(__('placeholder.select_one'))
93+
->options(NotificationMode::options())
94+
->enum(NotificationMode::class),
8495

85-
TextInput::make('notifier_other')
86-
->label(__('field.notifier_other'))
87-
->maxLength(100)
88-
->visible(fn (Get $get) => Notifier::isValue(
89-
$get('notifier'),
90-
Notifier::OTHER
91-
)),
96+
TextInput::make('notifier_other')
97+
->label(__('field.notifier_other'))
98+
->maxLength(100)
99+
->visible(fn (Get $get) => Notifier::isValue(
100+
$get('notifier'),
101+
Notifier::OTHER
102+
))]),
92103
]),
93104

94-
Grid::make()
105+
Group::make()
106+
->columnSpanFull()
107+
->columns(2)
95108
->schema([
96109
Select::make('act_location')
97110
->label(__('field.act_location'))

0 commit comments

Comments
 (0)