From a48a2c7f7ea1ac650ce1817af704bdf5138a9e73 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Tue, 3 May 2022 15:57:42 -0600 Subject: Add contact page --- src/routes/__layout.svelte | 2 + src/routes/approach/index.svelte | 2 +- src/routes/contact/index.svelte | 128 +++++++++++++++++++++++++++++++++++++-- src/routes/contact/submit.js | 69 +++++++++++++++++++++ src/routes/index.svelte | 2 +- src/routes/team/index.svelte | 2 +- 6 files changed, 198 insertions(+), 7 deletions(-) create mode 100644 src/routes/contact/submit.js (limited to 'src/routes') diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index aa8d8d8..ccb2fd5 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -2,8 +2,10 @@ import NavBar from '../components/NavBar.svelte'; import Footer from '../components/Footer.svelte'; import '../app.css'; + import { SvelteToast } from '@zerodevx/svelte-toast'; +
diff --git a/src/routes/approach/index.svelte b/src/routes/approach/index.svelte index f72b3e1..2dbe1df 100644 --- a/src/routes/approach/index.svelte +++ b/src/routes/approach/index.svelte @@ -4,7 +4,7 @@
- + boats in water

I meet each client where they are at and customize their therapeutic journey to best fit their personality and issues. The approaches I use most are listed below:

diff --git a/src/routes/contact/index.svelte b/src/routes/contact/index.svelte index cbedec9..84d9621 100644 --- a/src/routes/contact/index.svelte +++ b/src/routes/contact/index.svelte @@ -1,8 +1,128 @@ -
-
+ -
+ let captcha; + + function handleSubmit (e) { + e.preventDefault(); + + if (browser) { + const sendToast = toast.push('Sending...', { + duration: 300, + initial: 0, + next: 0.2, + dismissable: false + }); + fetch('/contact/submit', { + method: "POST", + body: JSON.stringify(submission) + }) + .then((x) => x.json()) + .then((x) => { + toast.set(sendToast, { next: 1 }); + + if (x.success) { + toast.push('Success! Reloading...', { + theme: { + '--toastBackground': '#48BB78', + '--toastBarBackground': '#2F855A' + }, + duration: 1000, + onpop: () => { window.location.reload(); }, + }); + } else if (x.error) { + toast.push(x.error, { + theme: { + '--toastBackground': '#F56565', + '--toastBarBackground': '#C53030' + } + }); + } + }) + .catch((err) => console.log(err)); + } + } + function onCaptchaError () { + toast.push('Failed to verify captcha, try again.', { + theme: { + '--toastBackground': '#F56565', + '--toastBarBackground': '#C53030' + } + }); + captcha.reset(); + } + + function onCaptchaSuccess ({ detail: { token } }) { + submission.captchaToken = token; + } + + +
+

Let's get in touch

+
+ +
+

+

+ Call or text +
+ (530) 638 - 3546 +

+
+
+

+

+ Email +
+ jeffer@mistymountainstherapy.com +

+
+
+
+

Or send us a message

+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ +
+ +
+
+
diff --git a/src/routes/contact/submit.js b/src/routes/contact/submit.js new file mode 100644 index 0000000..cf0d65c --- /dev/null +++ b/src/routes/contact/submit.js @@ -0,0 +1,69 @@ +import 'dotenv/config'; +import sgMail from '@sendgrid/mail'; +sgMail.setApiKey(process.env.SENDGRID_API_KEY); + +export async function get() { + const items = [ + {a: 1, b: 2}, + {a: 3, b: 4}, + {a: 5, b: 6}, + ]; + return { + body: items + }; +} + +export async function post({ request }) { + const body = await request.json(); + const { HCAPTCHA_SECRET, FORM_FROM_EMAIL, FORM_TO_EMAIL } = process.env; + + const captchaVerified = await fetch(`https://hcaptcha.com/siteverify?response=${body.captchaToken}&secret=${HCAPTCHA_SECRET}`, { + method: 'POST', + }) + .then((res) => res.json()) + .then((json) => json.success) + .catch(() => false); + + if (!captchaVerified) { + return { + statusCode: 400, + body: { + error: 'Captcha verification failed', + }, + }; + } + + const msg = { + to: FORM_TO_EMAIL, + from: FORM_FROM_EMAIL, + subject: `Form Submission from ${body.name}`, + text: ` + Name: ${body.name} + Email: ${body.email} + Message: ${body.message} + `, + }; + + const messageSent = await sgMail + .send(msg) + .then(() => true) + .catch((error) => { + console.error(error); + return false; + }); + + if (!messageSent) { + return { + statusCode: 500, + body: { + error: 'Message could not be sent', + }, + }; + } + + return { + body: { + success: true, + }, + }; +} diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 199014a..97d6566 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -20,7 +20,7 @@ Misty Mountains Therapy is a privately owned, high quality, specialty therapy clinic, founded in January 2020 by Jefferson Hunt. We are dedicated to providing comprehensive therapy evaluation and treatment services to children and adults for a wide variety of disorders in the most efficient and effective manner possible in the Rexburg area. We believe that therapy should be fun, engaging, and most importantly, useful to our clients.

- We are currently accepting new clients and offer a variety of services to help you live the life you desire. To find the right fit for you, schedule a free 15-minute consultation. + We are currently accepting new clients and offer a variety of services to help you live the life you desire. To find the right fit for you, schedule a free 15-minute consultation.

diff --git a/src/routes/team/index.svelte b/src/routes/team/index.svelte index 3d27c0e..52c97ee 100644 --- a/src/routes/team/index.svelte +++ b/src/routes/team/index.svelte @@ -38,7 +38,7 @@

{person.name}, {person.position}

-

{person.bio}

+

{person.bio}

{person.email}

-- cgit v1.2.3-70-g09d2