From 5bf0d1147f4ff2157fae3c48a46d71826634df1b Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Tue, 17 Dec 2024 23:31:56 +0800 Subject: [PATCH] feat: send email after generating --- src/app/api/email/route.ts | 2 +- src/app/event/components/devfest24-cert.tsx | 3 +- src/app/event/components/event-landing.tsx | 32 +++++++++++++++++---- src/components/devfest24-email.tsx | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/app/api/email/route.ts b/src/app/api/email/route.ts index 9be9870..cdce536 100644 --- a/src/app/api/email/route.ts +++ b/src/app/api/email/route.ts @@ -12,7 +12,7 @@ export async function POST(request: NextRequest) { await handleSendEmail({ to: email, - subject: "Certificate: Google DevFest 2024", + subject: "Certificate: DevFest Bacolod 2024", html: htmlContent, }); diff --git a/src/app/event/components/devfest24-cert.tsx b/src/app/event/components/devfest24-cert.tsx index 58fba15..5cb4a8d 100644 --- a/src/app/event/components/devfest24-cert.tsx +++ b/src/app/event/components/devfest24-cert.tsx @@ -65,14 +65,13 @@ export function DevfestCertificate() { link.download = `certificate_${certId}.png`; link.href = dataUrl; link.click(); - toast.success("Image Saved!"); setImgLoading(false); }) .catch((err) => { toast.error(err.message); setImgLoading(false); }), - { loading: "Saving image...", success: "Saved image!", error: "Error!" }, + { loading: "Saving image...", success: "Image saved!", error: "Error!" }, ); }, [cardRef, certId]); diff --git a/src/app/event/components/event-landing.tsx b/src/app/event/components/event-landing.tsx index 518e59c..bfce5a4 100644 --- a/src/app/event/components/event-landing.tsx +++ b/src/app/event/components/event-landing.tsx @@ -79,13 +79,31 @@ export default function EventLanding({ try { const querySnapshot = await getDocs(q); let message = "⚠️ Certificate Not Found"; - querySnapshot.forEach((doc) => { - if (doc.data().email) { + + for (const doc of querySnapshot.docs) { + const data = doc.data(); + + if (doc.exists()) { + await fetch("/api/email", { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify({ + id: doc.id, + email: data.email, + firstName: data.firstName, + lastName: data.lastName, + }), + }); + push(`/event/${eventCode}/${values.type}?id=${doc.id}`); message = "✅ Certificate found!"; - return; + break; } - }); + } + toast(message); setLoading(false); } catch (err: any) { @@ -144,7 +162,11 @@ export default function EventLanding({ - + Badge diff --git a/src/components/devfest24-email.tsx b/src/components/devfest24-email.tsx index 3135960..4e3255f 100644 --- a/src/components/devfest24-email.tsx +++ b/src/components/devfest24-email.tsx @@ -69,7 +69,7 @@ export const CertificateEmail = ({