all emails working when a customer submits an order

This commit is contained in:
Jacob Delgado 2024-08-31 01:51:01 -07:00
parent a75956c569
commit 5f0e56abec
5 changed files with 27 additions and 10 deletions

Binary file not shown.

View File

@ -31,7 +31,7 @@ export const sendEmail = async (formData: FormData) => {
try {
await resend.emails.send({
from:"Order Form <orders@kevosattire.com>",
from:"Kevos Official <orders@kevosattire.com>",
// to:"arcjcb11@gmail.com",
to: senderEmail as string,
subject: "New Order",

View File

@ -1,6 +1,7 @@
import { sendEmail } from "@/lib/mail.utils"
import { sendEmails } from "@/lib/mail.utils"
import { NextRequest } from "next/server"
export async function POST() {
export async function POST(request: NextRequest) {
const sender = {
name: 'Kevos Official',
address: 'no-reply@kevosattire.com',
@ -11,12 +12,14 @@ export async function POST() {
address: 'arcjcb11@gmail.com',
}]
const clientEmail = await request.json();
try{
const result = await sendEmail({
const result = await sendEmails({
sender,
recipients,
subject: "New Email!",
message: "We will follow up with a Paypal invoice soon!"
message: `New order from ${clientEmail}`
})
return Response.json({

View File

@ -9,7 +9,7 @@ import ClientPortal from "@/components/ClientPortal/ClientPortal";
import styles from "@/styles/Home.module.css";
import { Poppins } from "next/font/google";
import { sendEmail } from "./actions/sendEmail";
import { selfEmail } from "./api/emails/route";
import { sendEmails } from "@/lib/mail.utils";
const Popp = Poppins({ weight: "400", subsets: ["latin"] });
@ -33,10 +33,24 @@ export default function Home() {
// console.log({email:formData.get("email"), order:formData.get("order")})
// Send client email
// await sendEmail(formData);
await sendEmail(formData);
// Send new order email to self
// await selfEmail(formData);
const clientEmail = formData.get('senderEmail') as string
await fetch("/api/emails", {
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify(clientEmail),
})
// .then((response) => response.json())
// .then((data) => {
// console.log(data);
// })
.catch((error) => {
console.error(error);
});
// const response = await fetch("http://192.168.50.107:5580/new-order", {
@ -60,7 +74,7 @@ export default function Home() {
emails: "",
orders: "",
});
alert("Order Placed! Please check your email.")
// alert("Order Placed! Please check your email.")
}
return (

View File

@ -20,7 +20,7 @@ type SendEmailDto = {
message: string;
// react: React.ReactNode;
}
export const sendEmail = async (dto: SendEmailDto) => {
export const sendEmails = async (dto: SendEmailDto) => {
const { sender, recipients, subject, message} = dto;
return await transport.sendMail({