Skip to content

Commit 20cbba8

Browse files
committed
refactor: ♻️ refactor resend files & .env.development
1 parent 9220cdd commit 20cbba8

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/api/emailApi.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
// const RESEND_KEY = import.meta.env.VITE_RESEND_KEY;
21
import { Resend } from "resend";
32
import { Email } from "../../types/emails";
3+
const RESEND_KEY = import.meta.env.VITE_RESEND_KEY;
44

5-
// const resend = new Resend(RESEND_KEY);
6-
const resend = new Resend("re_SDc7pz1Y_KgTU6WSyX1Ed5rtwNHsuFqnG");
5+
const resend = new Resend(RESEND_KEY);
76

87
export async function sendEmail(email: Email) {
98
try {
109
const { data, error } = await resend.emails.send(email);
11-
12-
if (error) throw new Error(error.message);
13-
10+
if (error) { throw new Error(error.message) };
1411
return data;
1512
} catch (error) {
1613
console.error("Error sending email:", error);

src/api/send/route.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
import { EmailTemplate } from '../../components/emails/EmailTemplate';
1+
import { EmailTest } from '../../components/emails/Tester';
22
import { Resend } from 'resend';
3+
const RESEND_KEY = import.meta.env.VITE_RESEND_KEY;
34

4-
// const resend = new Resend(process.env.RESEND_API_KEY);
5-
const resend = new Resend("re_SDc7pz1Y_KgTU6WSyX1Ed5rtwNHsuFqnG");
5+
const resend = new Resend(RESEND_KEY);
6+
7+
const facTeam= {
8+
to: [
9+
10+
11+
12+
],
13+
names: "Alex, Dan & Jason"
14+
}
615

716
export async function POST() {
817
try {
918
const { data, error } = await resend.emails.send({
1019
from: ' <[email protected]>',
11-
to: [
12-
13-
14-
15-
],
20+
to: facTeam.to,
1621
subject: "Our Very First Nudgemail",
17-
react: EmailTemplate({ firstName: 'Alex, Dan & Jason' }),
22+
react: EmailTest({ firstName: facTeam.names }),
1823
});
1924

2025
if (error) {
21-
return Response.json({ error }, { status: 500 });
22-
}
23-
24-
return Response.json(data);
26+
return Response.json( { error }, { status: 500 } )
27+
} else {
28+
return Response.json(data)
29+
};
2530
} catch (error) {
2631
return Response.json({ error }, { status: 500 });
2732
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as React from 'react';
2+
import { EmailProps } from 'types/emails';
23

3-
interface EmailTemplateProps {
4-
firstName: string;
5-
}
6-
7-
export const EmailTemplate: React.FC<Readonly<EmailTemplateProps>> = ({
4+
export const EmailTest: React.FC<Readonly<EmailProps>> = ({
85
firstName,
96
}) => (
107
<div>
11-
<h1>BEACONS LIVES!</h1>
8+
<h1>
9+
BEACONS LIVES!
10+
</h1>
11+
1212
<p>
1313
Hello, {firstName}!
1414
Thankyou for your service. Soon, I will have no further need of you.

types/emails.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
export interface Email {
2-
// app email address
3-
from: string,
2+
from: string, /* app email address */
3+
to: string[], /* array containing employer email */
4+
subject: string, /* derp */
5+
html: string /* email body */
6+
}
47

5-
// array containing employer email
6-
to: string[],
7-
8-
// derp
9-
subject: string,
10-
11-
// email body
12-
html: string
8+
export interface EmailProps {
9+
firstName: string;
1310
}

0 commit comments

Comments
 (0)