feat: ✨ use settings and translations in contact server action and emails
parent
f573a4ac2e
commit
520dd137d8
@ -1,21 +1,53 @@
|
||||
"use server";
|
||||
|
||||
import ContactEmail from "@/emails/contact";
|
||||
import { getI18n } from "@/i18n/server";
|
||||
import { getPayload } from "@/utils/payload";
|
||||
import { render } from "@react-email/render";
|
||||
import { getSettings } from "@/api";
|
||||
import { renderContactConfirmationEmail } from "@/emails/contact-confirmation";
|
||||
import { renderContactEmail } from "@/emails/contact";
|
||||
|
||||
export const submitContactFormAction = async (formData: FormData) => {
|
||||
const payload = await getPayload();
|
||||
const { adminLanguage, contactEmailsTo } = await getSettings();
|
||||
const t = await getI18n();
|
||||
|
||||
console.log(
|
||||
await renderContactEmail(
|
||||
{
|
||||
name: formData.get("name"),
|
||||
email: formData.get("email"),
|
||||
subject: formData.get("subject"),
|
||||
message: formData.get("message"),
|
||||
locale: adminLanguage,
|
||||
},
|
||||
{ plainText: true },
|
||||
),
|
||||
);
|
||||
|
||||
await payload.sendEmail({
|
||||
to: "moravrav@gmail.com",
|
||||
subject: `Kontaktanfrage von ${formData.get("name")}`,
|
||||
email: await render(
|
||||
<ContactEmail
|
||||
name={formData.get("name")}
|
||||
email={formData.get("email")}
|
||||
subject={formData.get("subject")}
|
||||
message={formData.get("message")}
|
||||
/>,
|
||||
to: contactEmailsTo,
|
||||
subject: t("email.contactSubject", { name: formData.get("name") }),
|
||||
email: await renderContactEmail(
|
||||
{
|
||||
name: formData.get("name"),
|
||||
email: formData.get("email"),
|
||||
subject: formData.get("subject"),
|
||||
message: formData.get("message"),
|
||||
locale: adminLanguage,
|
||||
},
|
||||
{ plainText: true },
|
||||
),
|
||||
});
|
||||
|
||||
await payload.sendEmail({
|
||||
to: formData.get("email"),
|
||||
subject: `Bestätigung Ihrer Kontaktanfrage ${formData.get("name")}`,
|
||||
email: await renderContactConfirmationEmail({
|
||||
name: formData.get("name"),
|
||||
email: formData.get("email"),
|
||||
subject: formData.get("subject"),
|
||||
message: formData.get("message"),
|
||||
locale: adminLanguage,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue