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"],
user.id,
BUCKET_PITCH_NAME,
// file structure: userId/fileName
`${user?.id}/${recvData["businessPitchDeck"].name}`
);

View File

@ -17,37 +17,20 @@ export default function ApplyProject() {
const onSubmit: SubmitHandler<projectSchema> = 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",