mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 05:54:06 +01:00
fix: rename query to action.ts
This commit is contained in:
parent
cb20185f3c
commit
894791e15a
@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
import { useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { SubmitHandler } from "react-hook-form";
|
import { SubmitHandler } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import BusinessForm from "./BusinessForm";
|
import BusinessForm from "./BusinessForm";
|
||||||
@ -8,22 +8,23 @@ import { businessFormSchema } from "@/types/schemas/application.schema";
|
|||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import { getCurrentUserID } from "@/app/api/userApi";
|
import { getCurrentUserID } from "@/app/api/userApi";
|
||||||
import { uploadFile } from "@/app/api/generalApi";
|
import { uploadFile } from "@/app/api/generalApi";
|
||||||
import { useRouter } from "next/navigation";
|
import { Loader } from "@/components/loading/loader";
|
||||||
import { hasUserApplied, transformChoice } from "./query";
|
import { hasUserApplied, transformChoice } from "./actions";
|
||||||
|
|
||||||
type businessSchema = z.infer<typeof businessFormSchema>;
|
type businessSchema = z.infer<typeof businessFormSchema>;
|
||||||
const BUCKET_PITCH_NAME = "business-application";
|
const BUCKET_PITCH_NAME = "business-application";
|
||||||
const supabase = createSupabaseClient();
|
let supabase = createSupabaseClient();
|
||||||
|
|
||||||
export default function ApplyBusiness() {
|
export default function ApplyBusiness() {
|
||||||
const router = useRouter();
|
|
||||||
const alertShownRef = useRef(false);
|
const alertShownRef = useRef(false);
|
||||||
|
const [success, setSucess] = useState(false);
|
||||||
|
|
||||||
const onSubmit: SubmitHandler<businessSchema> = async (data) => {
|
const onSubmit: SubmitHandler<businessSchema> = async (data) => {
|
||||||
const transformedData = await transformChoice(data);
|
const transformedData = await transformChoice(data);
|
||||||
await sendApplication(transformedData);
|
await sendApplication(transformedData);
|
||||||
};
|
};
|
||||||
const sendApplication = async (recvData: any) => {
|
const sendApplication = async (recvData: any) => {
|
||||||
|
setSucess(false);
|
||||||
const {
|
const {
|
||||||
data: { user },
|
data: { user },
|
||||||
} = await supabase.auth.getUser();
|
} = await supabase.auth.getUser();
|
||||||
@ -65,6 +66,7 @@ export default function ApplyBusiness() {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
.select();
|
.select();
|
||||||
|
setSucess(true);
|
||||||
// console.table(data);
|
// console.table(data);
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: error == null ? "success" : "error",
|
icon: error == null ? "success" : "error",
|
||||||
@ -72,13 +74,14 @@ export default function ApplyBusiness() {
|
|||||||
text: error == null ? "Your application has been submitted" : error.message,
|
text: error == null ? "Your application has been submitted" : error.message,
|
||||||
confirmButtonColor: error == null ? "green" : "red",
|
confirmButtonColor: error == null ? "green" : "red",
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.push("/");
|
window.location.href = "/";
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUserData = async () => {
|
const fetchUserData = async () => {
|
||||||
try {
|
try {
|
||||||
|
setSucess(false);
|
||||||
const userID = await getCurrentUserID();
|
const userID = await getCurrentUserID();
|
||||||
if (userID) {
|
if (userID) {
|
||||||
const hasApplied = await hasUserApplied(supabase, userID);
|
const hasApplied = await hasUserApplied(supabase, userID);
|
||||||
@ -87,14 +90,14 @@ export default function ApplyBusiness() {
|
|||||||
alertShownRef.current = true;
|
alertShownRef.current = true;
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: "info",
|
icon: "info",
|
||||||
title: "You Already Have an Account or Application",
|
title: "You Already Have an Account",
|
||||||
text: "You have already submitted your business application.",
|
text: "You have already submitted your business application.",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
allowOutsideClick: false,
|
allowOutsideClick: false,
|
||||||
allowEscapeKey: false,
|
allowEscapeKey: false,
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
router.push("/");
|
window.location.href = "/";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -107,12 +110,13 @@ export default function ApplyBusiness() {
|
|||||||
console.error("Error fetching user ID:", error);
|
console.error("Error fetching user ID:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// setSucess(true);
|
||||||
fetchUserData();
|
fetchUserData();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<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">
|
<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">
|
<h1 className="text-2xl md:text-5xl font-medium md:font-bold justify-self-center md:mt-8">
|
||||||
Apply to raise on B2DVentures
|
Apply to raise on B2DVentures
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user