From ceb5933fef393fc61a0228828cf972c4a4e331cc Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Mon, 12 Feb 2024 18:19:10 +0000 Subject: [PATCH] Added contact us page --- src/app/ar/contact/page.tsx | 5 +- src/app/contact/page.tsx | 5 +- src/templates/ContactUs.tsx | 175 +++++++++++++++++++++++++++++++++ src/translation/contactus.json | 50 ++++++++++ 4 files changed, 229 insertions(+), 6 deletions(-) create mode 100644 src/templates/ContactUs.tsx create mode 100644 src/translation/contactus.json diff --git a/src/app/ar/contact/page.tsx b/src/app/ar/contact/page.tsx index 4d72b14..dcb32c6 100644 --- a/src/app/ar/contact/page.tsx +++ b/src/app/ar/contact/page.tsx @@ -1,6 +1,5 @@ -import About from "@/templates/About"; -import ComingSoon from "@/templates/ComingSoon"; +import ContactUs from "@/templates/ContactUs"; export default function Page() { - return ; + return ; } diff --git a/src/app/contact/page.tsx b/src/app/contact/page.tsx index f3392ac..94d974a 100644 --- a/src/app/contact/page.tsx +++ b/src/app/contact/page.tsx @@ -1,6 +1,5 @@ -import About from "@/templates/About"; -import ComingSoon from "@/templates/ComingSoon"; +import ContactUs from "@/templates/ContactUs"; export default function Page() { - return ; + return ; } diff --git a/src/templates/ContactUs.tsx b/src/templates/ContactUs.tsx new file mode 100644 index 0000000..0463f71 --- /dev/null +++ b/src/templates/ContactUs.tsx @@ -0,0 +1,175 @@ +"use client"; +import React from "react"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import Footer from "@/components/Footer"; +import Navbar from "@/components/Navbar"; +import Title from "@/components/Title"; +import translation from "@/translation/contactus.json"; + +type FormValues = { + name: string; + email: string; + description: string; + subject: string; + type: "feedback" | "bug" | "help" | ""; +}; + +interface Props { + language: "en" | "ar"; + page: string; +} + +const ErrorMessage = ({ message }: { message: string }) => ( +
+ {message} +
+); +export default function App({ language, page }: Props) { + const selectOptions = [ + { + label: translation.feedback[language], + value: "feedback", + }, + { + label: translation.bug[language], + value: "bug", + }, + { + label: translation.help[language], + value: "help", + }, + ]; + + const { register, control, handleSubmit, formState } = useForm({ + defaultValues: { + name: "", + email: "", + description: "", + subject: "", + type: "", + }, + }); + + const { errors, isDirty, isValid } = formState; + console.log("formState", formState.isSubmitSuccessful); + const onSubmit: SubmitHandler = async (data) => { + try { + const response = await fetch( + `${process.env.NEXT_PUBLIC_APP_URL}/api/tickets`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + reporter: { + name: data.name, + email: data.email, + }, + subject: data.subject, + type: data.type, + reportedFrom: window.location.href, + status: "submitted", + date: new Date().toISOString(), + description: data.description, + }), + } + ); + + if (response.status === 200) { + const data = await response.json(); + // Pass data to the page via props + console.log(data); + return; + } + } catch (err) {} + }; + + return ( +
+ +
+
+ {translation.title[language]} +
+
+
+
+ + {errors.name && errors.name.type === "required" && ( + + )} + + + {errors.email && errors.email.type === "required" && ( + + )} + {errors.email && errors.email.type === "pattern" && ( + + )} + + + {errors.subject && errors.subject.type === "required" && ( + + )} + + {errors.type && errors.type.type === "required" && ( + + )} + +