File tree Expand file tree Collapse file tree 15 files changed +52
-44
lines changed
resources/views/components/livewire/people
tests/Feature/Livewire/People/Edit Expand file tree Collapse file tree 15 files changed +52
-44
lines changed Original file line number Diff line number Diff line change 88use App \Livewire \Traits \TrimStringsAndConvertEmptyStringsToNull ;
99use App \Models \Person ;
1010use Illuminate \Support \Collection ;
11+ use Livewire \Attributes \On ;
1112use Livewire \Component ;
1213use Livewire \WithFileUploads ;
1314use TallStackUi \Traits \Interactions ;
2930
3031 public ?string $ selectedTab = null ;
3132
33+ #[On('person_added_as_child ' )]
3234 public function mount (): void
3335 {
36+ $ this ->form ->reset ();
37+
3438 $ this ->persons = Person::where ('id ' , '!= ' , $ this ->person ->id )
3539 ->whereNull ($ this ->person ->sex === 'm ' ? 'father_id ' : 'mother_id ' )
3640 ->youngerThan ($ this ->person ->dob , $ this ->person ->yob )
@@ -56,7 +60,7 @@ public function saveChild(): void
5660 $ this ->createNewChild ($ validated ['form ' ]);
5761 }
5862
59- $ this ->redirect ( route ( ' people.show ' , $ this -> person -> id ) );
63+ $ this ->dispatch ( ' person_added_as_child ' );
6064 }
6165
6266 /**
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public function saveFather(): void
5757 $ this ->createNewFather ($ validated ['form ' ]);
5858 }
5959
60- $ this ->redirect ( route ( ' people.show ' , $ this -> person -> id ) );
60+ $ this ->dispatch ( ' father_added ' );
6161 }
6262
6363 /**
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ public function saveMother(): void
5757 $ this ->createNewMother ($ validated ['form ' ]);
5858 }
5959
60- $ this ->redirect ( route ( ' people.show ' , $ this -> person -> id ) );
60+ $ this ->dispatch ( ' mother_added ' );
6161 }
6262
6363 /**
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ public function savePartner(): void
7777 $ this ->createNewPartner ($ validated );
7878 }
7979
80- $ this ->redirect ( route ( ' people.show ' , $ this -> person -> id ) );
80+ $ this ->dispatch ( ' couple_added ' );
8181 }
8282
8383 /**
Original file line number Diff line number Diff line change 2121
2222 public PersonForm $ form ;
2323
24- public function mount (): void {}
25-
2624 public function savePerson (): void
2725 {
2826 $ user = auth ()->user ();
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ public function saveFamily(): void
7272
7373 $ this ->toast ()->success (__ ('app.save ' ), __ ('app.saved ' ))->send ();
7474
75- $ this ->redirect ( ' /people/ ' . $ this -> person -> id );
75+ $ this ->dispatch ( ' family_updated ' );
7676 }
7777
7878 // -----------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -63,21 +63,21 @@ public function savePartner(): void
6363 'date_start ' => $ validated ['date_start ' ] ?? null ,
6464 'date_end ' => $ validated ['date_end ' ] ?? null ,
6565 'is_married ' => $ validated ['is_married ' ],
66- 'has_ended ' => $ validated ['date_end ' ] or $ validated ['has_ended ' ],
66+ 'has_ended ' => $ validated ['date_end ' ] || $ validated ['has_ended ' ],
6767 ]);
6868 } elseif ($ this ->person ->id === $ this ->couple ->person2_id ) {
6969 $ this ->couple ->update ([
7070 'person1_id ' => $ validated ['partner_id ' ],
7171 'date_start ' => $ validated ['date_start ' ] ?? null ,
7272 'date_end ' => $ validated ['date_end ' ] ?? null ,
7373 'is_married ' => $ validated ['is_married ' ],
74- 'has_ended ' => $ validated ['date_end ' ] or $ validated ['has_ended ' ],
74+ 'has_ended ' => $ validated ['date_end ' ] || $ validated ['has_ended ' ],
7575 ]);
7676 }
7777
7878 $ this ->toast ()->success (__ ('app.save ' ), __ ('app.saved ' ))->send ();
7979
80- $ this ->redirect ( ' /people/ ' . $ this -> person -> id );
80+ $ this ->dispatch ( ' couple_updated ' );
8181 }
8282
8383 // -----------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ public function saveProfile(): void
6969
7070 $ this ->toast ()->success (__ ('app.save ' ), __ ('app.saved ' ))->send ();
7171
72- $ this ->redirect ( ' /people/ ' . $ this -> person -> id );
72+ $ this ->dispatch ( ' person_updated ' );
7373 }
7474
7575 // -----------------------------------------------------------------------
Original file line number Diff line number Diff line change 44
55use App \Models \Person ;
66use Illuminate \Support \Collection ;
7+ use Livewire \Attributes \On ;
78use Livewire \Component ;
89use TallStackUi \Traits \Interactions ;
910
1920 public Collection $ children ;
2021
2122 // ------------------------------------------------------------------------------
23+ #[On('person_added_as_child ' )]
2224 public function mount (): void
2325 {
2426 $ this ->children = $ this ->person ->childrenNaturalAll ();
@@ -48,6 +50,6 @@ public function disconnect(int $child_id): void
4850
4951 $ this ->toast ()->success (__ ('app.disconnect ' ), e ($ child ->name ) . ' ' . __ ('app.disconnected ' ) . '. ' )->send ();
5052
51- $ this ->redirect ( route ( ' people.show ' , $ this -> person -> id ) );
53+ $ this ->dispatch ( ' person_added_as_child ' );
5254 }
5355};
Original file line number Diff line number Diff line change 33declare (strict_types=1 );
44
55use App \Models \Person ;
6+ use Livewire \Attributes \On ;
67use Livewire \Component ;
78
89new class extends Component
1112 public Person $ person ;
1213
1314 // ------------------------------------------------------------------------------
14- /** @var array<string, string> */
15- protected $ listeners = [
16- 'couple_deleted ' => 'render ' ,
17- ];
15+ #[On('couple_added ' )]
16+ #[On('couple_deleted ' )]
17+ #[On('family_updated ' )]
18+ #[On('father_added ' )]
19+ #[On('mother_added ' )]
20+ public function refreshFamily (): void
21+ {
22+ // optionally refresh any data here
23+ // Livewire will re-render automatically
24+ }
1825};
You can’t perform that action at this time.
0 commit comments