mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 00:33:44 -04:00
Livewire rebuilds listener names from the session team on every event call. After a team switch in another tab, open pages still listen on the old team channel, so events failed with EventHandlerDoesNotExist (500), or ran handlers that load resources scoped to the new team (404). Store the team at mount and build team channel listeners from it. Events for a team that is no longer the session team are ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Project\Service;
|
|
|
|
use App\Models\Service;
|
|
use App\Models\ServiceApplication;
|
|
use App\Models\ServiceDatabase;
|
|
use App\Traits\ListensToTeamChannel;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Component;
|
|
|
|
class ResourceCard extends Component
|
|
{
|
|
use AuthorizesRequests;
|
|
use ListensToTeamChannel;
|
|
|
|
public Service $service;
|
|
|
|
public ServiceApplication|ServiceDatabase $resource;
|
|
|
|
public array $parameters = [];
|
|
|
|
public function getListeners(): array
|
|
{
|
|
return $this->teamChannelListeners([
|
|
'ServiceChecked' => 'refreshResource',
|
|
]);
|
|
}
|
|
|
|
public function refreshResource(): void
|
|
{
|
|
$this->resource->refresh();
|
|
}
|
|
|
|
public function restart(): void
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->service);
|
|
$this->resource->restart();
|
|
$message = $this->resource instanceof ServiceApplication
|
|
? 'Service application restarted successfully.'
|
|
: 'Service database restarted successfully.';
|
|
$this->dispatch('success', $message);
|
|
} catch (\Throwable $e) {
|
|
handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.project.service.resource-card', [
|
|
'isApplication' => $this->resource instanceof ServiceApplication,
|
|
'isDatabase' => $this->resource instanceof ServiceDatabase,
|
|
]);
|
|
}
|
|
}
|