From 5c8ba2b93d42aa4cdad4f9d43aa7ca78bd58bae3 Mon Sep 17 00:00:00 2001 From: JulSteele <20680187+julsteele@users.noreply.github.com> Date: Wed, 31 Jan 2024 00:17:23 +0100 Subject: [PATCH] fix(admin): share/assistant removal when status is Canceled --- .../RelationManagers/ChildrenRelationManager.php | 2 +- app/Models/Application.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/ApplicationResource/RelationManagers/ChildrenRelationManager.php b/app/Filament/Resources/ApplicationResource/RelationManagers/ChildrenRelationManager.php index f8fde1c..c086d48 100644 --- a/app/Filament/Resources/ApplicationResource/RelationManagers/ChildrenRelationManager.php +++ b/app/Filament/Resources/ApplicationResource/RelationManagers/ChildrenRelationManager.php @@ -58,7 +58,7 @@ public function table(Table $table): Table ->url(fn (Application $record): string => ApplicationResource::getUrl('edit', ['record' => $record])), Tables\Actions\Action::make('Delete') ->action(function (Application $record): void { - $record->setStatusAttribute(ApplicationStatus::Canceled); + $record->deleteParentAndReset(); }) ->requiresConfirmation() ->color('danger'), diff --git a/app/Models/Application.php b/app/Models/Application.php index 81b7df1..04a4c4a 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -324,6 +324,21 @@ public function setStatusAttribute(ApplicationStatus|string $status) } } + /** + * Reset to Dealer if an application has been removed as a Share or Assistant. + */ + public function deleteParentAndReset() { + $this->update([ + 'offer_accepted_at' => null, + 'offer_sent_at' => null, + 'table_number' => null, + 'parent' => null, + 'waiting_at' => null, + 'type' => ApplicationType::Dealer, + 'canceled_at' => now(), + ]); + } + public static function findByUserId(int|null $user_id): Application|null { return self::where('user_id', $user_id)->first();