From 4bbb4701cf51035b158f43aa4f2d01170eadf8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Gawro=C5=84ski?= Date: Sat, 11 Nov 2023 08:15:22 +0100 Subject: [PATCH] chore: function to form aplllied --- src/components/FormJoin/FormJoin.tsx | 9 +++++++-- src/pages/_app.tsx | 12 +++++++----- src/pages/api/contact.ts | 9 +++++++-- src/pages/index.tsx | 26 +++++++++++++++----------- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/components/FormJoin/FormJoin.tsx b/src/components/FormJoin/FormJoin.tsx index d8318d5..db43ea8 100644 --- a/src/components/FormJoin/FormJoin.tsx +++ b/src/components/FormJoin/FormJoin.tsx @@ -8,6 +8,7 @@ import { FormEmail } from '@/components/FormEmail'; import { FormSelect } from '@/components/FormSelect'; import { FormTextarea } from '@/components/FormTextarea'; import { FormUsername } from '@/components/FormUsername'; +import contactHandler from '@/pages/api/contact'; export type Inputs = { name: string; @@ -25,8 +26,12 @@ export function FormJoin() { formState: { errors, dirtyFields } } = useForm({ mode: 'onChange' }); - const onSubmit = (data: Inputs) => { - console.log(data); + const onSubmit = async (data: Inputs) => { + const resopnse = await fetch(`${location.origin}/api/contact`, { + body: JSON.stringify(data), + method: 'POST' + }); + console.log(resopnse); }; return ( diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 5062b98..744a3d8 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -4,10 +4,12 @@ import type { AppProps } from 'next/app'; import { Layout } from '@/layouts'; -const App = ({ Component, pageProps }: AppProps) => ( - - - -); +const App = ({ Component, pageProps }: AppProps) => { + return ( + + + + ); +}; export default App; diff --git a/src/pages/api/contact.ts b/src/pages/api/contact.ts index 8231790..5e1a04a 100644 --- a/src/pages/api/contact.ts +++ b/src/pages/api/contact.ts @@ -14,6 +14,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method === 'POST') { const { name, email, guild, message } = req.body; const response = schema.safeParse(req.body); + console.log(req.body); if (!response.success) { const { errors } = response.error; @@ -26,10 +27,14 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { const apiUrl = 'https://api.brevo.com/v3/smtp/email'; const emailData = { - sender: { name, email }, + sender: { + name: 'Formularz', + email: 'jedrzej.ratajczak@coderscrew.pl', + replayTo: { email, name } + }, to: [ { - email: 'kontakt@coderscrew.pl', + email: 'jedrzej.ratajczak@coderscrew.pl', name: 'Coders Crew' } ], diff --git a/src/pages/index.tsx b/src/pages/index.tsx index dc42817..c47480e 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,3 +1,5 @@ +import { useRouter } from 'next/router'; + import { About, Guilds, @@ -8,16 +10,18 @@ import { Projects } from '@/containers'; -const Index = () => ( -
- - - - - - - -
-); +const Index = () => { + return ( +
+ + + + + + + +
+ ); +}; export default Index;