88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
namespace App\Livewire\Filament;
|
|
|
|
use App\Filament\Pages\Strumenti\PostItGestione;
|
|
use App\Models\ChiamataPostIt;
|
|
use App\Models\User;
|
|
use App\Services\Cti\LiveIncomingCallService;
|
|
use App\Support\StabileContext;
|
|
use Filament\Notifications\Notification;
|
|
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;
|
|
}
|
|
|
|
$stabileId = StabileContext::resolveActiveStabileId($user);
|
|
if (! $stabileId) {
|
|
Notification::make()->title('Seleziona prima uno stabile attivo')->warning()->send();
|
|
return;
|
|
}
|
|
|
|
$postIt = ChiamataPostIt::query()->create([
|
|
'stabile_id' => (int) $stabileId,
|
|
'creato_da_user_id' => (int) $user->id,
|
|
'rubrica_id' => (int) ($this->liveIncomingCall['rubrica_id'] ?? 0) ?: null,
|
|
'telefono' => (string) ($this->liveIncomingCall['phone'] ?? ''),
|
|
'nome_chiamante' => (string) (($this->liveIncomingCall['rubrica_nome'] ?? '') ?: ('Chiamata ' . ($this->liveIncomingCall['phone'] ?? ''))),
|
|
'direzione' => 'in_arrivo',
|
|
'origine' => 'topbar_live_call',
|
|
'origine_id' => (string) ($this->liveIncomingCall['message_id'] ?? ''),
|
|
'oggetto' => 'Chiamata in arrivo da valutare',
|
|
'nota' => (string) ($this->liveIncomingCall['line'] ?? ('Chiamata in ingresso da ' . ($this->liveIncomingCall['phone'] ?? ''))),
|
|
'priorita' => 'Media',
|
|
'stato' => 'post_it',
|
|
'chiamata_il' => now(),
|
|
]);
|
|
|
|
Notification::make()->title('Post-it creato dalla testata')->success()->send();
|
|
|
|
$this->redirect(
|
|
PostItGestione::getUrl([
|
|
'tab' => 'storico',
|
|
'focus_post_it' => (int) $postIt->id,
|
|
], 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');
|
|
}
|
|
}
|