feat(api): organisation email branding and shared mail layout
- Add email branding columns to organisations table (logo, color, reply-to, sender name, footer)
- Create MailBrandingService for resolving per-org branding with defaults
- Create CrewliMailable abstract base class with branded from/reply-to
- Create shared Blade layout (mail.layouts.crewli) with inline CSS
- Refactor Registration*Mail and InvitationMail to extend CrewliMailable
- Add config/crewli.php for platform-wide defaults (portal_url, app_url, logo)
- Add dev-only /mail-preview/{type} route for browser email previewing
- Update Organisation model, resource, and form requests with branding fields
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,11 @@ final class StoreOrganisationRequest extends FormRequest
|
||||
'slug' => ['required', 'string', 'max:255', 'unique:organisations,slug', 'regex:/^[a-z0-9-]+$/'],
|
||||
'billing_status' => ['sometimes', 'string', 'in:trial,active,suspended,cancelled'],
|
||||
'settings' => ['sometimes', 'array'],
|
||||
'email_logo_url' => ['nullable', 'url', 'max:500'],
|
||||
'email_primary_color' => ['nullable', 'string', 'regex:/^#[0-9A-Fa-f]{6}$/'],
|
||||
'email_reply_to' => ['nullable', 'email'],
|
||||
'email_sender_name' => ['nullable', 'string', 'max:100'],
|
||||
'email_footer_text' => ['nullable', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ final class UpdateOrganisationRequest extends FormRequest
|
||||
],
|
||||
'billing_status' => ['sometimes', 'string', 'in:active,trial,suspended'],
|
||||
'settings' => ['sometimes', 'array'],
|
||||
'email_logo_url' => ['nullable', 'url', 'max:500'],
|
||||
'email_primary_color' => ['nullable', 'string', 'regex:/^#[0-9A-Fa-f]{6}$/'],
|
||||
'email_reply_to' => ['nullable', 'email'],
|
||||
'email_sender_name' => ['nullable', 'string', 'max:100'],
|
||||
'email_footer_text' => ['nullable', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@ final class OrganisationResource extends JsonResource
|
||||
'slug' => $this->slug,
|
||||
'billing_status' => $this->billing_status,
|
||||
'settings' => $this->settings,
|
||||
'email_logo_url' => $this->email_logo_url,
|
||||
'email_primary_color' => $this->email_primary_color,
|
||||
'email_reply_to' => $this->email_reply_to,
|
||||
'email_sender_name' => $this->email_sender_name,
|
||||
'email_footer_text' => $this->email_footer_text,
|
||||
'created_at' => $this->created_at->toIso8601String(),
|
||||
'updated_at' => $this->updated_at->toIso8601String(),
|
||||
];
|
||||
|
||||
41
api/app/Mail/CrewliMailable.php
Normal file
41
api/app/Mail/CrewliMailable.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Organisation;
|
||||
use App\Services\MailBrandingService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
abstract class CrewliMailable extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
protected Organisation $organisation;
|
||||
|
||||
public function __construct(Organisation $organisation)
|
||||
{
|
||||
$this->organisation = $organisation;
|
||||
}
|
||||
|
||||
protected function buildBranding(): static
|
||||
{
|
||||
$branding = app(MailBrandingService::class)->getBranding($this->organisation);
|
||||
|
||||
$this->from(
|
||||
config('mail.from.address'),
|
||||
$branding['sender_name']
|
||||
);
|
||||
|
||||
if ($branding['reply_to']) {
|
||||
$this->replyTo($branding['reply_to']);
|
||||
}
|
||||
|
||||
return $this->with('branding', $branding);
|
||||
}
|
||||
}
|
||||
@@ -5,21 +5,18 @@ declare(strict_types=1);
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\UserInvitation;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
final class InvitationMail extends Mailable implements ShouldQueue
|
||||
final class InvitationMail extends CrewliMailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
public UserInvitation $invitation;
|
||||
|
||||
public function __construct(
|
||||
public readonly UserInvitation $invitation,
|
||||
) {}
|
||||
public function __construct(UserInvitation $invitation)
|
||||
{
|
||||
parent::__construct($invitation->organisation);
|
||||
$this->invitation = $invitation;
|
||||
}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -30,11 +27,12 @@ final class InvitationMail extends Mailable implements ShouldQueue
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
$this->buildBranding();
|
||||
|
||||
return new Content(
|
||||
markdown: 'emails.invitation',
|
||||
view: 'mail.invitation',
|
||||
with: [
|
||||
'acceptUrl' => config('app.frontend_app_url') . '/invitations/' . $this->invitation->token . '/accept',
|
||||
'organisationName' => $this->invitation->organisation->name,
|
||||
'acceptUrl' => config('crewli.app_url') . '/invitations/' . $this->invitation->token . '/accept',
|
||||
'inviterName' => $this->invitation->invitedBy?->name ?? 'Een beheerder',
|
||||
'role' => $this->invitation->role,
|
||||
'expiresAt' => $this->invitation->expires_at,
|
||||
|
||||
@@ -6,22 +6,20 @@ namespace App\Mail;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\Person;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
final class RegistrationApprovedMail extends Mailable implements ShouldQueue
|
||||
final class RegistrationApprovedMail extends CrewliMailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
public Person $person;
|
||||
public Event $event;
|
||||
|
||||
public function __construct(
|
||||
public readonly Person $person,
|
||||
public readonly Event $event,
|
||||
) {}
|
||||
public function __construct(Person $person, Event $event)
|
||||
{
|
||||
parent::__construct($event->organisation);
|
||||
$this->person = $person;
|
||||
$this->event = $event;
|
||||
}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -32,12 +30,14 @@ final class RegistrationApprovedMail extends Mailable implements ShouldQueue
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
$this->buildBranding();
|
||||
|
||||
return new Content(
|
||||
markdown: 'emails.registration-approved',
|
||||
view: 'mail.registration-approved',
|
||||
with: [
|
||||
'personName' => $this->person->first_name,
|
||||
'eventName' => $this->event->name,
|
||||
'portalUrl' => config('app.frontend_portal_url'),
|
||||
'person' => $this->person,
|
||||
'event' => $this->event,
|
||||
'portalUrl' => config('crewli.portal_url'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,22 +6,20 @@ namespace App\Mail;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\Person;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
final class RegistrationConfirmationMail extends Mailable implements ShouldQueue
|
||||
final class RegistrationConfirmationMail extends CrewliMailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
public Person $person;
|
||||
public Event $event;
|
||||
|
||||
public function __construct(
|
||||
public readonly Person $person,
|
||||
public readonly Event $event,
|
||||
) {}
|
||||
public function __construct(Person $person, Event $event)
|
||||
{
|
||||
parent::__construct($event->organisation);
|
||||
$this->person = $person;
|
||||
$this->event = $event;
|
||||
}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -32,14 +30,14 @@ final class RegistrationConfirmationMail extends Mailable implements ShouldQueue
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
$this->buildBranding();
|
||||
|
||||
return new Content(
|
||||
markdown: 'emails.registration-confirmation',
|
||||
view: 'mail.registration-confirmation',
|
||||
with: [
|
||||
'personName' => $this->person->first_name,
|
||||
'eventName' => $this->event->name,
|
||||
'startDate' => $this->event->start_date->format('d-m-Y'),
|
||||
'endDate' => $this->event->end_date->format('d-m-Y'),
|
||||
'portalUrl' => config('app.frontend_portal_url'),
|
||||
'person' => $this->person,
|
||||
'event' => $this->event,
|
||||
'portalUrl' => config('crewli.portal_url'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,23 +6,22 @@ namespace App\Mail;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\Person;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
final class RegistrationRejectedMail extends Mailable implements ShouldQueue
|
||||
final class RegistrationRejectedMail extends CrewliMailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
public Person $person;
|
||||
public Event $event;
|
||||
public ?string $reason;
|
||||
|
||||
public function __construct(
|
||||
public readonly Person $person,
|
||||
public readonly Event $event,
|
||||
public readonly ?string $reason = null,
|
||||
) {}
|
||||
public function __construct(Person $person, Event $event, ?string $reason = null)
|
||||
{
|
||||
parent::__construct($event->organisation);
|
||||
$this->person = $person;
|
||||
$this->event = $event;
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -33,11 +32,13 @@ final class RegistrationRejectedMail extends Mailable implements ShouldQueue
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
$this->buildBranding();
|
||||
|
||||
return new Content(
|
||||
markdown: 'emails.registration-rejected',
|
||||
view: 'mail.registration-rejected',
|
||||
with: [
|
||||
'personName' => $this->person->first_name,
|
||||
'eventName' => $this->event->name,
|
||||
'person' => $this->person,
|
||||
'event' => $this->event,
|
||||
'reason' => $this->reason,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -22,6 +22,11 @@ final class Organisation extends Model
|
||||
'slug',
|
||||
'billing_status',
|
||||
'settings',
|
||||
'email_logo_url',
|
||||
'email_primary_color',
|
||||
'email_reply_to',
|
||||
'email_sender_name',
|
||||
'email_footer_text',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
|
||||
25
api/app/Services/MailBrandingService.php
Normal file
25
api/app/Services/MailBrandingService.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Organisation;
|
||||
|
||||
final class MailBrandingService
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getBranding(Organisation $organisation): array
|
||||
{
|
||||
return [
|
||||
'organisation_name' => $organisation->name,
|
||||
'logo_url' => $organisation->email_logo_url ?? config('crewli.default_logo_url'),
|
||||
'primary_color' => $organisation->email_primary_color ?? '#6366f1',
|
||||
'reply_to' => $organisation->email_reply_to,
|
||||
'sender_name' => $organisation->email_sender_name ?? $organisation->name,
|
||||
'footer_text' => $organisation->email_footer_text,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user