diff --git a/src/components/BusinessForm.tsx b/src/app/business/apply/BusinessForm.tsx similarity index 99% rename from src/components/BusinessForm.tsx rename to src/app/business/apply/BusinessForm.tsx index b26d583..bd12f73 100644 --- a/src/components/BusinessForm.tsx +++ b/src/app/business/apply/BusinessForm.tsx @@ -72,6 +72,7 @@ const BusinessForm = ({ onSubmit }: BusinessFormProps & { onSubmit: SubmitHandle useEffect(() => { fetchCountries(); fetchIndustry(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (
@@ -360,7 +361,7 @@ const BusinessForm = ({ onSubmit }: BusinessFormProps & { onSubmit: SubmitHandle What's the rough size of your community?} + header={<>What's the rough size of your community?} fieldName="communitySize" choices={communitySize} handleFunction={(selectedValues: any) => { diff --git a/src/app/business/apply/page.tsx b/src/app/business/apply/page.tsx index 1025b45..b3554aa 100644 --- a/src/app/business/apply/page.tsx +++ b/src/app/business/apply/page.tsx @@ -1,29 +1,28 @@ "use client"; import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; -import { useState, useEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; import { SubmitHandler } from "react-hook-form"; import { z } from "zod"; -import BusinessForm from "@/components/BusinessForm"; +import BusinessForm from "./BusinessForm"; import { businessFormSchema } from "@/types/schemas/application.schema"; import Swal from "sweetalert2"; import { getCurrentUserID } from "@/app/api/userApi"; import { uploadFile } from "@/app/api/generalApi"; -import { Loader } from "@/components/loading/loader"; +import { useRouter } from "next/navigation"; type businessSchema = z.infer; const BUCKET_PITCH_NAME = "business-application"; -let supabase = createSupabaseClient(); +const supabase = createSupabaseClient(); export default function ApplyBusiness() { + const router = useRouter(); const alertShownRef = useRef(false); - const [success, setSucess] = useState(false); const onSubmit: SubmitHandler = async (data) => { const transformedData = await transformChoice(data); await sendApplication(transformedData); }; const sendApplication = async (recvData: any) => { - setSucess(false); const { data: { user }, } = await supabase.auth.getUser(); @@ -65,7 +64,6 @@ export default function ApplyBusiness() { }, ]) .select(); - setSucess(true); // console.table(data); Swal.fire({ icon: error == null ? "success" : "error", @@ -73,7 +71,7 @@ export default function ApplyBusiness() { text: error == null ? "Your application has been submitted" : error.message, confirmButtonColor: error == null ? "green" : "red", }).then(() => { - window.location.href = "/"; + router.push("/"); }); }; @@ -115,27 +113,24 @@ export default function ApplyBusiness() { useEffect(() => { const fetchUserData = async () => { try { - setSucess(false); const userID = await getCurrentUserID(); if (userID) { const hasApplied = await hasUserApplied(userID); - setSucess(true); if (hasApplied && !alertShownRef.current) { alertShownRef.current = true; Swal.fire({ icon: "info", - title: "You Already Have an Account", + title: "You Already Have an Account or Application", text: "You have already submitted your business application.", confirmButtonText: "OK", allowOutsideClick: false, allowEscapeKey: false, }).then((result) => { if (result.isConfirmed) { - window.location.href = "/"; + router.push("/"); } }); } - setSucess(false); } else { console.error("User ID is undefined."); } @@ -143,13 +138,12 @@ export default function ApplyBusiness() { console.error("Error fetching user ID:", error); } }; - // setSucess(true); fetchUserData(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (
-

Apply to raise on B2DVentures diff --git a/src/components/loading/LegacyLoader.tsx b/src/components/loading/LegacyLoader.tsx new file mode 100644 index 0000000..92b826b --- /dev/null +++ b/src/components/loading/LegacyLoader.tsx @@ -0,0 +1,22 @@ +export function LegacyLoader() { + return ( +
+
+ + + + +

Loading data...

+
+
+ ); +}