Refactor ApplyBusiness component and BusinessForm component

This commit is contained in:
THIS ONE IS A LITTLE BIT TRICKY KRUB 2024-10-30 15:07:13 +07:00
parent 2fba56288d
commit ca895bd605
2 changed files with 9 additions and 48 deletions

View File

@ -15,7 +15,6 @@ const BUCKET_PITCH_NAME = "business-application";
let supabase = createSupabaseClient();
export default function ApplyBusiness() {
const [applyProject, setApplyProject] = useState(false);
const alertShownRef = useRef(false);
const [success, setSucess] = useState(false);
@ -75,12 +74,8 @@ export default function ApplyBusiness() {
text:
error == null ? "Your application has been submitted" : error.message,
confirmButtonColor: error == null ? "green" : "red",
}).then((result) => {
if (result.isConfirmed && applyProject) {
window.location.href = "/project/apply";
} else {
window.location.href = "/";
}
}).then(() => {
window.location.href = "/";
});
};
@ -98,7 +93,10 @@ export default function ApplyBusiness() {
console.error(error);
console.error(applicationError);
}
if ((business && business.length != 0) || (businessApplication && businessApplication.length != 0)) {
if (
(business && business.length != 0) ||
(businessApplication && businessApplication.length != 0)
) {
return true;
}
return false;
@ -156,8 +154,8 @@ export default function ApplyBusiness() {
console.error("Error fetching user ID:", error);
}
};
// setSucess(true);
fetchUserData();
setSucess(true);
// fetchUserData();
}, []);
return (
@ -180,11 +178,7 @@ export default function ApplyBusiness() {
</div>
{/* form */}
{/* <form action="" onSubmit={handleSubmit(handleSubmitForms)}> */}
<BusinessForm
onSubmit={onSubmit}
applyProject={applyProject}
setApplyProject={setApplyProject}
/>
<BusinessForm onSubmit={onSubmit} />
</div>
);
}

View File

@ -17,25 +17,14 @@ import { businessFormSchema } from "@/types/schemas/application.schema";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@radix-ui/react-tooltip";
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
type businessSchema = z.infer<typeof businessFormSchema>;
interface BusinessFormProps {
applyProject: boolean;
setApplyProject: Function;
onSubmit: SubmitHandler<businessSchema>;
}
const BusinessForm = ({
applyProject,
setApplyProject,
onSubmit,
}: BusinessFormProps & { onSubmit: SubmitHandler<businessSchema> }) => {
const communitySize = [
@ -461,28 +450,6 @@ const BusinessForm = ({
</FormItem>
)}
/>
<div className="flex space-x-5">
<Switch
onCheckedChange={() => setApplyProject(!applyProject)}
></Switch>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="text-[12px] text-neutral-500 self-center cursor-pointer">
Would you like to apply for your first fundraising project
as well?
</span>
</TooltipTrigger>
<TooltipContent>
<p className="text-[11px]">
Toggling this option allows you to begin your first
project, <br /> which is crucial for unlocking the tools
necessary to raise funds.
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
<center>
<Button
className="mt-12 mb-20 h-10 text-base font-bold py-6 px-5"