From 29be79f6e88a7720d1a9479fde667afa475072ae Mon Sep 17 00:00:00 2001 From: Pattadon Date: Tue, 22 Oct 2024 14:47:46 +0700 Subject: [PATCH] Refactor ApplyBusiness component to update file upload path --- src/app/business/apply/page.tsx | 1 + src/app/project/apply/page.tsx | 41 +++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/app/business/apply/page.tsx b/src/app/business/apply/page.tsx index 8d4c17d..10969ec 100644 --- a/src/app/business/apply/page.tsx +++ b/src/app/business/apply/page.tsx @@ -35,6 +35,7 @@ export default function ApplyBusiness() { recvData["businessPitchDeck"], user.id, BUCKET_PITCH_NAME, + // file structure: userId/fileName `${user?.id}/${recvData["businessPitchDeck"].name}` ); diff --git a/src/app/project/apply/page.tsx b/src/app/project/apply/page.tsx index fa081a4..546c281 100644 --- a/src/app/project/apply/page.tsx +++ b/src/app/project/apply/page.tsx @@ -17,37 +17,20 @@ export default function ApplyProject() { const onSubmit: SubmitHandler = async (data) => { alert("มาแน้ววว"); console.table(data); + console.log(typeof data["projectPhotos"], data["projectPhotos"]); }; const sendApplication = async (recvData: any) => { const { data: { user }, } = await supabase.auth.getUser(); - const pitchType = typeof recvData["businessPitchDeck"]; - if (pitchType === "object") { - if (user?.id) { - // const uploadSuccess = await uploadFile( - // recvData["businessPitchDeck"], - // user.id, - // BUCKET_PITCH_NAME - // ); - - // if (!uploadSuccess) { - // return; - // } - - console.log("file upload successful"); - } else { - console.error("user ID is undefined."); - return; - } - } + const pitchType = typeof recvData["projectPitchDeck"]; const { data, error } = await supabase .from("business_application") .insert([ { user_id: user?.id, - business_name: recvData["companyName"], + business_name: recvData["projectName"], business_type_id: recvData["industry"], location: recvData["country"], is_for_sale: recvData["isForSale"], @@ -60,6 +43,24 @@ export default function ApplyProject() { }, ]) .select(); + if (pitchType === "object") { + if (user?.id) { + // const uploadSuccess = await uploadFile( + // recvData["businessPitchDeck"], + // user.id, + // BUCKET_PITCH_NAME + // ); + + // if (!uploadSuccess) { + // return; + // } + + console.log("file upload successful"); + } else { + console.error("user ID is undefined."); + return; + } + } // console.table(data); Swal.fire({ icon: error == null ? "success" : "error",