From 645b3973967a1fdeb5cf6a4260e304bb3d612856 Mon Sep 17 00:00:00 2001 From: AmirReza Jamali Date: Mon, 27 Oct 2025 11:33:18 +0330 Subject: [PATCH] feat(form): enhance and refactor contact form to inquiries form This commit refactors the contact form into a more robust inquiries form, relocating it from `/contact-us` to a new `/inquires` route. Key changes include: - Renamed and moved the component from `ContactUs` to `Inquires`. - Updated form fields: removed "Company Name", added "Message", and renamed "Work Email" and "Phone Number" for clarity. - Implemented comprehensive client-side validation for all fields using `react-hook-form`. - Added a loading state to the submit button to provide user feedback during submission. - The form now automatically resets upon successful submission. - Introduced new reusable `TextareaGroup` and `Loading` components to support the enhanced form functionality. --- app/_components/FooterForm.tsx | 4 +- app/_components/Loading.tsx | 20 ++++ app/_components/Textarea.tsx | 61 ++++++++++++ app/_contact-us/form.tsx | 125 +++++++++++++++++------- app/_inquires/form.tsx | 106 ++++++++++++++++++++ app/{_contact-us => _inquires}/page.tsx | 8 +- 6 files changed, 284 insertions(+), 40 deletions(-) create mode 100644 app/_components/Loading.tsx create mode 100644 app/_components/Textarea.tsx create mode 100644 app/_inquires/form.tsx rename app/{_contact-us => _inquires}/page.tsx (83%) 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 ( +
+
+ Loading... +
+
+ ); +} + +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 ( +
+
+