Skip to content

Commit

Permalink
feat: add team entry email & enhance confirmation modal (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsp45 authored Mar 28, 2024
1 parent dc4fc3a commit e73de8f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/confirmationModal.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default function ConfirmationModal({ placeHolder, closeModal }) {
return (
<div className="fixed inset-0 bg-gray-800 bg-opacity-75 flex justify-center items-center">
<div className="relative bg-black rounded-lg shadow-lg">
<div className="relative bg-black border-2 border-gray-500 rounded-lg shadow-lg">
<div className="p-4 md:p-5 text-center">
<svg
className="mx-auto mb-4 text-gray-400 w-12 h-12"
className="mx-auto mb-4 text-white w-12 h-12"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand Down
50 changes: 50 additions & 0 deletions src/pages/api/teams/join.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createClient } from "@supabase/supabase-js";
import type { APIRoute } from "astro";
import { SMTPClient } from "emailjs";

export const prerender = false;

Expand All @@ -8,6 +9,14 @@ const supabase = createClient(
import.meta.env.SUPABASE_ANON_KEY,
);

const senderEmail = import.meta.env.SENDER_EMAIL;
const client = new SMTPClient({
user: import.meta.env.SMTP_USER,
password: import.meta.env.SMTP_PASS,
host: import.meta.env.SMTP_HOST,
ssl: true,
});

export const POST: APIRoute = async ({ request }) => {
const formData = await request.formData();

Expand Down Expand Up @@ -47,6 +56,17 @@ export const POST: APIRoute = async ({ request }) => {
);
}

// get the team name to send the email
const { data: data, error: error } = await supabase
.from("teams")
.select("name")
.eq("code", team_code);

if (data && data.length > 0) {
const team_name = data[0].name;
sendTeamEntryEmail(email, team_name);
}

return new Response(
JSON.stringify({
status: 200,
Expand Down Expand Up @@ -103,3 +123,33 @@ const validateForms = async (formData: FormData, errors: String[]) => {

return valid;
};

const sendTeamEntryEmail = async (to: string, team_name: string) => {
const message = {
text: "",
from: senderEmail.toString(),
to: to,
subject: "[BugsByte] Team entry confirmation",
attachment: [
{
data: `<h1>Hello again 👋</h1>
<div>
<p>You just entered a new team - <b>${team_name}</b></p>
<p>Looking forward to seeing you soon!</p>
<p>Organization team 🪲</p>
</div>`.toString(),
alternative: true,
},
],
};

try {
client.send(message, function (err, message) {
console.log(err || message);
});

return null;
} catch (error) {
return error;
}
};

0 comments on commit e73de8f

Please sign in to comment.