authorizeAbility($request, 'service_queues.console'); $organization = $this->organization($request); if (! $this->integrationEnabled($organization)) { return redirect()->route('frontdesk.settings')->with('error', 'Enable Ladill Queue integration in settings first.'); } $owner = $this->ownerRef($request); try { $counters = $queue->counters($owner); } catch (RequestException $e) { if ($queue->configured() && $e->response?->status() === 403) { try { $queue->syncIntegration($owner, true); $counters = $queue->counters($owner); } catch (RequestException) { return redirect()->route('frontdesk.settings')->with('error', 'Ladill Queue integration is not enabled. Save settings with Queue integration checked, and enable Frontdesk in Queue settings.'); } } else { return redirect()->route('frontdesk.settings')->with('error', 'Could not reach Ladill Queue. Enable Frontdesk integration in Queue settings and verify API keys.'); } } return view('frontdesk.service-queues.index', compact('counters', 'organization')); } public function console(Request $request, string $counterUuid, QueueClient $queue): View|RedirectResponse { $this->authorizeAbility($request, 'service_queues.console'); $organization = $this->organization($request); $owner = $this->ownerRef($request); if (! $this->integrationEnabled($organization)) { return redirect()->route('frontdesk.settings'); } try { $state = $queue->console($owner, $counterUuid); } catch (RequestException) { return redirect()->route('frontdesk.service-queues.index')->with('error', 'Counter console unavailable.'); } return view('frontdesk.service-queues.console', [ 'state' => $state, 'counterUuid' => $counterUuid, 'organization' => $organization, ]); } public function action(Request $request, string $counterUuid, QueueClient $queue): RedirectResponse { $this->authorizeAbility($request, 'service_queues.console'); $owner = $this->ownerRef($request); $validated = $request->validate([ 'action' => ['required', 'string'], 'queue_uuid' => ['nullable', 'uuid'], 'ticket_uuid' => ['nullable', 'uuid'], 'to_queue_uuid' => ['nullable', 'uuid'], 'reason' => ['nullable', 'string', 'max:500'], ]); try { $queue->consoleAction($owner, $counterUuid, $validated); } catch (RequestException) { return back()->with('error', 'Queue action failed. Try again.'); } return back()->with('success', 'Queue updated.'); } protected function integrationEnabled(\App\Models\Organization $organization): bool { return (bool) data_get($organization->settings, 'queue_integration_enabled', false); } }