-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: resend integrated feedback form
- Loading branch information
1 parent
ccace74
commit cf23f12
Showing
15 changed files
with
597 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
CONTENTFUL_SPACE_ID= | ||
CONTENTFUL_ACCESS_TOKEN= | ||
CONTENTFUL_ACCESS_TOKEN= | ||
RESEND_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import EmailTemplate, { EmailAdminTemplate } from "@/components/EmailTemplate"; | ||
import { FeedbackSchema, TFeedbackSchema } from "@/lib/schemas"; | ||
import { Resend } from "resend"; | ||
|
||
const resend = new Resend(process.env.RESEND_API_KEY); | ||
|
||
export async function POST(req: Request) { | ||
const { values } = await req.json(); | ||
|
||
if (!FeedbackSchema.safeParse(values).success) | ||
return Response.json({ error: "Invalid fields" }, { status: 401 }); | ||
|
||
const validatedFormFields = values as TFeedbackSchema; | ||
|
||
try { | ||
const data = await Promise.all([ | ||
resend.emails.send({ | ||
from: "SyllabusX <mail@syllabusx.live>", | ||
to: ["iboard990@gmail.com"], | ||
subject: "New response has arrived", | ||
react: EmailAdminTemplate( | ||
validatedFormFields | ||
) as React.ReactElement, | ||
}), | ||
resend.emails.send({ | ||
from: "SyllabusX <mail@syllabusx.live>", | ||
to: [validatedFormFields.email], | ||
subject: "Thanks for the feedback", | ||
react: EmailTemplate({ | ||
name: validatedFormFields.name, | ||
}) as React.ReactElement, | ||
}), | ||
]); | ||
return Response.json(data); | ||
} catch (error) { | ||
return Response.json({ error }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.