Brand patient emails with organization logo.
Deploy Ladill Care / deploy (push) Successful in 54s

Wrap Bird patient mail in a customer-branded layout and show the logo preview in settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-12 20:07:34 +00:00
co-authored by Cursor
parent 6c14c3802c
commit 6c8a0e7e9f
5 changed files with 176 additions and 4 deletions
@@ -10,6 +10,7 @@ use App\Services\Care\OrganizationResolver;
use App\Services\Messaging\CustomerEmailClient;
use App\Services\Messaging\CustomerSmsClient;
use App\Services\Messaging\MessagingCredentialsService;
use App\Support\OrganizationBranding;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -46,7 +47,8 @@ class PatientMessageController extends Controller
]);
$owner = $this->ownerRef($request);
$html = nl2br(e($data['body']));
$organization = $this->organization($request);
$html = OrganizationBranding::wrapEmailHtml(nl2br(e($data['body'])), $organization);
$sent = $email->send(
$apiKey,
(string) $credential->bird_from_email,
+23
View File
@@ -47,4 +47,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();
}
}
+11 -3
View File
@@ -30,11 +30,19 @@
@if ($canManage)
<div>
<label class="block text-sm font-medium text-slate-700">Logo</label>
<input type="file" name="logo" accept="image/png,image/jpeg,image/webp,image/svg+xml" class="mt-2 block w-full text-sm">
<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&nbsp;MB. Shown in patient emails.</p>
@if (\App\Support\OrganizationBranding::hasCustomLogo($organization))
<label class="mt-2 flex items-center gap-2 text-sm"><input type="checkbox" name="remove_logo" value="1"> Remove current logo</label>
<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-teal-50 file:px-3 file:py-2 file:text-sm file:font-medium file:text-teal-700">
</div>
@endif
</div>
@@ -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>
+117
View File
@@ -0,0 +1,117 @@
<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\Member;
use App\Models\MessagingCredential;
use App\Models\Organization;
use App\Models\Patient;
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 CareEmailBrandingTest extends TestCase
{
use RefreshDatabase;
protected User $user;
protected Organization $organization;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
$this->user = User::create([
'public_id' => 'test-user-brand-001',
'name' => 'Test User',
'email' => 'brand@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->user->public_id,
'name' => 'Test Clinic',
'slug' => 'test-clinic-brand',
'timezone' => 'UTC',
'settings' => ['onboarded' => true, 'facility_type' => 'clinic'],
]);
Member::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'user_ref' => $this->user->public_id,
'role' => 'hospital_admin',
]);
Branch::create([
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'name' => 'Main',
'is_active' => true,
]);
}
public function test_patient_email_contains_organization_logo(): void
{
Storage::fake('public');
$path = UploadedFile::fake()->image('clinic-logo.png', 400, 120)
->store('care/organizations/'.$this->organization->id, 'public');
$this->organization->update(['logo_path' => $path, 'name' => 'Test Clinic']);
$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' => 'clinic@example.test',
'bird_from_name' => 'Clinic',
'bird_status' => MessagingCredential::STATUS_VALID,
'bird_validated_at' => now(),
]);
Http::fake([
'*/api/smtp/send' => Http::response(['success' => true, 'message_id' => 'x']),
]);
$patient = Patient::create([
'uuid' => (string) \Illuminate\Support\Str::uuid(),
'owner_ref' => $this->user->public_id,
'organization_id' => $this->organization->id,
'branch_id' => Branch::first()->id,
'patient_number' => 'LC-BRAND-00001',
'first_name' => 'Ada',
'last_name' => 'Lovelace',
'email' => 'ada@example.com',
]);
$this->actingAs($this->user)
->post(route('care.patients.email', $patient), [
'subject' => 'Appointment reminder',
'body' => 'Please arrive 10 minutes early.',
])
->assertRedirect()
->assertSessionHas('success');
$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, 'Test Clinic')
&& str_contains($html, $logoUrl)
&& ! str_contains($html, 'ladillcare-logo')
&& ! str_contains($html, 'Sent via Ladill');
});
}
}