diff --git a/src/app/business/apply/query.ts b/src/app/business/apply/actions.ts similarity index 100% rename from src/app/business/apply/query.ts rename to src/app/business/apply/actions.ts diff --git a/src/app/business/apply/page.tsx b/src/app/business/apply/page.tsx index 0370737..a1b11c1 100644 --- a/src/app/business/apply/page.tsx +++ b/src/app/business/apply/page.tsx @@ -1,6 +1,6 @@ "use client"; import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; -import { useEffect, useRef } from "react"; +import { useState, useEffect, useRef } from "react"; import { SubmitHandler } from "react-hook-form"; import { z } from "zod"; import BusinessForm from "./BusinessForm"; @@ -8,22 +8,23 @@ import { businessFormSchema } from "@/types/schemas/application.schema"; import Swal from "sweetalert2"; import { getCurrentUserID } from "@/app/api/userApi"; import { uploadFile } from "@/app/api/generalApi"; -import { useRouter } from "next/navigation"; -import { hasUserApplied, transformChoice } from "./query"; +import { Loader } from "@/components/loading/loader"; +import { hasUserApplied, transformChoice } from "./actions"; type businessSchema = z.infer; const BUCKET_PITCH_NAME = "business-application"; -const supabase = createSupabaseClient(); +let 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,6 +66,7 @@ export default function ApplyBusiness() { }, ]) .select(); + setSucess(true); // console.table(data); Swal.fire({ icon: error == null ? "success" : "error", @@ -72,13 +74,14 @@ export default function ApplyBusiness() { text: error == null ? "Your application has been submitted" : error.message, confirmButtonColor: error == null ? "green" : "red", }).then(() => { - router.push("/"); + window.location.href = "/"; }); }; useEffect(() => { const fetchUserData = async () => { try { + setSucess(false); const userID = await getCurrentUserID(); if (userID) { const hasApplied = await hasUserApplied(supabase, userID); @@ -87,14 +90,14 @@ export default function ApplyBusiness() { alertShownRef.current = true; Swal.fire({ icon: "info", - title: "You Already Have an Account or Application", + title: "You Already Have an Account", text: "You have already submitted your business application.", confirmButtonText: "OK", allowOutsideClick: false, allowEscapeKey: false, }).then((result) => { if (result.isConfirmed) { - router.push("/"); + window.location.href = "/"; } }); } @@ -107,12 +110,13 @@ 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