67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Livewire\Filament;
|
|
|
|
use App\Filament\Pages\Strumenti\PostIt;
|
|
use App\Models\User;
|
|
use App\Services\Cti\LiveIncomingCallService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Component;
|
|
|
|
class TopbarLiveCall extends Component
|
|
{
|
|
/** @var array<string,mixed>|null */
|
|
public ?array $liveIncomingCall = null;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->refreshLiveIncomingCall();
|
|
}
|
|
|
|
public function refreshLiveIncomingCall(): void
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
$this->liveIncomingCall = null;
|
|
return;
|
|
}
|
|
|
|
$this->liveIncomingCall = app(LiveIncomingCallService::class)->getForUser($user);
|
|
}
|
|
|
|
public function createPostIt(): void
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User || ! $this->liveIncomingCall) {
|
|
return;
|
|
}
|
|
|
|
$this->redirect(
|
|
PostIt::getUrl([
|
|
'source' => 'topbar_live_call',
|
|
'telefono' => (string) ($this->liveIncomingCall['phone'] ?? ''),
|
|
'nome' => (string) ($this->liveIncomingCall['rubrica_nome'] ?? ''),
|
|
'rubrica_id' => (int) ($this->liveIncomingCall['rubrica_id'] ?? 0) ?: null,
|
|
'direzione' => 'in_arrivo',
|
|
'oggetto' => 'Chiamata in arrivo da valutare',
|
|
'nota' => (string) ($this->liveIncomingCall['line'] ?? ('Chiamata in ingresso da ' . ($this->liveIncomingCall['phone'] ?? ''))),
|
|
'lock_stabile' => 1,
|
|
], panel: 'admin-filament'),
|
|
navigate: true,
|
|
);
|
|
}
|
|
|
|
public function openTicketMobile()
|
|
{
|
|
if (! $this->liveIncomingCall || empty($this->liveIncomingCall['ticket_mobile_url'])) {
|
|
return null;
|
|
}
|
|
|
|
return redirect()->to((string) $this->liveIncomingCall['ticket_mobile_url']);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.filament.topbar-live-call');
|
|
}
|
|
}
|