22
33declare (strict_types=1 );
44
5- namespace App \Filament \Organizations \Resources \MonitoringResource \Pages ;
5+ namespace App \Filament \Organizations \Resources \BeneficiaryResource \ Resources \ MonitoringResource \Pages ;
66
77use Filament \Schemas \Components \Wizard \Step ;
88use App \Actions \BackAction ;
99use App \Concerns \PreventMultipleSubmit ;
1010use App \Concerns \PreventSubmitFormOnEnter ;
1111use App \Filament \Organizations \Resources \BeneficiaryResource ;
12- use App \Filament \Organizations \Resources \MonitoringResource ;
12+ use App \Filament \Organizations \Resources \BeneficiaryResource \Resources \MonitoringResource ;
13+ use App \Filament \Organizations \Resources \BeneficiaryResource \Resources \MonitoringResource \Pages \EditDetails ;
14+ use App \Filament \Organizations \Resources \BeneficiaryResource \Resources \MonitoringResource \Pages \EditChildren ;
15+ use App \Filament \Organizations \Resources \BeneficiaryResource \Resources \MonitoringResource \Pages \EditGeneral ;
1316use App \Models \Monitoring ;
1417use App \Models \Specialist ;
1518use App \Services \Breadcrumb \BeneficiaryBreadcrumb ;
@@ -39,7 +42,7 @@ class CreateMonitoring extends CreateRecord
3942 public function getBreadcrumbs (): array
4043 {
4144 $ breadcrumb = __ ('monitoring.breadcrumbs.file ' , ['file_number ' => null ]);
42- $ ownerRecord = $ this ->getOwnerRecord ();
45+ $ ownerRecord = $ this ->getParentRecord ();
4346
4447 return array_merge (
4548 BeneficiaryBreadcrumb::make ($ ownerRecord )
@@ -55,23 +58,26 @@ public function getTitle(): string|Htmlable
5558
5659 protected function getRedirectUrl (): string
5760 {
58- return MonitoringResource::getUrl ('view ' , [
61+ $ parentRecord = $ this ->getParentRecord ();
62+ return static ::getResource ()::getUrl ('view ' , [
63+ 'beneficiary ' => $ parentRecord ,
5964 'record ' => $ this ->record ,
6065 ]);
6166 }
6267
6368 protected function getHeaderActions (): array
6469 {
70+ $ parentRecord = $ this ->getParentRecord ();
6571 return [
6672 BackAction::make ()
67- ->url (MonitoringResource:: getUrl ('index ' )),
73+ ->url (static :: getResource ():: getUrl ('index ' , [ ' beneficiary ' => $ parentRecord ] )),
6874 ];
6975 }
7076
7177 protected function afterFill (): void
7278 {
7379 $ copyLastFile = (bool ) request ('copyLastFile ' );
74- $ ownerRecord = $ this ->getOwnerRecord ();
80+ $ ownerRecord = $ this ->getParentRecord ();
7581 $ this ->lastFile = $ ownerRecord
7682 ->monitorings
7783 ->sortByDesc ('id ' )
@@ -100,17 +106,17 @@ public function getSteps(): array
100106 return [
101107
102108 Step::make (__ ('monitoring.headings.details ' ))
103- ->schema (EditDetails::getSchema ())
109+ ->schema (EditDetails::getFormSchemaStatic ())
104110 ->afterStateHydrated (fn (Set $ set ) => $ set ('specialistsTeam ' , $ this ->specialistTeam )),
105111
106112 Step::make (__ ('monitoring.headings.child_info ' ))
107- ->schema (EditChildren::getSchema ())
113+ ->schema (EditChildren::getFormSchemaStatic ())
108114 ->afterStateHydrated (function (Set $ set ) {
109115 $ set ('children ' , $ this ->children );
110116 }),
111117
112118 Step::make (__ ('monitoring.headings.general ' ))
113- ->schema (EditGeneral::getSchema ()),
119+ ->schema (EditGeneral::getFormSchemaStatic ()),
114120
115121 ];
116122 }
@@ -127,21 +133,21 @@ protected function getCancelFormAction(): Action
127133 {
128134 return Action::make ('cancel ' )
129135 ->label (__ ('filament-panels::resources/pages/create-record.form.actions.cancel.label ' ))
130- ->alpineClickHandler ('document.referrer ? window.history.back() : (window.location.href = ' . Js::from ($ this ->previousUrl ?? MonitoringResource:: getUrl ('index ' )) . ') ' )
136+ ->alpineClickHandler ('document.referrer ? window.history.back() : (window.location.href = ' . Js::from ($ this ->previousUrl ?? static :: getResource ():: getUrl ('index ' , [ ' beneficiary ' => $ this -> getParentRecord ()] )) . ') ' )
131137 ->color ('gray ' );
132138 }
133139
134140 protected function mutateFormDataBeforeCreate (array $ data ): array
135141 {
136142 // Set the parent relationship key to the parent resource's ID.
137- $ data ['beneficiary_id ' ] = $ this ->getOwnerRecord ()->id ;
143+ $ data ['beneficiary_id ' ] = $ this ->getParentRecord ()->id ;
138144
139145 return $ data ;
140146 }
141147
142148 private function getChildren (): array
143149 {
144- $ ownerRecord = $ this ->getOwnerRecord ();
150+ $ ownerRecord = $ this ->getParentRecord ();
145151
146152 if ($ this ->lastFile && $ this ->lastFile ->children ->isNotEmpty ()) {
147153 return $ this ->lastFile ->children ->toArray ();
@@ -152,7 +158,7 @@ private function getChildren(): array
152158
153159 private function getSpecialists (): array
154160 {
155- $ ownerRecord = $ this ->getOwnerRecord ();
161+ $ ownerRecord = $ this ->getParentRecord ();
156162
157163 if ($ this ->lastFile && $ this ->lastFile ->specialistsTeam ->isNotEmpty ()) {
158164 return $ this ->lastFile
0 commit comments