fix: fix business ui loader not remove

This commit is contained in:
Sosokker 2024-11-09 15:50:23 +07:00
parent e4cf116f30
commit 5c455d20ee
3 changed files with 33 additions and 16 deletions

View File

@ -72,6 +72,7 @@ const BusinessForm = ({ onSubmit }: BusinessFormProps & { onSubmit: SubmitHandle
useEffect(() => {
fetchCountries();
fetchIndustry();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<Form {...form}>
@ -360,7 +361,7 @@ const BusinessForm = ({ onSubmit }: BusinessFormProps & { onSubmit: SubmitHandle
<FormItem>
<FormControl>
<MultipleOptionSelector
header={<>What's the rough size of your community?</>}
header={<>What&apos;s the rough size of your community?</>}
fieldName="communitySize"
choices={communitySize}
handleFunction={(selectedValues: any) => {

View File

@ -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<typeof businessFormSchema>;
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<businessSchema> = 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 (
<div>
<Loader isSuccess={success} />
<div className="grid grid-flow-row auto-rows-max w-full h-52 md:h-92 bg-gray-100 dark:bg-gray-800 p-5">
<h1 className="text-2xl md:text-5xl font-medium md:font-bold justify-self-center md:mt-8">
Apply to raise on B2DVentures

View File

@ -0,0 +1,22 @@
export function LegacyLoader() {
return (
<div className="container flex items-center justify-center h-screen">
<div className="text-center">
<svg
className="animate-spin h-12 w-12 text-gray-600 mx-auto mb-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291l-2.832 2.832A10.003 10.003 0 0112 22v-4a8.001 8.001 0 01-6-5.709z"
></path>
</svg>
<p className="text-lg font-semibold text-gray-600">Loading data...</p>
</div>
</div>
);
}