Add settings logo upload and brand queue notification emails.
Deploy Ladill Queue / deploy (push) Successful in 55s
Deploy Ladill Queue / deploy (push) Successful in 55s
Let orgs manage logos in settings and render customer-facing mail with company branding. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Http\Controllers\Qms\Concerns\ScopesToAccount;
|
||||
use App\Models\Branch;
|
||||
use App\Services\Qms\AuditLogger;
|
||||
use App\Services\Qms\QmsPermissions;
|
||||
use App\Support\OrganizationBranding;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
@@ -48,6 +49,8 @@ class SettingsController extends Controller
|
||||
'notifications_enabled' => ['boolean'],
|
||||
'care_integration_enabled' => ['nullable', 'boolean'],
|
||||
'frontdesk_integration_enabled' => ['nullable', 'boolean'],
|
||||
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
|
||||
'remove_logo' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$settings = $organization->settings ?? [];
|
||||
@@ -63,9 +66,21 @@ class SettingsController extends Controller
|
||||
}
|
||||
$settings['integrations'] = $integrations;
|
||||
|
||||
$logoPath = $organization->logo_path;
|
||||
|
||||
if ($request->boolean('remove_logo')) {
|
||||
OrganizationBranding::deleteStoredLogo($organization);
|
||||
$logoPath = null;
|
||||
}
|
||||
|
||||
if ($request->hasFile('logo')) {
|
||||
$logoPath = OrganizationBranding::storeLogo($organization, $request->file('logo'));
|
||||
}
|
||||
|
||||
$organization->update([
|
||||
'name' => $validated['name'],
|
||||
'timezone' => $validated['timezone'],
|
||||
'logo_path' => $logoPath,
|
||||
'settings' => $settings,
|
||||
]);
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ class ContactMessageMail extends Mailable
|
||||
public string $bodyText,
|
||||
public ?string $fromName = null,
|
||||
public ?string $replyToAddress = null,
|
||||
public ?string $logoUrl = null,
|
||||
public ?string $companyName = null,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
@@ -34,6 +36,8 @@ class ContactMessageMail extends Mailable
|
||||
with: [
|
||||
'bodyText' => $this->bodyText,
|
||||
'fromName' => $this->fromName,
|
||||
'logoUrl' => $this->logoUrl,
|
||||
'companyName' => $this->companyName,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Services\Comms;
|
||||
|
||||
use App\Mail\ContactMessageMail;
|
||||
use App\Models\Organization;
|
||||
use App\Support\OrganizationBranding;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
@@ -13,14 +15,21 @@ use Illuminate\Support\Facades\Mail;
|
||||
*/
|
||||
class EmailService
|
||||
{
|
||||
public function send(string $to, string $subject, string $body, ?string $fromName = null, ?string $replyTo = null): bool
|
||||
public function send(string $to, string $subject, string $body, ?string $fromName = null, ?string $replyTo = null, ?Organization $organization = null): bool
|
||||
{
|
||||
if (! filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$logoUrl = null;
|
||||
$companyName = null;
|
||||
if ($organization) {
|
||||
$logoUrl = OrganizationBranding::emailLogoUrl($organization);
|
||||
$companyName = $organization->name;
|
||||
}
|
||||
|
||||
try {
|
||||
Mail::to($to)->send(new ContactMessageMail($subject, $body, $fromName, $replyTo));
|
||||
Mail::to($to)->send(new ContactMessageMail($subject, $body, $fromName, $replyTo, $logoUrl, $companyName));
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
@@ -47,7 +47,8 @@ class QueueNotificationService
|
||||
public function appointmentReminder(\App\Models\QueueAppointment $appointment): void
|
||||
{
|
||||
$message = "Reminder: your appointment at {$appointment->scheduled_at->format('M j, H:i')} is coming up. Ref: {$appointment->reference}";
|
||||
$this->sendToContact($appointment->customer_phone, $appointment->customer_email, $message);
|
||||
$organization = $appointment->organization;
|
||||
$this->sendToContact($appointment->customer_phone, $appointment->customer_email, $message, $organization);
|
||||
}
|
||||
|
||||
protected function notify(Ticket $ticket, string $event, string $message): void
|
||||
@@ -56,7 +57,8 @@ class QueueNotificationService
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendToContact($ticket->customer_phone, $ticket->customer_email, $message);
|
||||
$organization = $ticket->organization ?? $ticket->serviceQueue?->organization;
|
||||
$this->sendToContact($ticket->customer_phone, $ticket->customer_email, $message, $organization);
|
||||
|
||||
Log::info('Queue notification sent', [
|
||||
'event' => $event,
|
||||
@@ -64,13 +66,13 @@ class QueueNotificationService
|
||||
]);
|
||||
}
|
||||
|
||||
protected function sendToContact(?string $phone, ?string $email, string $message): void
|
||||
protected function sendToContact(?string $phone, ?string $email, string $message, ?\App\Models\Organization $organization = null): void
|
||||
{
|
||||
if ($phone) {
|
||||
$this->sms->send($phone, $message);
|
||||
}
|
||||
if ($email) {
|
||||
$this->email->send($email, 'Ladill Queue update', $message);
|
||||
$this->email->send($email, 'Ladill Queue update', $message, null, null, $organization);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,4 +54,27 @@ class OrganizationBranding
|
||||
Storage::disk('public')->delete($organization->logo_path);
|
||||
}
|
||||
}
|
||||
|
||||
public static function emailLogoUrl(Organization $organization): ?string
|
||||
{
|
||||
if (! self::hasCustomLogo($organization)) {
|
||||
return null;
|
||||
}
|
||||
$ext = strtolower(pathinfo($organization->logo_path, PATHINFO_EXTENSION));
|
||||
if ($ext === 'svg') {
|
||||
return null;
|
||||
}
|
||||
$version = $organization->updated_at?->getTimestamp() ?? time();
|
||||
|
||||
return Storage::disk('public')->url($organization->logo_path).'?v='.$version;
|
||||
}
|
||||
|
||||
public static function wrapEmailHtml(string $bodyHtml, Organization $organization): string
|
||||
{
|
||||
return view('email.customer-branded', [
|
||||
'logoUrl' => self::emailLogoUrl($organization),
|
||||
'companyName' => $organization->name,
|
||||
'bodyHtml' => $bodyHtml,
|
||||
])->render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,26 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body style="margin:0;background:#f1f5f9;font-family:Arial,Helvetica,sans-serif;color:#0f172a;">
|
||||
<div style="max-width:560px;margin:0 auto;padding:32px 16px;">
|
||||
<div style="background:#ffffff;border-radius:16px;padding:28px;border:1px solid #e2e8f0;">
|
||||
<div style="white-space:pre-wrap;font-size:14px;line-height:1.6;color:#334155;">{{ $bodyText }}</div>
|
||||
<body style="margin:0;background:#f8fafc;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:#0f172a;">
|
||||
<div style="max-width:600px;margin:0 auto;padding:48px 16px;">
|
||||
@if (! empty($logoUrl) || ! empty($companyName))
|
||||
<div style="text-align:center;padding:0 0 24px;">
|
||||
@if (! empty($logoUrl))
|
||||
<img src="{{ $logoUrl }}" alt="{{ $companyName }}" style="height:42px;max-height:42px;width:auto;">
|
||||
@else
|
||||
<div style="font-size:22px;font-weight:700;letter-spacing:-0.02em;color:#0f172a;">{{ $companyName }}</div>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
<div style="background:#ffffff;border-radius:16px;padding:40px;border:1px solid #e2e8f0;box-shadow:0 4px 6px -1px rgba(0,0,0,0.1);">
|
||||
<div style="white-space:pre-wrap;font-size:16px;line-height:1.7;color:#475569;">{{ $bodyText }}</div>
|
||||
@if (! empty($fromName))
|
||||
<p style="margin-top:24px;font-size:13px;color:#64748b;">— {{ $fromName }}</p>
|
||||
<p style="margin-top:24px;font-size:14px;color:#64748b;">— {{ $fromName }}</p>
|
||||
@endif
|
||||
</div>
|
||||
<p style="margin-top:16px;text-align:center;font-size:11px;color:#94a3b8;">Sent via Ladill Frontdesk</p>
|
||||
@if (! empty($companyName))
|
||||
<p style="margin-top:20px;text-align:center;font-size:13px;color:#94a3b8;">{{ $companyName }}</p>
|
||||
@endif
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body style="margin:0;background:#f8fafc;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:#0f172a;">
|
||||
<div style="max-width:600px;margin:0 auto;padding:48px 16px;">
|
||||
<div style="text-align:center;padding:0 0 24px;">
|
||||
@if (! empty($logoUrl))
|
||||
<img src="{{ $logoUrl }}" alt="{{ $companyName }}" style="height:42px;max-height:42px;width:auto;">
|
||||
@else
|
||||
<div style="font-size:22px;font-weight:700;letter-spacing:-0.02em;color:#0f172a;">{{ $companyName }}</div>
|
||||
@endif
|
||||
</div>
|
||||
<div style="background:#ffffff;border-radius:16px;padding:40px;border:1px solid #e2e8f0;box-shadow:0 4px 6px -1px rgba(0,0,0,0.1);">
|
||||
{!! $bodyHtml !!}
|
||||
</div>
|
||||
<p style="margin-top:20px;text-align:center;font-size:13px;color:#94a3b8;">{{ $companyName }}</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,6 @@
|
||||
<x-app-layout title="Settings">
|
||||
<x-settings.page title="Organization settings">
|
||||
<form method="POST" action="{{ route('qms.settings.update') }}" class="space-y-6">
|
||||
<form method="POST" action="{{ route('qms.settings.update') }}" enctype="multipart/form-data" class="space-y-6">
|
||||
@csrf @method('PUT')
|
||||
|
||||
<x-settings.card title="Organization" description="Name, timezone, appointment mode, and notification preferences.">
|
||||
@@ -33,6 +33,23 @@
|
||||
<input type="checkbox" name="notifications_enabled" value="1" @checked($organization->settings['notifications_enabled'] ?? true) @disabled(! $canManage)>
|
||||
Enable SMS/email queue notifications
|
||||
</label>
|
||||
@if ($canManage)
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Company logo</label>
|
||||
<p class="mt-1 text-xs text-slate-500">PNG, JPG, WebP, or SVG up to 2 MB. Shown in queue notification emails.</p>
|
||||
@if (\App\Support\OrganizationBranding::hasCustomLogo($organization))
|
||||
<img src="{{ \App\Support\OrganizationBranding::logoUrl($organization) }}"
|
||||
alt="{{ $organization->name }}"
|
||||
class="mt-3 h-12 w-auto max-w-xs rounded-lg border border-slate-200 bg-white object-contain p-2">
|
||||
<label class="mt-3 flex items-center gap-2 text-sm text-slate-600">
|
||||
<input type="checkbox" name="remove_logo" value="1" @checked(old('remove_logo'))>
|
||||
Remove custom logo
|
||||
</label>
|
||||
@endif
|
||||
<input type="file" name="logo" accept="image/png,image/jpeg,image/webp,image/svg+xml"
|
||||
class="mt-3 block w-full text-sm text-slate-600 file:mr-3 file:rounded-lg file:border-0 file:bg-indigo-50 file:px-3 file:py-2 file:text-sm file:font-medium file:text-indigo-700">
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</x-settings.card>
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Mail\ContactMessageMail;
|
||||
use App\Models\Branch;
|
||||
use App\Models\ServiceQueue;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Services\Qms\OrganizationResolver;
|
||||
use App\Services\Qms\QueueNotificationService;
|
||||
use App\Support\OrganizationBranding;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QueueEmailBrandingTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $owner;
|
||||
|
||||
protected \App\Models\Organization $organization;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
|
||||
$this->owner = User::create([
|
||||
'public_id' => 'queue-brand-001',
|
||||
'name' => 'Owner',
|
||||
'email' => 'owner@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$this->organization = app(OrganizationResolver::class)->completeOnboarding($this->owner, [
|
||||
'organization_name' => 'Acme Queue Co',
|
||||
'industry' => 'retail',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_org_admin_can_upload_organization_logo(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->put(route('qms.settings.update'), [
|
||||
'name' => 'Acme Queue Co',
|
||||
'timezone' => 'UTC',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'industry' => 'retail',
|
||||
'notifications_enabled' => '1',
|
||||
'logo' => UploadedFile::fake()->image('company-logo.png', 400, 120),
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$this->organization->refresh();
|
||||
$this->assertNotNull($this->organization->logo_path);
|
||||
Storage::disk('public')->assertExists($this->organization->logo_path);
|
||||
}
|
||||
|
||||
public function test_queue_notification_email_contains_company_branding_without_product_logo(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
Mail::fake();
|
||||
|
||||
$path = UploadedFile::fake()->image('company-logo.png', 400, 120)
|
||||
->store('queue/organizations/'.$this->organization->id, 'public');
|
||||
$this->organization->update(['logo_path' => $path, 'name' => 'Acme Queue Co']);
|
||||
|
||||
$branch = Branch::first();
|
||||
$queue = ServiceQueue::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $branch->id,
|
||||
'name' => 'Reception',
|
||||
'prefix' => 'A',
|
||||
'strategy' => 'fifo',
|
||||
'is_active' => true,
|
||||
'settings' => ['notifications_enabled' => true],
|
||||
]);
|
||||
|
||||
$ticket = Ticket::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $branch->id,
|
||||
'service_queue_id' => $queue->id,
|
||||
'ticket_number' => 'A001',
|
||||
'status' => 'waiting',
|
||||
'customer_email' => 'customer@example.com',
|
||||
'issued_at' => now(),
|
||||
]);
|
||||
|
||||
app(QueueNotificationService::class)->ticketIssued($ticket);
|
||||
|
||||
$logoUrl = OrganizationBranding::emailLogoUrl($this->organization->fresh());
|
||||
|
||||
Mail::assertSent(ContactMessageMail::class, function (ContactMessageMail $mail) use ($logoUrl) {
|
||||
$html = $mail->render();
|
||||
|
||||
return $mail->companyName === 'Acme Queue Co'
|
||||
&& $mail->logoUrl === $logoUrl
|
||||
&& str_contains($html, 'Acme Queue Co')
|
||||
&& str_contains($html, $logoUrl)
|
||||
&& ! str_contains($html, 'ladillqueue-logo')
|
||||
&& ! str_contains($html, 'Sent via Ladill');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_queue_notification_email_shows_company_name_when_no_logo(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$this->organization->update(['name' => 'Plain Name Org', 'logo_path' => null]);
|
||||
|
||||
$branch = Branch::first();
|
||||
$queue = ServiceQueue::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $branch->id,
|
||||
'name' => 'Reception',
|
||||
'prefix' => 'B',
|
||||
'strategy' => 'fifo',
|
||||
'is_active' => true,
|
||||
'settings' => ['notifications_enabled' => true],
|
||||
]);
|
||||
|
||||
$ticket = Ticket::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $branch->id,
|
||||
'service_queue_id' => $queue->id,
|
||||
'ticket_number' => 'B001',
|
||||
'status' => 'waiting',
|
||||
'customer_email' => 'customer@example.com',
|
||||
'issued_at' => now(),
|
||||
]);
|
||||
|
||||
app(QueueNotificationService::class)->ticketIssued($ticket);
|
||||
|
||||
Mail::assertSent(ContactMessageMail::class, function (ContactMessageMail $mail) {
|
||||
$html = $mail->render();
|
||||
|
||||
return $mail->companyName === 'Plain Name Org'
|
||||
&& $mail->logoUrl === null
|
||||
&& str_contains($html, 'Plain Name Org')
|
||||
&& ! str_contains($html, 'ladillqueue-logo')
|
||||
&& ! str_contains($html, 'Sent via Ladill');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user