diff --git a/app/_components/FooterForm.tsx b/app/_components/FooterForm.tsx
index 7364666..415defd 100644
--- a/app/_components/FooterForm.tsx
+++ b/app/_components/FooterForm.tsx
@@ -1,9 +1,9 @@
-import ContactUs from "../_contact-us/page";
+import Inquires from "../_inquires/page";
const FooterForm = () => {
return (
-
+
);
};
diff --git a/app/_components/Loading.tsx b/app/_components/Loading.tsx
new file mode 100644
index 0000000..21496aa
--- /dev/null
+++ b/app/_components/Loading.tsx
@@ -0,0 +1,20 @@
+function Loading({ size = "md" }: { size?: "sm" | "md" | "lg" }) {
+ const sizeClasses = {
+ sm: "w-4 h-4 border-2",
+ md: "w-8 h-8 border-3",
+ lg: "w-12 h-12 border-4",
+ };
+
+ return (
+
+ );
+}
+
+export default Loading;
diff --git a/app/_components/Textarea.tsx b/app/_components/Textarea.tsx
new file mode 100644
index 0000000..54b7e25
--- /dev/null
+++ b/app/_components/Textarea.tsx
@@ -0,0 +1,61 @@
+"use client";
+import { useState } from "react";
+import { RegisterOptions, UseFormRegister } from "react-hook-form";
+
+function TextareaGroup({
+ id,
+ label,
+ register,
+ validation,
+ error,
+}: {
+ label: string;
+ id: string;
+ register: UseFormRegister;
+ validation?: RegisterOptions;
+ error?: string;
+}) {
+ const [isFocused, setIsFocused] = useState(false);
+ const [hasValue, setHasValue] = useState(false);
+
+ const { onChange, ...rest } = register(id, validation);
+
+ const handleChange = (e: React.ChangeEvent) => {
+ setHasValue(e.target.value !== "");
+ onChange(e);
+ };
+
+ return (
+
+
+
+ {error &&
{error}
}
+
+ );
+}
+
+export default TextareaGroup;
diff --git a/app/_contact-us/form.tsx b/app/_contact-us/form.tsx
index c13ec69..2eb3a81 100644
--- a/app/_contact-us/form.tsx
+++ b/app/_contact-us/form.tsx
@@ -1,42 +1,47 @@
"use client";
import api from "@/service/api";
+import { useState } from "react";
import { useForm } from "react-hook-form";
import { toast } from "react-toastify";
import InputGroup from "../_components/InputGroup";
+import Loading from "../_components/Loading";
+import TextareaGroup from "../_components/Textarea";
type TContactUsForm = {
full_name: string;
- company_name: string;
- work_email: string;
- phone_number: string;
+ email: string;
+ phone: string;
+ message: string;
};
-
-type ContactUsFormProps = {
+interface IProps {
columnsPerRow?: 1 | 2 | 3 | 4;
buttonText?: string;
-};
-
+}
const ContactUsForm = ({
- columnsPerRow = 2,
buttonText = "Submit",
-}: ContactUsFormProps) => {
+ columnsPerRow = 1,
+}: IProps) => {
+ const [isLoading, setIsLoading] = useState(false);
const {
register,
handleSubmit,
formState: { errors },
+ reset,
} = useForm();
-
const onSubmit = async (data: TContactUsForm) => {
+ setIsLoading(() => true);
try {
- const response = (await api.post("inquiries", { ...data })).data;
+ const response = (await api.post("contacts", { ...data })).data;
toast.success(response.message);
+ reset();
} catch (error) {
console.log(error);
toast.error("Something went wrong");
throw error;
+ } finally {
+ setIsLoading(() => false);
}
};
-
const gridColsClass = {
1: "lg:grid-cols-1",
2: "lg:grid-cols-2",
@@ -59,36 +64,88 @@ const ContactUsForm = ({
id="full_name"
label="Full Name"
register={register}
- type="text"
- />
-
-
-
+
+
+
-
diff --git a/app/_inquires/form.tsx b/app/_inquires/form.tsx
new file mode 100644
index 0000000..0e1c2b5
--- /dev/null
+++ b/app/_inquires/form.tsx
@@ -0,0 +1,106 @@
+"use client";
+import api from "@/service/api";
+import { useState } from "react";
+import { useForm } from "react-hook-form";
+import { toast } from "react-toastify";
+import InputGroup from "../_components/InputGroup";
+import Loading from "../_components/Loading";
+
+type TInquiresForm = {
+ full_name: string;
+ company_name: string;
+ work_email: string;
+ phone_number: string;
+};
+
+type InquiresFormProps = {
+ columnsPerRow?: 1 | 2 | 3 | 4;
+ buttonText?: string;
+};
+
+const InquiresForm = ({
+ columnsPerRow = 2,
+ buttonText = "Submit",
+}: InquiresFormProps) => {
+ const [isLoading, setIsLoading] = useState(false);
+ const {
+ register,
+ handleSubmit,
+ formState: { errors },
+ reset,
+ } = useForm();
+
+ const onSubmit = async (data: TInquiresForm) => {
+ setIsLoading(true);
+ try {
+ const response = (await api.post("inquiries", { ...data })).data;
+ toast.success(response.message);
+ reset();
+ } catch (error) {
+ console.log(error);
+ toast.error("Something went wrong");
+ throw error;
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ const gridColsClass = {
+ 1: "lg:grid-cols-1",
+ 2: "lg:grid-cols-2",
+ 3: "lg:grid-cols-3",
+ 4: "lg:grid-cols-4",
+ }[columnsPerRow];
+
+ const colSpanClass = {
+ 1: "lg:col-span-1",
+ 2: "lg:col-span-2",
+ 3: "lg:col-span-3",
+ 4: "lg:col-span-4",
+ }[columnsPerRow];
+
+ return (
+
+ );
+};
+
+export default InquiresForm;
diff --git a/app/_contact-us/page.tsx b/app/_inquires/page.tsx
similarity index 83%
rename from app/_contact-us/page.tsx
rename to app/_inquires/page.tsx
index d9e85c6..92da4dd 100644
--- a/app/_contact-us/page.tsx
+++ b/app/_inquires/page.tsx
@@ -1,6 +1,6 @@
-import ContactUsForm from "./form";
+import InquiresForm from "./form";
-const ContactUs = () => {
+const Inquires = () => {
return (
@@ -11,10 +11,10 @@ const ContactUs = () => {
);
};
-export default ContactUs;
+export default Inquires;