I am trying to store data into my firestore using a form built with reactJS using semantic UI .. Upon submission of the form, the image file uploaded in the form is stored into the firebase storage, but the rest of the data inserted in the form is not added to the firestore collection.
Its like the program freezes after storing the image because it does not generate any bug or error .. It just shows an endless loading indicator which means it still processing the onSubmit function
You can test the form to see how it behaves on via this link: https://envy-hxxdini.firebaseapp.com/eventcreate
Here is my source code for the onSubmit function:
const onSubmit = (e) => {
e.preventDefault();
if (eventImage) {
setLoading(true);
const uploadImage = storage.ref(`EventImages/${values.eventTitle}`)
uploadImage.put(eventImage).then(() => {
storage.ref('EventImages').child(values.eventName).getDownloadURL().then(url => {
dbref.add({
eventName: values.eventTitle,
eventCategory: values.eventCategory,
eventType: values.eventType,
eventOrganizer: values.eventOrganizer,
eventVenue: values.eventVenue,
eventStreet1: values.eventStreet1,
eventStreet2: values.eventStreet2,
eventPhone: values.eventPhone,
eventEmail: values.eventEmail,
eventDetails: values.eventDetails,
startDate: startDate,
startTime: startTime,
endDate: endDate,
endTime: endTime,
eventImgUrl: url,
public: state.public,
tickets: state.ticket
}).then((docRef) => {
console.log("Document written with ID: ", docRef.id);
setValues('');
setImage('');
setPrevUrl("");
setLoading(false);
}).catch((error) => {
console.error("Error adding document: ", error);
});
})
})
}
else {
NotificationManager.error('Please an image is required', 'Close', 3000);
}
}