diff --git a/app/components/faq/form.tsx b/app/components/faq/form.tsx index 3c3f734a..3e4ac3c0 100644 --- a/app/components/faq/form.tsx +++ b/app/components/faq/form.tsx @@ -1,12 +1,43 @@ import { zodResolver } from "@hookform/resolvers/zod"; -import { useEffect, useMemo } from "react"; +import { ActionFunction } from "@remix-run/node"; +import { Form, Link, useActionData } from "@remix-run/react"; +import { useEffect, useMemo, useState } from "react"; import { useForm } from "react-hook-form"; import type { z } from "zod"; import { schema } from "~/components/faq/schema"; +import Footer from "../ui/footer"; +import Header from "../ui/header"; type Form = z.infer; +const dataArray = [ + "What is EcoClean?", + "How does EcoClean work?", + "What are the key features of EcoClean?", + "Who can benefit from using EcoClean?", + "What are the system requirements for EcoClean?", + "How do I use EcoClean?", + "How do I store EcoClean?", + "How much does EcoClean cost?", + "Are there any discounts available?", +]; +export const action: ActionFunction = async ({ request }) => { + const formData = await request.formData(); + const searchValue = formData.get("search")?.toString().toLowerCase() || ""; + + const matches = dataArray.filter((item) => + item.toLowerCase().includes(searchValue), + ); + + return { matches, searchValue }; +}; + +interface ActionData { + matches: string[]; + searchValue: string; +} + function QuestionForm() { const defaultValues = useMemo( () => ({ @@ -29,7 +60,6 @@ function QuestionForm() { mode: "onBlur", }); - // FROM DOCs: It's recommended to reset in useEffect as execution order matters useEffect(() => { if (isSubmitSuccessful) { reset(defaultValues); @@ -40,131 +70,233 @@ function QuestionForm() { console.log("Form submitted with data:", data); }; + const actionData = useActionData(); + const [faqOpen, setFaqOpen] = useState(true); + + useEffect(() => { + if (actionData?.matches?.length > 0) { + setFaqOpen(false); + } + }, [actionData]); return ( -
-
-
- Still have questions ? -
-

- Fill the form and enter your message + <> +

+
+

+ Contact us / + FAQ

-
-
-
-
-
-