mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
Refactor ApplyProject component to update file upload path and add Lottie animation for loading
This commit is contained in:
parent
4b5be49874
commit
f9aa1c586f
@ -6,58 +6,65 @@ import { projectFormSchema } from "@/types/schemas/application.schema";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { SubmitHandler } from "react-hook-form";
|
import { SubmitHandler } from "react-hook-form";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
|
import { uploadFile } from "@/app/api/generalApi";
|
||||||
|
|
||||||
type projectSchema = z.infer<typeof projectFormSchema>;
|
type projectSchema = z.infer<typeof projectFormSchema>;
|
||||||
let supabase = createSupabaseClient();
|
let supabase = createSupabaseClient();
|
||||||
const BUCKET_PITCH_NAME = "project-pitches";
|
const BUCKET_PITCH_APPLICATION_NAME = "project-pitches";
|
||||||
const BUCKET_LOGO_NAME = "project-logo";
|
|
||||||
const BUCKET_PHOTOS_NAME = "project-additional-photos";
|
|
||||||
|
|
||||||
export default function ApplyProject() {
|
export default function ApplyProject() {
|
||||||
const onSubmit: SubmitHandler<projectSchema> = async (data) => {
|
const onSubmit: SubmitHandler<projectSchema> = async (data) => {
|
||||||
alert("มาแน้ววว");
|
alert("มาแน้ววว");
|
||||||
|
await sendApplication(data);
|
||||||
console.table(data);
|
// console.table(data);
|
||||||
console.log(typeof data["projectPhotos"], data["projectPhotos"]);
|
// console.log(typeof data["projectPhotos"], data["projectPhotos"]);
|
||||||
};
|
};
|
||||||
const sendApplication = async (recvData: any) => {
|
const sendApplication = async (recvData: any) => {
|
||||||
const {
|
const {
|
||||||
data: { user },
|
data: { user },
|
||||||
} = await supabase.auth.getUser();
|
} = await supabase.auth.getUser();
|
||||||
|
let projectId = null;
|
||||||
const pitchType = typeof recvData["projectPitchDeck"];
|
const pitchType = typeof recvData["projectPitchDeck"];
|
||||||
|
// save the general application data to project_application table
|
||||||
const { data, error } = await supabase
|
const { data: project_application, error } = await supabase
|
||||||
.from("project_application")
|
.from("project_application")
|
||||||
.insert([
|
.insert([
|
||||||
{
|
{
|
||||||
user_id: user?.id,
|
user_id: user?.id,
|
||||||
pitch_deck_url:
|
pitch_deck_url:
|
||||||
pitchType === "string" ? recvData["businessPitchDeck"] : "",
|
pitchType === "string" ? recvData["projectPitchDeck"] : "",
|
||||||
target_investment: recvData["targetInvest"],
|
target_investment: recvData["targetInvest"],
|
||||||
deadline: recvData["deadline"],
|
deadline: recvData["deadline"],
|
||||||
project_name: recvData["projectName"],
|
project_name: recvData["projectName"],
|
||||||
|
project_type_id: recvData["projectType"],
|
||||||
|
short_description: recvData["shortDescription"],
|
||||||
|
min_investment: recvData["minInvest"],
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
.select();
|
.select();
|
||||||
if (pitchType === "object") {
|
if (project_application) {
|
||||||
if (user?.id) {
|
projectId = project_application[0].id;
|
||||||
// const uploadSuccess = await uploadFile(
|
}
|
||||||
// recvData["businessPitchDeck"],
|
// upload pitch file
|
||||||
// user.id,
|
if (pitchType === "object") {
|
||||||
// BUCKET_PITCH_NAME
|
if (user?.id) {
|
||||||
// );
|
const uploadSuccess = await uploadFile(
|
||||||
|
recvData["businessPitchDeck"],
|
||||||
|
user.id,
|
||||||
|
BUCKET_PITCH_APPLICATION_NAME,
|
||||||
|
`${user?.id}/${projectId}/pitches/${recvData["projectPitchDeck"].name}`
|
||||||
|
);
|
||||||
|
|
||||||
// if (!uploadSuccess) {
|
if (!uploadSuccess) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
console.log("file upload successful");
|
console.log("file upload successful");
|
||||||
} else {
|
} else {
|
||||||
console.error("user ID is undefined.");
|
console.error("user ID is undefined.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.table(data);
|
// console.table(data);
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: error == null ? "success" : "error",
|
icon: error == null ? "success" : "error",
|
||||||
@ -67,7 +74,7 @@ export default function ApplyProject() {
|
|||||||
confirmButtonColor: error == null ? "green" : "red",
|
confirmButtonColor: error == null ? "green" : "red",
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
window.location.href = "/";
|
// window.location.href = "/";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user