Brand host alert emails with the organization logo.
Deploy Ladill Frontdesk / deploy (push) Successful in 51s
Deploy Ladill Frontdesk / deploy (push) Successful in 51s
Wrap Frontdesk Bird host notifications in the customer-branded email layout. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Notifications\FrontdeskAlertNotification;
|
|||||||
use App\Services\Messaging\CustomerEmailClient;
|
use App\Services\Messaging\CustomerEmailClient;
|
||||||
use App\Services\Messaging\CustomerSmsClient;
|
use App\Services\Messaging\CustomerSmsClient;
|
||||||
use App\Services\Messaging\MessagingCredentialsService;
|
use App\Services\Messaging\MessagingCredentialsService;
|
||||||
|
use App\Support\OrganizationBranding;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class NotificationDispatcher
|
class NotificationDispatcher
|
||||||
@@ -218,7 +219,7 @@ class NotificationDispatcher
|
|||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$html = nl2br(e($message));
|
$html = OrganizationBranding::wrapEmailHtml(nl2br(e($message)), $organization);
|
||||||
$sent = $this->customerEmail->send(
|
$sent = $this->customerEmail->send(
|
||||||
$apiKey,
|
$apiKey,
|
||||||
(string) $credential->bird_from_email,
|
(string) $credential->bird_from_email,
|
||||||
|
|||||||
@@ -47,4 +47,27 @@ class OrganizationBranding
|
|||||||
Storage::disk('public')->delete($organization->logo_path);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Http\Middleware\EnsurePlatformSession;
|
||||||
|
use App\Models\Branch;
|
||||||
|
use App\Models\Host;
|
||||||
|
use App\Models\Member;
|
||||||
|
use App\Models\MessagingCredential;
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\OrganizationBranding;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class FrontdeskEmailBrandingTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected User $user;
|
||||||
|
|
||||||
|
protected Organization $organization;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||||
|
config(['billing.api_url' => 'https://billing.test']);
|
||||||
|
|
||||||
|
$this->user = User::create([
|
||||||
|
'public_id' => 'fd-brand-001',
|
||||||
|
'name' => 'Test User',
|
||||||
|
'email' => 'frontdesk@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->organization = Organization::create([
|
||||||
|
'owner_ref' => $this->user->public_id,
|
||||||
|
'name' => 'Frontdesk HQ',
|
||||||
|
'slug' => 'frontdesk-hq',
|
||||||
|
'timezone' => 'UTC',
|
||||||
|
'settings' => [
|
||||||
|
'onboarded' => true,
|
||||||
|
'plan' => 'pro',
|
||||||
|
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
||||||
|
'badge_expiry_hours' => 8,
|
||||||
|
'kiosk_reset_seconds' => 120,
|
||||||
|
'notification_channels' => ['email'],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
Member::create([
|
||||||
|
'owner_ref' => $this->user->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'user_ref' => $this->user->public_id,
|
||||||
|
'role' => 'org_admin',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Branch::create([
|
||||||
|
'owner_ref' => $this->user->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'name' => 'Main Office',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_host_alert_email_contains_organization_branding(): void
|
||||||
|
{
|
||||||
|
Storage::fake('public');
|
||||||
|
|
||||||
|
$path = UploadedFile::fake()->image('hq-logo.png', 400, 120)
|
||||||
|
->store('frontdesk/organizations/'.$this->organization->id, 'public');
|
||||||
|
$this->organization->update(['logo_path' => $path, 'name' => 'Frontdesk HQ']);
|
||||||
|
|
||||||
|
$plain = 'lsk_live_'.str_repeat('d', 32);
|
||||||
|
MessagingCredential::create([
|
||||||
|
'owner_ref' => $this->user->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'bird_api_key_encrypted' => Crypt::encryptString($plain),
|
||||||
|
'bird_api_key_prefix' => substr($plain, 0, 16),
|
||||||
|
'bird_from_email' => 'frontdesk@example.test',
|
||||||
|
'bird_from_name' => 'Frontdesk',
|
||||||
|
'bird_status' => MessagingCredential::STATUS_VALID,
|
||||||
|
'bird_validated_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'billing.test/*' => Http::response(['affordable' => true, 'ok' => true]),
|
||||||
|
'*/api/smtp/send' => Http::response(['success' => true, 'message_id' => 'x']),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$host = Host::create([
|
||||||
|
'owner_ref' => $this->user->public_id,
|
||||||
|
'organization_id' => $this->organization->id,
|
||||||
|
'name' => 'Jane Host',
|
||||||
|
'email' => 'jane@example.com',
|
||||||
|
'is_available' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($this->user)
|
||||||
|
->post(route('frontdesk.visits.store'), [
|
||||||
|
'full_name' => 'John Visitor',
|
||||||
|
'host_id' => $host->id,
|
||||||
|
'visitor_type' => 'visitor',
|
||||||
|
'policies_accepted' => '1',
|
||||||
|
])
|
||||||
|
->assertRedirect();
|
||||||
|
|
||||||
|
$logoUrl = OrganizationBranding::emailLogoUrl($this->organization->fresh());
|
||||||
|
|
||||||
|
Http::assertSent(function ($request) use ($logoUrl) {
|
||||||
|
$html = $request['html'] ?? '';
|
||||||
|
|
||||||
|
return str_contains($request->url(), '/api/smtp/send')
|
||||||
|
&& str_contains($html, 'Frontdesk HQ')
|
||||||
|
&& str_contains($html, $logoUrl)
|
||||||
|
&& ! str_contains($html, 'ladillfrontdesk-logo')
|
||||||
|
&& ! str_contains($html, 'Sent via Ladill');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user