Skip to content

Commit

Permalink
feat: send email after generating
Browse files Browse the repository at this point in the history
  • Loading branch information
joshxfi committed Dec 17, 2024
1 parent 89e0fee commit 5bf0d11
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app/api/email/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
3 changes: 1 addition & 2 deletions src/app/event/components/devfest24-cert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
32 changes: 27 additions & 5 deletions src/app/event/components/event-landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -144,7 +162,11 @@ export default function EventLanding({
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem className="cursor-pointer" value="badge">
<SelectItem
disabled
className="cursor-pointer"
value="badge"
>
Badge
</SelectItem>
<SelectItem className="cursor-pointer" value="cert">
Expand Down
2 changes: 1 addition & 1 deletion src/components/devfest24-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const CertificateEmail = ({
<Section className="mb-8 text-center">
<Button
className="rounded-full bg-blue-600 px-6 py-3 text-center text-base font-semibold text-white no-underline transition-all hover:bg-blue-700"
href={`https://devfest23.omsimos.com/cert/${id}`}
href={`https://gdg.omsimos.com/event/devfest-24/cert?id=${id}`}
>
View Your Certificate
</Button>
Expand Down

0 comments on commit 5bf0d11

Please sign in to comment.