Compare commits
7 Commits
cf174db014
...
520dd137d8
Author | SHA1 | Date |
---|---|---|
RaviAnand Mohabir | 520dd137d8 | 3 months ago |
RaviAnand Mohabir | f573a4ac2e | 3 months ago |
RaviAnand Mohabir | 0349d4c255 | 3 months ago |
RaviAnand Mohabir | 6a1ab314ad | 3 months ago |
RaviAnand Mohabir | faeda0e174 | 3 months ago |
RaviAnand Mohabir | 92fd8d9dd1 | 3 months ago |
RaviAnand Mohabir | ad22d47947 | 3 months ago |
@ -1,12 +0,0 @@
|
||||
"use server";
|
||||
|
||||
export const submitContactFormAction = (formData: FormData) => {
|
||||
console.log(JSON.stringify(formData, null, 2));
|
||||
console.log(formData.get("message"));
|
||||
console.log(formData.get("subject"));
|
||||
console.log(formData.get("date"));
|
||||
console.log(formData.get("time"));
|
||||
console.log(formData.get("name"));
|
||||
console.log(formData.get("email"));
|
||||
console.log(formData.get("phone"));
|
||||
};
|
@ -0,0 +1,53 @@
|
||||
"use server";
|
||||
|
||||
import { getI18n } from "@/i18n/server";
|
||||
import { getPayload } from "@/utils/payload";
|
||||
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: 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,
|
||||
}),
|
||||
});
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
"use server";
|
||||
|
||||
export const submitReservationFormAction = (formData: FormData) => {
|
||||
console.log(JSON.stringify(formData, null, 2));
|
||||
console.log(formData.get("message"));
|
||||
console.log(formData.get("subject"));
|
||||
console.log(formData.get("date"));
|
||||
console.log(formData.get("time"));
|
||||
console.log(formData.get("name"));
|
||||
console.log(formData.get("email"));
|
||||
console.log(formData.get("phone"));
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
"use server";
|
||||
|
||||
import { getPayload } from "@/utils/payload";
|
||||
|
||||
export const submitReservationFormAction = async (formData: FormData) => {
|
||||
const payload = await getPayload();
|
||||
await payload.sendEmail({
|
||||
to: "moravrav@gmail.com",
|
||||
subject: `Reservation von ${formData.get("name")}`,
|
||||
text: `Sie haben eine Reservation von ${formData.get("name")} erhalten:
|
||||
|
||||
Datum / Uhrzeit: ${formData.get("date")} / ${formData.get("date")}
|
||||
Gäste: ${formData.get("guests")}
|
||||
|
||||
Nachricht: ${formData.get("message")}
|
||||
|
||||
Kontaktdaten:
|
||||
- E-Mail: ${formData.get("email")}
|
||||
- Telefonnummer: ${formData.get("phone")}
|
||||
`,
|
||||
});
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
import type { Options } from "node_modules/payload/dist/globals/operations/local/findOne";
|
||||
import { getPayload } from "@/utils/payload";
|
||||
|
||||
export const getSettings = async (opts: Omit<Options<"settings">, "slug"> = {}) => {
|
||||
const payload = await getPayload();
|
||||
return await payload.findGlobal({ slug: "settings", ...opts });
|
||||
};
|
@ -0,0 +1,60 @@
|
||||
import { Font, Head, Html, Preview, Tailwind, Text } from "@react-email/components";
|
||||
import { I18nProviderClient, useI18n } from "@/i18n/client";
|
||||
import { Options, render } from "@react-email/render";
|
||||
|
||||
import { defaultLocale } from "@/i18n/settings";
|
||||
|
||||
type ContactConfirmationEmailContentProps = {
|
||||
name: string;
|
||||
email: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
};
|
||||
|
||||
function ContactConfirmationEmailContent(_props: ContactConfirmationEmailContentProps) {
|
||||
const t = useI18n();
|
||||
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<title>{t("email.contactConfirmationSubject")}</title>
|
||||
<Font
|
||||
fontFamily="Roboto"
|
||||
fallbackFontFamily="Verdana"
|
||||
webFont={{
|
||||
url: "https://fonts.googleapis.com/css2?family=Moderustic:wght@300..800&display=swap",
|
||||
format: "woff2",
|
||||
}}
|
||||
fontWeight={400}
|
||||
fontStyle="normal"
|
||||
/>
|
||||
</Head>
|
||||
<Preview>{t("email.contactConfirmationSubject")}</Preview>
|
||||
<Tailwind>
|
||||
<Text>{t("email.contactConfirmationText")}</Text>
|
||||
</Tailwind>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
|
||||
type ContactConfirmationEmailProps = {
|
||||
locale: string;
|
||||
} & ContactConfirmationEmailContentProps;
|
||||
|
||||
export default function ContactConfirmationEmail({
|
||||
locale = defaultLocale,
|
||||
...props
|
||||
}: ContactConfirmationEmailProps) {
|
||||
return (
|
||||
<I18nProviderClient locale={locale}>
|
||||
<ContactConfirmationEmailContent {...props} />
|
||||
</I18nProviderClient>
|
||||
);
|
||||
}
|
||||
|
||||
export async function renderContactConfirmationEmail(
|
||||
props: ContactConfirmationEmailProps,
|
||||
opts?: Options,
|
||||
) {
|
||||
return await render(<ContactConfirmationEmail {...props} />, opts);
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
import {
|
||||
Column,
|
||||
Font,
|
||||
Head,
|
||||
Html,
|
||||
Preview,
|
||||
Row,
|
||||
Section,
|
||||
Tailwind,
|
||||
Text,
|
||||
} from "@react-email/components";
|
||||
import { I18nProviderClient, useI18n } from "@/i18n/client";
|
||||
import { Options, render } from "@react-email/render";
|
||||
|
||||
import { defaultLocale } from "@/i18n/settings";
|
||||
|
||||
type ContactEmailContentProps = { name: string; email: string; subject: string; message: string };
|
||||
|
||||
function ContactEmailContent({
|
||||
name = "[[Name]]",
|
||||
subject = "[[Subject]]",
|
||||
email = "[[Email]]",
|
||||
message = "[[Message]]",
|
||||
}: ContactEmailContentProps) {
|
||||
const t = useI18n();
|
||||
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<title>{t("email.contactSubject", { name })}</title>
|
||||
<Font
|
||||
fontFamily="Roboto"
|
||||
fallbackFontFamily="Verdana"
|
||||
webFont={{
|
||||
url: "https://fonts.googleapis.com/css2?family=Moderustic:wght@300..800&display=swap",
|
||||
format: "woff2",
|
||||
}}
|
||||
fontWeight={400}
|
||||
fontStyle="normal"
|
||||
/>
|
||||
</Head>
|
||||
<Preview>{t("email.contactSubject", { name })}</Preview>
|
||||
<Tailwind>
|
||||
<Text>{t("email.contactTitle", { name })}</Text>
|
||||
<Text>{subject}</Text>
|
||||
<Section>
|
||||
<Row>
|
||||
<Column>{t("contact.name")}</Column>
|
||||
<Column>{name}</Column>
|
||||
</Row>
|
||||
<Row>
|
||||
<Column>{t("general.email")}</Column>
|
||||
<Column>{email}</Column>
|
||||
</Row>
|
||||
</Section>
|
||||
<Text>{t("contact.message")}</Text>
|
||||
<Text>{message}</Text>
|
||||
</Tailwind>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
|
||||
type ContactEmailProps = { locale: string } & ContactEmailContentProps;
|
||||
|
||||
export default function ContactEmail({ locale = defaultLocale, ...props }: ContactEmailProps) {
|
||||
return (
|
||||
<I18nProviderClient locale={locale}>
|
||||
<ContactEmailContent {...props} />
|
||||
</I18nProviderClient>
|
||||
);
|
||||
}
|
||||
|
||||
export async function renderContactEmail(props: ContactEmailProps, opts?: Options) {
|
||||
return await render(<ContactEmail {...props} />, opts);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
import { defaultLocale, locales } from "@/i18n/settings";
|
||||
|
||||
import type { GlobalConfig } from "payload";
|
||||
|
||||
export const Settings: GlobalConfig = {
|
||||
slug: "settings",
|
||||
access: {},
|
||||
fields: [
|
||||
{
|
||||
name: "adminLanguage",
|
||||
type: "select",
|
||||
options: locales.map((l) => ({
|
||||
value: l.code,
|
||||
label: l.label[l.code] ?? l.label[defaultLocale],
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: "contactEmailsTo",
|
||||
type: "email",
|
||||
},
|
||||
],
|
||||
};
|
@ -1,9 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { createI18nClient } from "next-international/client";
|
||||
import { importedLocales } from "./settings";
|
||||
|
||||
export const { useI18n, useScopedI18n, I18nProviderClient, useChangeLocale, useCurrentLocale } =
|
||||
createI18nClient({
|
||||
de: () => import("./de"),
|
||||
en: () => import("./en"),
|
||||
});
|
||||
createI18nClient(importedLocales);
|
||||
|
@ -0,0 +1 @@
|
||||
export default {} as const;
|
@ -0,0 +1 @@
|
||||
export default {} as const;
|
@ -1,6 +1,5 @@
|
||||
import { createI18nServer } from "next-international/server";
|
||||
import { importedLocales } from "./settings";
|
||||
|
||||
export const { getI18n, getScopedI18n, getStaticParams } = createI18nServer({
|
||||
de: () => import("./de"),
|
||||
en: () => import("./en"),
|
||||
});
|
||||
export const { getI18n, getScopedI18n, getStaticParams, getCurrentLocale } =
|
||||
createI18nServer(importedLocales);
|
||||
|
@ -1,4 +1,49 @@
|
||||
export const defaultLocale = "de" as const;
|
||||
export const locales = [defaultLocale, "en"] as const;
|
||||
export const locales = [
|
||||
{
|
||||
label: {
|
||||
de: "Deutsch",
|
||||
en: "German",
|
||||
fr: "Allemand",
|
||||
it: "Tedesco",
|
||||
},
|
||||
code: "de",
|
||||
},
|
||||
{
|
||||
label: {
|
||||
fr: "Français",
|
||||
en: "French",
|
||||
de: "Französisch",
|
||||
it: "Francese",
|
||||
},
|
||||
code: "fr",
|
||||
},
|
||||
{
|
||||
label: {
|
||||
it: "Italiano",
|
||||
de: "Italienisch",
|
||||
en: "Italian",
|
||||
fr: "Italien",
|
||||
},
|
||||
code: "it",
|
||||
},
|
||||
{
|
||||
label: {
|
||||
de: "Englisch",
|
||||
en: "English",
|
||||
it: "Inglese",
|
||||
fr: "Anglais",
|
||||
},
|
||||
code: "en",
|
||||
},
|
||||
] as const;
|
||||
|
||||
export type Locale = (typeof locales)[number];
|
||||
export type Locale = (typeof locales)[number]["code"];
|
||||
|
||||
export const defaultLocale: Locale = "de";
|
||||
|
||||
export const importedLocales = {
|
||||
de: () => import("./de"),
|
||||
en: () => import("./en"),
|
||||
it: () => import("./it"),
|
||||
fr: () => import("./fr"),
|
||||
} as const;
|
||||
|
Loading…
Reference in New Issue