mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 05:54:06 +01:00
connect apply application to database
This commit is contained in:
parent
0d9a0821c0
commit
a079900756
@ -37,37 +37,82 @@ export default function Apply() {
|
|||||||
"100K+",
|
"100K+",
|
||||||
];
|
];
|
||||||
|
|
||||||
// move to lib?
|
// get industry list to display in dropdown
|
||||||
const fetchIndustry = async () => {
|
const fetchIndustry = async () => {
|
||||||
let { data: BusinessType, error } = await supabase
|
let { data: businessType, error } = await supabase
|
||||||
.from("business_type")
|
.from("business_type")
|
||||||
.select("value");
|
.select("value");
|
||||||
|
|
||||||
if (!BusinessType) {
|
if (!businessType) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} else {
|
} else {
|
||||||
setIndustry(BusinessType.map((item) => item.value));
|
setIndustry(businessType.map((item) => item.value));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchIndustry();
|
fetchIndustry();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const createFormat = () => ({
|
// get business id from business type
|
||||||
"Company Name: ": companyName,
|
const getBusinessTypeID = async () => {
|
||||||
"Industry": selectedIndustry,
|
const { data, error } = await supabase
|
||||||
"Money Raised to Date": moneyRaisedToDate,
|
.from('business_type')
|
||||||
"Is in USA": isInUS,
|
.select('id')
|
||||||
"Is for sale": isForSale,
|
.eq('value', selectedIndustry)
|
||||||
"Is generating revenue": isGeneratingRevenue,
|
.single();
|
||||||
"Business Pitch": businessPitch,
|
|
||||||
"Community Size": selectedCommunitySize,
|
|
||||||
"Created At": new Date().toString()
|
|
||||||
});
|
|
||||||
|
|
||||||
const submitApplication = () => {
|
if (error) {
|
||||||
let format = createFormat();
|
console.error('Error fetching business ID:', error);
|
||||||
alert(JSON.stringify(format));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
// get current user id
|
||||||
|
const getUserID = async () => {
|
||||||
|
const { data: { user }, error } = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
if (error || !user) {
|
||||||
|
console.error('Error fetching user:', error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return user.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// format input data as json
|
||||||
|
const createFormat = async () => {
|
||||||
|
return {
|
||||||
|
"company_name": companyName,
|
||||||
|
"business_type_id": await getBusinessTypeID(),
|
||||||
|
"raise_to_date": moneyRaisedToDate, //TODO change to money_raised_to_date in database and change type to number
|
||||||
|
"is_in_us": isInUS,
|
||||||
|
"is_for_sale": isForSale,
|
||||||
|
"is_generating_revenue": isGeneratingRevenue,
|
||||||
|
"pitch_deck_url": businessPitch,
|
||||||
|
"community_size": selectedCommunitySize,
|
||||||
|
"created_at": new Date(),
|
||||||
|
"user_id": await getUserID()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// insert into business_application database
|
||||||
|
const submitApplication = async () => {
|
||||||
|
let format = await createFormat();
|
||||||
|
// alert(JSON.stringify(format)) // debug message
|
||||||
|
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('business_application')
|
||||||
|
.insert([format]);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
// return div error here
|
||||||
|
console.error('Error inserting data:', error);
|
||||||
|
// alert("Error" + JSON.stringify(error));
|
||||||
|
} else {
|
||||||
|
alert("Data successfully submitted!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user