Skip to content

Commit

Permalink
fix(admin): share/assistant removal when status is Canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
julsteele committed Jan 30, 2024
1 parent 6d6570f commit 5c8ba2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
15 changes: 15 additions & 0 deletions app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5c8ba2b

Please sign in to comment.