Refactor ApplyBusiness component to update file upload path

This commit is contained in:
Pattadon 2024-10-22 14:47:46 +07:00
parent 6da89cc38b
commit 29be79f6e8
2 changed files with 22 additions and 20 deletions

View File

@ -35,6 +35,7 @@ export default function ApplyBusiness() {
recvData["businessPitchDeck"], recvData["businessPitchDeck"],
user.id, user.id,
BUCKET_PITCH_NAME, BUCKET_PITCH_NAME,
// file structure: userId/fileName
`${user?.id}/${recvData["businessPitchDeck"].name}` `${user?.id}/${recvData["businessPitchDeck"].name}`
); );

View File

@ -17,37 +17,20 @@ export default function ApplyProject() {
const onSubmit: SubmitHandler<projectSchema> = async (data) => { const onSubmit: SubmitHandler<projectSchema> = async (data) => {
alert("มาแน้ววว"); alert("มาแน้ววว");
console.table(data); console.table(data);
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();
const pitchType = typeof recvData["businessPitchDeck"]; const pitchType = typeof recvData["projectPitchDeck"];
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 { data, error } = await supabase const { data, error } = await supabase
.from("business_application") .from("business_application")
.insert([ .insert([
{ {
user_id: user?.id, user_id: user?.id,
business_name: recvData["companyName"], business_name: recvData["projectName"],
business_type_id: recvData["industry"], business_type_id: recvData["industry"],
location: recvData["country"], location: recvData["country"],
is_for_sale: recvData["isForSale"], is_for_sale: recvData["isForSale"],
@ -60,6 +43,24 @@ export default function ApplyProject() {
}, },
]) ])
.select(); .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); // console.table(data);
Swal.fire({ Swal.fire({
icon: error == null ? "success" : "error", icon: error == null ? "success" : "error",