Skip to content

Commit 9f0d862

Browse files
committed
⚙️Integrate: Sendgrid ➕ADD: Sendgrid UI
1 parent d12ba9a commit 9f0d862

File tree

5 files changed

+84
-26
lines changed

5 files changed

+84
-26
lines changed

components/Contact.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ export default function Contact() {
2424
e.preventDefault();
2525
setForm({ state: "loading" });
2626

27-
// const res = await fetch("/api/subscribe", {
28-
// body: JSON.stringify({
29-
// email: inputEl.current.value,
30-
// }),
31-
// headers: {
32-
// "Content-Type": "application/json",
33-
// },
34-
// method: "POST",
35-
// });
27+
const res = await fetch("/api/sendgrid", {
28+
body: JSON.stringify({
29+
email: inputEl.current.value,
30+
}),
31+
headers: {
32+
"Content-Type": "application/json",
33+
},
34+
method: "POST",
35+
});
3636

37-
// const { error } = await res.json();
38-
// if (error) {
39-
// setForm({
40-
// state: "error",
41-
// message: error,
42-
// });
43-
// return;
44-
// }
37+
const { error } = await res.json();
38+
if (error) {
39+
setForm({
40+
state: "error",
41+
message: error,
42+
});
43+
return;
44+
}
4545

4646
// trackGoal("JYFUFMSF", 0);
4747
inputEl.current.value = "";
4848
setForm({
4949
state: "success",
50-
message: `Hooray! You're now on the list. I'll get back to you soon.`,
50+
message: `Hooray! You're now on the list. Check your inbox or promotions for a mail.`,
5151
});
5252
};
5353

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"@mdx-js/loader": "^1.6.22",
2222
"@mdx-js/react": "^1.6.22",
23+
"@sendgrid/mail": "^7.4.2",
2324
"@tailwindcss/typography": "^0.4.0",
2425
"comma-number": "^2.0.1",
2526
"date-fns": "^2.19.0",

pages/api/sendgrid.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sendgrid from "@sendgrid/mail";
2+
3+
sendgrid.setApiKey(process.env.SENDGRID_API_KEY);
4+
5+
export default async (req, res) => {
6+
try {
7+
// console.log("REQ.BODY", req.body);
8+
await sendgrid.send({
9+
to: req.body.email,
10+
from: "manuarorawork@gmail.com",
11+
subject: "Greetings! Thankyou for contacting Manu",
12+
text:
13+
"Thank you for contacting me from my website.\nPlease reply to this mail with your requirements and let me know how I can help you with your project.\n\nBest Regards,\nManu Arora\nSoftware Developer\n+91, 9587738861\n",
14+
});
15+
} catch (error) {
16+
console.log(error);
17+
return res.status(error.statusCode || 500).json({ error: error.message });
18+
}
19+
20+
return res.status(200).json({ error: "" });
21+
};

public/sitemap.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
<loc>https://manuarora.in/tweets</loc>
2525
</url>
2626

27-
<url>
28-
<loc>https://manuarora.in/blog/css-with-react</loc>
29-
</url>
30-
31-
<url>
32-
<loc>https://manuarora.in/blog/demo-blog</loc>
33-
</url>
34-
3527
<url>
3628
<loc>https://manuarora.in/blog/top-5-nextjs-resources</loc>
3729
</url>

0 commit comments

Comments
 (0)