49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Components;
|
|
|
|
use App\Enums\Status;
|
|
|
|
use Livewire\Component;
|
|
|
|
class Badge extends Component
|
|
{
|
|
|
|
public $status;
|
|
public string $type;
|
|
public int $id;
|
|
|
|
|
|
public function mount(string $status = null, $id = 0, $type = null)
|
|
{
|
|
$this->type = $type;
|
|
$this->id ??= $id;
|
|
$this->status = Status::tryFrom($status) ?? Status::Success;
|
|
}
|
|
|
|
public function getColorClasses(): string
|
|
{
|
|
return match ($this->status) {
|
|
Status::Success => 'bg-green-100 text-green-700',
|
|
Status::Failed => 'bg-red-100 text-red-700',
|
|
Status::Pending => 'bg-gray-100 text-gray-600',
|
|
};
|
|
}
|
|
|
|
public function setStatus(string $status): void
|
|
{
|
|
$this->status = Status::tryFrom($status) ?? Status::Success;
|
|
}
|
|
|
|
public function refreshPendingMessage()
|
|
{
|
|
$this->dispatch('PendingMessage:refresh');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
logger(sprintf('%s %s', __CLASS__, $this->id));
|
|
return view('livewire.components.badge');
|
|
}
|
|
}
|