feat: ✨ use settings and translations in contact server action and emails
parent
f573a4ac2e
commit
520dd137d8
@ -1,21 +1,53 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import ContactEmail from "@/emails/contact";
|
import { getI18n } from "@/i18n/server";
|
||||||
import { getPayload } from "@/utils/payload";
|
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) => {
|
export const submitContactFormAction = async (formData: FormData) => {
|
||||||
const payload = await getPayload();
|
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({
|
await payload.sendEmail({
|
||||||
to: "moravrav@gmail.com",
|
to: contactEmailsTo,
|
||||||
subject: `Kontaktanfrage von ${formData.get("name")}`,
|
subject: t("email.contactSubject", { name: formData.get("name") }),
|
||||||
email: await render(
|
email: await renderContactEmail(
|
||||||
<ContactEmail
|
{
|
||||||
name={formData.get("name")}
|
name: formData.get("name"),
|
||||||
email={formData.get("email")}
|
email: formData.get("email"),
|
||||||
subject={formData.get("subject")}
|
subject: formData.get("subject"),
|
||||||
message={formData.get("message")}
|
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