Add in-app Ladill Queue integration for service queue consoles.
Deploy Ladill Frontdesk / deploy (push) Successful in 46s

Settings toggle provisions Queue org via API; reception can call tickets from Frontdesk.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-29 21:51:23 +00:00
co-authored by Cursor
parent 8e45bc1cfb
commit a715faf511
12 changed files with 372 additions and 1 deletions
@@ -0,0 +1,87 @@
<?php
namespace App\Http\Controllers\Frontdesk;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Services\Queue\QueueClient;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class ServiceQueueController extends Controller
{
use ScopesToAccount;
public function index(Request $request, QueueClient $queue): View|RedirectResponse
{
$this->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) {
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);
}
}
@@ -9,6 +9,7 @@ use App\Services\Frontdesk\FrontdeskPermissions;
use App\Services\Frontdesk\NotificationPricingService;
use App\Services\Frontdesk\NotificationUsageService;
use App\Services\Frontdesk\PlanService;
use App\Services\Queue\QueueClient;
use App\Support\OrganizationBranding;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -52,10 +53,11 @@ class SettingsController extends Controller
]);
}
public function update(Request $request): RedirectResponse
public function update(Request $request, QueueClient $queue): RedirectResponse
{
$this->authorizeAbility($request, 'settings.manage');
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
@@ -71,10 +73,24 @@ class SettingsController extends Controller
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
'remove_logo' => ['nullable', 'boolean'],
'employee_kiosk_enabled' => ['nullable', 'boolean'],
'queue_integration_enabled' => ['nullable', 'boolean'],
]);
$settings = $organization->settings ?? [];
$settings['onboarded'] = true;
$wantsQueue = $request->boolean('queue_integration_enabled');
$hadQueue = (bool) data_get($settings, 'queue_integration_enabled', false);
$settings['queue_integration_enabled'] = $wantsQueue;
if ($wantsQueue && ! $hadQueue && $queue->configured()) {
$branch = Branch::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->first();
try {
$queue->enable($owner, $organization->name, $branch?->name);
} catch (\Throwable) {
return back()->withInput()->with('error', 'Could not provision Ladill Queue for this account. Ensure Queue API keys are configured and Queue allows Frontdesk integration.');
}
}
$settings['badge_expiry_hours'] = $validated['badge_expiry_hours'];
$settings['kiosk_reset_seconds'] = $validated['kiosk_reset_seconds'];
$settings['visitor_policy'] = $validated['visitor_policy'] ?? null;
@@ -17,10 +17,12 @@ class FrontdeskPermissions
'settings.view', 'admin.branches.view', 'admin.desks.view', 'admin.desks.manage',
'watchlist.view', 'watchlist.manage', 'audit.view', 'audit.export',
'devices.view', 'devices.manage', 'reports.view', 'reports.export',
'service_queues.console',
],
'receptionist' => [
'dashboard.view', 'visits.view', 'visits.manage', 'visitors.view', 'visitors.manage',
'hosts.view', 'employees.view', 'kiosk.use', 'watchlist.view', 'devices.view',
'service_queues.console',
],
'security_officer' => [
'dashboard.view', 'visits.view', 'visitors.view', 'employees.view',
+104
View File
@@ -0,0 +1,104 @@
<?php
namespace App\Services\Queue;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
class QueueClient
{
private function base(): string
{
return rtrim((string) config('frontdesk.queue.api_url'), '/');
}
private function token(): string
{
return (string) (config('frontdesk.queue.api_key') ?? '');
}
private function http(string $owner)
{
return Http::withToken($this->token())
->acceptJson()
->timeout(12)
->withQueryParameters(['owner' => $owner]);
}
public function configured(): bool
{
return $this->token() !== '' && $this->base() !== '';
}
/**
* @return array<string, mixed>
*/
public function status(string $owner): array
{
$response = $this->http($owner)->get($this->base().'/integrations/status');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @return array<string, mixed>
*/
public function enable(string $owner, string $organizationName, ?string $branchName = null): array
{
$response = $this->http($owner)->post($this->base().'/integrations/provision', array_filter([
'organization_name' => $organizationName,
'branch_name' => $branchName,
'industry' => 'visitor',
]));
$response->throw();
return (array) ($response->json('data') ?? []);
}
public function isLinked(string $owner): bool
{
if (! $this->configured()) {
return false;
}
try {
$status = $this->status($owner);
return (bool) ($status['provisioned'] ?? false)
&& (bool) data_get($status, 'integrations.frontdesk', false);
} catch (RequestException) {
return false;
}
}
/**
* @return list<array<string, mixed>>
*/
public function counters(string $owner): array
{
$response = $this->http($owner)->get($this->base().'/counters');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @return array<string, mixed>
*/
public function console(string $owner, string $counterUuid): array
{
$response = $this->http($owner)->get($this->base().'/counters/'.$counterUuid.'/console');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @param array<string, mixed> $payload
*/
public function consoleAction(string $owner, string $counterUuid, array $payload): void
{
$this->http($owner)->post($this->base().'/counters/'.$counterUuid.'/console', $payload)->throw();
}
}