Fix editing events

This commit is contained in:
Milan Paunovic
2024-10-20 15:32:30 +02:00
parent 5801420164
commit 8b37108be3
5 changed files with 81 additions and 330 deletions

View File

@ -11,11 +11,30 @@ export const useCreateEvent = () => {
mutationKey: ["createEvent"],
mutationFn: async (eventData: Partial<EventData>) => {
try {
if (eventData.id) {
const snapshot = await firestore()
.collection("Events")
.where("id", "==", eventData.id)
.get();
if (!snapshot.empty) {
const docId = snapshot.docs[0].id;
await firestore()
.collection("Events")
.doc(docId)
.set({
...eventData,
creatorId: currentUser?.uid,
familyId: profileData?.familyId
}, {merge: true});
return;
}
}
await firestore()
.collection("Events")
.add({...eventData, creatorId: currentUser?.uid, familyId: profileData?.familyId})
.add({...eventData, creatorId: currentUser?.uid, familyId: profileData?.familyId});
} catch (e) {
console.error(e)
console.error(e);
}
},
onSuccess: () => {