diff --git a/src/lib/components/ContactForm.svelte b/src/lib/components/ContactForm.svelte index bcc8f5c..d65b8c9 100644 --- a/src/lib/components/ContactForm.svelte +++ b/src/lib/components/ContactForm.svelte @@ -14,7 +14,7 @@ const { form: formData, enhance } = form; -
+ {#snippet children({ props })} diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts new file mode 100644 index 0000000..c8cacf0 --- /dev/null +++ b/src/routes/+layout.ts @@ -0,0 +1 @@ +export const prerender = true; \ No newline at end of file diff --git a/src/routes/api/actions/+page.server.ts b/src/routes/api/actions/+page.server.ts new file mode 100644 index 0000000..472ed51 --- /dev/null +++ b/src/routes/api/actions/+page.server.ts @@ -0,0 +1,31 @@ +export const prerender = false; + +import type { Actions } from "./$types"; +import { superValidate } from "sveltekit-superforms/server" +import { zod } from "sveltekit-superforms/adapters"; +import { emailSchema } from "$lib/utils/schema"; +import { fail } from "@sveltejs/kit"; +import emailHelper from "$lib/utils/emailHelper"; + +export const actions: Actions = { + sendEmail: async (event) => { + const form = await superValidate(event, zod(emailSchema)); + if (!form.valid) { + return fail(400, { + form, + }); + } + console.log('**this is +page.server.ts**'); + const { from, subject, message } = form.data; + try { + const emailResponse = await emailHelper(from, subject, message); + console.log('message sent from ', emailResponse.envelope.from); + } catch (error) { + console.log(error); + } + + return { + form, + }; + }, +}; \ No newline at end of file diff --git a/src/routes/contact/+layout.ts b/src/routes/contact/+layout.ts new file mode 100644 index 0000000..c8cacf0 --- /dev/null +++ b/src/routes/contact/+layout.ts @@ -0,0 +1 @@ +export const prerender = true; \ No newline at end of file diff --git a/src/routes/contact/+page.server.ts b/src/routes/contact/+page.server.ts index 2301ef1..8ed3f4e 100644 --- a/src/routes/contact/+page.server.ts +++ b/src/routes/contact/+page.server.ts @@ -1,9 +1,10 @@ -import type { PageServerLoad, Actions } from "./$types"; +// export const prerender = true; +// export const ssr = false; + +import type { PageServerLoad } from "./$types"; import { superValidate } from "sveltekit-superforms/server" import { zod } from "sveltekit-superforms/adapters"; import { emailSchema } from "../../lib/utils/schema"; -import { fail } from "@sveltejs/kit"; -import emailHelper from "$lib/utils/emailHelper"; export const load: PageServerLoad = (async () => { // Server API: @@ -12,25 +13,3 @@ export const load: PageServerLoad = (async () => { return { form }; }); -export const actions: Actions = { - default: async (event) => { - const form = await superValidate(event, zod(emailSchema)); - if (!form.valid) { - return fail(400, { - form, - }); - } - console.log('**this is +page.server.ts**'); - const { from, subject, message } = form.data; - try { - const emailResponse = await emailHelper(from, subject, message); - console.log('message sent from ', emailResponse.envelope.from); - } catch (error) { - console.log(error); - } - - return { - form, - }; - }, -}; \ No newline at end of file