Improve speaker invites and redesign roster add flow.
Deploy Ladill Events / deploy (push) Successful in 41s
Deploy Ladill Events / deploy (push) Successful in 41s
Surface specific send failures, allow resend, use ladl.link portal URLs, and replace stacked speaker forms with a single add-to-list pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -90,10 +90,13 @@ class SpeakerController extends Controller
|
||||
'email' => ['required', 'email', 'max:190'],
|
||||
]);
|
||||
|
||||
$sent = $this->invites->sendManualInvite($event, $event->user, $validated['email']);
|
||||
$owner = ladill_account() ?? $event->user;
|
||||
abort_unless($owner, 500);
|
||||
|
||||
if (! $sent) {
|
||||
return back()->with('error', 'Could not send invitation. Check the email address or whether this speaker was already invited from the programme.');
|
||||
$result = $this->invites->sendManualInvite($event, $owner, $validated['email']);
|
||||
|
||||
if (! $result['ok']) {
|
||||
return back()->with('error', $result['error']);
|
||||
}
|
||||
|
||||
return back()->with('success', 'Speaker invitation sent.');
|
||||
|
||||
@@ -19,7 +19,7 @@ class PlatformEmailClient
|
||||
|
||||
public function send(string $ownerPublicId, string $to, string $subject, string $html, ?string $text = null): bool
|
||||
{
|
||||
if ($this->token() === '') {
|
||||
if (! $this->isConfigured()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -54,4 +54,9 @@ class PlatformEmailClient
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return $this->token() !== '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,34 +30,28 @@ class EventSpeakerInviteService
|
||||
|
||||
public function canSendManualInvite(QrCode $event, array $speaker): bool
|
||||
{
|
||||
if (($speaker['email'] ?? '') === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->speakers->linkedProgramme($event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($speaker['invited_at'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ($speaker['invite_source'] ?? '') === self::SOURCE_MANUAL;
|
||||
return ($speaker['email'] ?? '') !== '';
|
||||
}
|
||||
|
||||
public function sendManualInvite(QrCode $event, User $owner, string $email): bool
|
||||
/** @return array{ok: true}|array{ok: false, error: string} */
|
||||
public function sendManualInvite(QrCode $event, User $owner, string $email): array
|
||||
{
|
||||
$email = strtolower(trim($email));
|
||||
$speakers = $this->rosterWithInviteState($event);
|
||||
$index = collect($speakers)->search(fn ($row) => strcasecmp((string) ($row['email'] ?? ''), $email) === 0);
|
||||
$event = $event->fresh() ?? $event;
|
||||
$speaker = $this->findSpeakerByEmail($event, $email);
|
||||
|
||||
if ($index === false) {
|
||||
return false;
|
||||
if ($speaker === null) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'That speaker is not on the saved roster. Click Save speakers first, then send the invitation.',
|
||||
];
|
||||
}
|
||||
|
||||
$speaker = $speakers[$index];
|
||||
if (! $this->canSendManualInvite($event, $speaker)) {
|
||||
return false;
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'Add a valid email address for this speaker before sending an invitation.',
|
||||
];
|
||||
}
|
||||
|
||||
return $this->deliverInvite($event, $owner, $speaker, self::SOURCE_MANUAL);
|
||||
@@ -103,7 +97,7 @@ class EventSpeakerInviteService
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->deliverInvite($event, $owner, $speaker, self::SOURCE_PROGRAMME)) {
|
||||
if ($this->deliverInvite($event, $owner, $speaker, self::SOURCE_PROGRAMME)['ok']) {
|
||||
$sent++;
|
||||
}
|
||||
}
|
||||
@@ -161,10 +155,7 @@ class EventSpeakerInviteService
|
||||
|
||||
public function portalUrl(QrCode $event, string $token): string
|
||||
{
|
||||
return route('qr.public.speaker.portal', [
|
||||
'shortCode' => $event->short_code,
|
||||
'token' => $token,
|
||||
]);
|
||||
return $event->publicPath('speaker/'.$token);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $session */
|
||||
@@ -222,12 +213,21 @@ class EventSpeakerInviteService
|
||||
return $assignments;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $speaker */
|
||||
private function deliverInvite(QrCode $event, User $owner, array $speaker, string $source): bool
|
||||
/** @return array{ok: true}|array{ok: false, error: string} */
|
||||
private function deliverInvite(QrCode $event, User $owner, array $speaker, string $source): array
|
||||
{
|
||||
$email = trim((string) ($speaker['email'] ?? ''));
|
||||
if ($email === '') {
|
||||
return false;
|
||||
return ['ok' => false, 'error' => 'Add a valid email address for this speaker before sending an invitation.'];
|
||||
}
|
||||
|
||||
$ownerRef = trim((string) ($owner->public_id ?? ''));
|
||||
if ($ownerRef === '') {
|
||||
return ['ok' => false, 'error' => 'Could not resolve the event owner account for sending email.'];
|
||||
}
|
||||
|
||||
if (! app(\App\Services\Billing\PlatformEmailClient::class)->isConfigured()) {
|
||||
return ['ok' => false, 'error' => 'Outbound email is not configured on this Events instance.'];
|
||||
}
|
||||
|
||||
$token = (string) ($speaker['invite_token'] ?? '');
|
||||
@@ -239,7 +239,7 @@ class EventSpeakerInviteService
|
||||
$portalUrl = $this->portalUrl($event, $token);
|
||||
|
||||
$sent = $this->email->sendSpeakerInvite(
|
||||
$owner->public_id,
|
||||
$ownerRef,
|
||||
$email,
|
||||
$eventName,
|
||||
$portalUrl,
|
||||
@@ -247,12 +247,27 @@ class EventSpeakerInviteService
|
||||
);
|
||||
|
||||
if (! $sent) {
|
||||
return false;
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'The invitation email could not be sent. Check your Ladill wallet balance and try again.',
|
||||
];
|
||||
}
|
||||
|
||||
$this->persistSpeakerInviteMeta($event, $email, $token, $source);
|
||||
|
||||
return true;
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
private function findSpeakerByEmail(QrCode $event, string $email): ?array
|
||||
{
|
||||
foreach ($this->rosterWithInviteState($event) as $speaker) {
|
||||
if (strcasecmp((string) ($speaker['email'] ?? ''), $email) === 0) {
|
||||
return $speaker;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function persistSpeakerInviteMeta(QrCode $event, string $email, string $token, string $source): void
|
||||
|
||||
@@ -33,46 +33,101 @@
|
||||
|
||||
<form method="POST" action="{{ route('speakers.update', $qrCode) }}" class="space-y-5 rounded-2xl border border-slate-200 bg-white p-6"
|
||||
x-data="{
|
||||
speakers: {{ Illuminate\Support\Js::from(array_values(old('speakers', $roster ?: [['name' => '', 'email' => '', 'role' => '', 'bio' => '']]))) }},
|
||||
addSpeaker() { this.speakers.push({ name: '', email: '', role: '', bio: '' }); },
|
||||
removeSpeaker(i) { this.speakers.splice(i, 1); if (this.speakers.length === 0) this.addSpeaker(); },
|
||||
draft: { name: '', email: '', role: '', bio: '' },
|
||||
draftError: '',
|
||||
speakers: {{ Illuminate\Support\Js::from(array_values(old('speakers', collect($roster)->filter(fn ($s) => trim($s['name'] ?? '') !== '')->values()->all()))) }},
|
||||
blankDraft() { return { name: '', email: '', role: '', bio: '' }; },
|
||||
addToRoster() {
|
||||
this.draftError = '';
|
||||
const name = this.draft.name.trim();
|
||||
const email = this.draft.email.trim();
|
||||
if (name === '') {
|
||||
this.draftError = 'Enter the speaker name.';
|
||||
return;
|
||||
}
|
||||
if (email === '' || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
this.draftError = 'Enter a valid email address.';
|
||||
return;
|
||||
}
|
||||
const duplicate = this.speakers.some(s => s.email.toLowerCase() === email.toLowerCase());
|
||||
if (duplicate) {
|
||||
this.draftError = 'This email is already on the roster.';
|
||||
return;
|
||||
}
|
||||
this.speakers.push({
|
||||
name,
|
||||
email,
|
||||
role: this.draft.role.trim(),
|
||||
bio: this.draft.bio.trim(),
|
||||
});
|
||||
this.draft = this.blankDraft();
|
||||
},
|
||||
removeSpeaker(i) { this.speakers.splice(i, 1); },
|
||||
}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold text-slate-900">Event speaker roster</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-500">Every speaker needs an email. They are available when building the programme schedule.</p>
|
||||
</div>
|
||||
<button type="button" @click="addSpeaker()" class="text-xs font-semibold text-indigo-600 hover:text-indigo-800">+ Add speaker</button>
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold text-slate-900">Event speaker roster</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-500">Add speakers one at a time. Every speaker needs an email for invitations and the programme schedule.</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<template x-for="(speaker, index) in speakers" :key="index">
|
||||
<div class="rounded-xl border border-slate-200 p-4 space-y-3">
|
||||
<div class="grid gap-3 sm:grid-cols-2">
|
||||
<input type="text" :name="'speakers[' + index + '][name]'" x-model="speaker.name" placeholder="Name *" required
|
||||
class="rounded-xl border border-slate-200 px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30">
|
||||
<input type="email" :name="'speakers[' + index + '][email]'" x-model="speaker.email" placeholder="Email *" required
|
||||
class="rounded-xl border border-slate-200 px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30">
|
||||
</div>
|
||||
<input type="text" :name="'speakers[' + index + '][role]'" x-model="speaker.role" placeholder="Role / session (optional)"
|
||||
class="w-full rounded-xl border border-slate-200 px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30">
|
||||
<textarea :name="'speakers[' + index + '][bio]'" x-model="speaker.bio" rows="2" placeholder="Short bio (optional)"
|
||||
class="w-full rounded-xl border border-slate-200 px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30"></textarea>
|
||||
<button type="button" @click="removeSpeaker(index)" class="text-xs font-medium text-red-600 hover:text-red-700">Remove</button>
|
||||
</div>
|
||||
{{-- Single add form --}}
|
||||
<div class="rounded-xl border border-dashed border-slate-200 bg-slate-50/60 p-4 space-y-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Add speaker</p>
|
||||
<div class="grid gap-3 sm:grid-cols-2">
|
||||
<input type="text" x-model="draft.name" placeholder="Name *" autocomplete="off"
|
||||
class="rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30"
|
||||
@keydown.enter.prevent="addToRoster()">
|
||||
<input type="email" x-model="draft.email" placeholder="Email *" autocomplete="off"
|
||||
class="rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30"
|
||||
@keydown.enter.prevent="addToRoster()">
|
||||
</div>
|
||||
<input type="text" x-model="draft.role" placeholder="Role / session (optional)" autocomplete="off"
|
||||
class="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30">
|
||||
<textarea x-model="draft.bio" rows="2" placeholder="Short bio (optional)"
|
||||
class="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm focus:border-indigo-400 focus:outline-none focus:ring-1 focus:ring-indigo-400/30"></textarea>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<p x-show="draftError" x-text="draftError" class="text-xs font-medium text-red-600"></p>
|
||||
<button type="button" @click="addToRoster()" class="ml-auto btn-secondary btn-secondary-sm">Add to roster</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Roster list --}}
|
||||
<div>
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">
|
||||
On roster (<span x-text="speakers.length"></span>)
|
||||
</p>
|
||||
<template x-if="speakers.length === 0">
|
||||
<p class="mt-3 rounded-xl border border-dashed border-slate-200 px-4 py-6 text-center text-sm text-slate-400">No speakers yet. Use the form above to add your first speaker.</p>
|
||||
</template>
|
||||
<div class="mt-3 space-y-2" x-show="speakers.length > 0">
|
||||
<template x-for="(speaker, index) in speakers" :key="index">
|
||||
<div class="flex items-start justify-between gap-3 rounded-xl border border-slate-200 px-4 py-3">
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="font-semibold text-slate-900" x-text="speaker.name"></p>
|
||||
<p class="text-xs text-slate-500" x-text="speaker.email"></p>
|
||||
<p x-show="speaker.role" class="mt-0.5 text-xs text-slate-600" x-text="speaker.role"></p>
|
||||
<p x-show="speaker.bio" class="mt-1 text-xs text-slate-500 line-clamp-2" x-text="speaker.bio"></p>
|
||||
<input type="hidden" :name="'speakers[' + index + '][name]'" :value="speaker.name">
|
||||
<input type="hidden" :name="'speakers[' + index + '][email]'" :value="speaker.email">
|
||||
<input type="hidden" :name="'speakers[' + index + '][role]'" :value="speaker.role">
|
||||
<input type="hidden" :name="'speakers[' + index + '][bio]'" :value="speaker.bio">
|
||||
</div>
|
||||
<button type="button" @click="removeSpeaker(index)" class="shrink-0 text-xs font-medium text-red-600 hover:text-red-700">Remove</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-primary w-full">Save speakers</button>
|
||||
<p class="text-center text-xs text-slate-500">Save before using Send invitation below.</p>
|
||||
</form>
|
||||
|
||||
@if(count($roster))
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-6">
|
||||
<h2 class="text-sm font-semibold text-slate-900">Invitations</h2>
|
||||
<p class="mt-0.5 text-xs text-slate-500">Speakers assigned on the programme are emailed when the programme is saved. Send manually for events without a programme or speakers not yet on the schedule.</p>
|
||||
<p class="mt-0.5 text-xs text-slate-500">Save your speaker roster first, then send invitations. Programme hosts are emailed automatically when you save the programme.</p>
|
||||
<div class="mt-4 divide-y divide-slate-100">
|
||||
@foreach($roster as $speaker)
|
||||
@php
|
||||
@@ -95,10 +150,10 @@
|
||||
<form method="POST" action="{{ route('speakers.invite', $qrCode) }}">
|
||||
@csrf
|
||||
<input type="hidden" name="email" value="{{ $email }}">
|
||||
<button type="submit" class="btn-secondary btn-secondary-sm">Send invitation</button>
|
||||
<button type="submit" class="btn-secondary btn-secondary-sm">{{ $invited ? 'Resend invitation' : 'Send invitation' }}</button>
|
||||
</form>
|
||||
@elseif($invited && ($speaker['invite_source'] ?? '') === 'programme')
|
||||
<span class="text-[11px] text-slate-400">Auto-invited from programme</span>
|
||||
<span class="text-[11px] text-slate-400">Invited via programme</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -226,4 +226,73 @@ class EventSpeakerInviteTest extends TestCase
|
||||
])
|
||||
->assertSessionHasErrors('speakers.0.email');
|
||||
}
|
||||
|
||||
public function test_manual_speaker_invite_reports_when_email_not_configured(): void
|
||||
{
|
||||
config(['smtp.platform_api_key' => '']);
|
||||
|
||||
$owner = User::factory()->create(['public_id' => 'usr_sp_no_smtp']);
|
||||
|
||||
$event = QrCode::create([
|
||||
'user_id' => $owner->id,
|
||||
'short_code' => 'evt-sp-no-smtp',
|
||||
'type' => QrCode::TYPE_EVENT,
|
||||
'label' => 'No SMTP event',
|
||||
'payload' => [
|
||||
'content' => [
|
||||
'name' => 'No SMTP event',
|
||||
'speakers' => [[
|
||||
'name' => 'Alex Host',
|
||||
'email' => 'alex@example.com',
|
||||
'role' => 'Panelist',
|
||||
'bio' => '',
|
||||
]],
|
||||
],
|
||||
'style' => [],
|
||||
],
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($owner)
|
||||
->from(route('speakers.show', $event))
|
||||
->post(route('speakers.invite', $event), ['email' => 'alex@example.com'])
|
||||
->assertRedirect(route('speakers.show', $event))
|
||||
->assertSessionHas('error');
|
||||
}
|
||||
|
||||
public function test_manual_speaker_invite_can_be_resent_after_programme_invite(): void
|
||||
{
|
||||
$owner = User::factory()->create(['public_id' => 'usr_sp_resend']);
|
||||
|
||||
$event = QrCode::create([
|
||||
'user_id' => $owner->id,
|
||||
'short_code' => 'evt-sp-resend',
|
||||
'type' => QrCode::TYPE_EVENT,
|
||||
'label' => 'Resend event',
|
||||
'payload' => [
|
||||
'content' => [
|
||||
'name' => 'Resend event',
|
||||
'speakers' => [[
|
||||
'name' => 'Pat Speaker',
|
||||
'email' => 'pat@example.com',
|
||||
'role' => 'Host',
|
||||
'bio' => '',
|
||||
'invite_token' => 'existing-token',
|
||||
'invited_at' => now()->toIso8601String(),
|
||||
'invite_source' => EventSpeakerInviteService::SOURCE_PROGRAMME,
|
||||
]],
|
||||
],
|
||||
'style' => [],
|
||||
],
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($owner)
|
||||
->from(route('speakers.show', $event))
|
||||
->post(route('speakers.invite', $event), ['email' => 'pat@example.com'])
|
||||
->assertRedirect(route('speakers.show', $event))
|
||||
->assertSessionHas('success');
|
||||
|
||||
Http::assertSent(fn ($request) => $request['to'] === 'pat@example.com');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user