diff --git a/src/routes/private/api/google/gmail/+server.ts b/src/routes/private/api/google/gmail/+server.ts index eea6c9b..a885ec7 100644 --- a/src/routes/private/api/google/gmail/+server.ts +++ b/src/routes/private/api/google/gmail/+server.ts @@ -16,6 +16,16 @@ interface EmailResult { error?: string; } +/** + * Replaces template variables in a string with participant data + * Currently supports {name} and {surname} placeholders + */ +function replaceTemplateVariables(template: string, participant: Participant): string { + return template + .replace(/{name}/gi, participant.name || '') + .replace(/{surname}/gi, participant.surname || ''); +} + async function generateQRCode(participantId: string): Promise { const qrCodeBase64 = await QRCode.toDataURL(participantId, { type: 'image/png', @@ -38,11 +48,15 @@ async function sendEmailToParticipant( try { const qrCodeBase64Data = await generateQRCode(participant.id); + // Replace template variables in subject and body + const personalizedSubject = replaceTemplateVariables(subject, participant); + const personalizedText = replaceTemplateVariables(text, participant); + // Send email with QR code await sendGmail(refreshToken, { to: participant.email, - subject: subject, - text: text, + subject: personalizedSubject, + text: personalizedText, qr_code: qrCodeBase64Data }); diff --git a/src/routes/private/events/event/new/components/EmailSettingsStep.svelte b/src/routes/private/events/event/new/components/EmailSettingsStep.svelte index 3daf494..e946b81 100644 --- a/src/routes/private/events/event/new/components/EmailSettingsStep.svelte +++ b/src/routes/private/events/event/new/components/EmailSettingsStep.svelte @@ -6,38 +6,69 @@ }; errors: Record; }>(); + + const templateVariables = [ + { name: '{name}', description: "Participant's first name" }, + { name: '{surname}', description: "Participant's last name" } + ]; + + const subjectTemplatesDetected = $derived( + templateVariables.filter((v) => emailData.subject && emailData.subject.includes(v.name)) + ); + const bodyTemplatesDetected = $derived( + templateVariables.filter((v) => emailData.body && emailData.body.includes(v.name)) + );
-
-
+ +
+

Tip:

+

+ Use {name} and + {surname} to personalize + your message. Works for both subject and body. (e.g., "Hello {name}, welcome to our event!") +

+
diff --git a/src/routes/private/events/queries.ts b/src/routes/private/events/queries.ts index c741adc..7cd2e09 100644 --- a/src/routes/private/events/queries.ts +++ b/src/routes/private/events/queries.ts @@ -16,8 +16,6 @@ export interface Event { export async function getEvents(supabase: SupabaseClient, searchTerm: string = '') { try { const searchPattern = searchTerm.trim() ? `%${searchTerm}%` : null; - - console.log('Actually fetching!'); // Build regular events query let regularQuery = supabase