Add event deletion

This commit is contained in:
Milan Paunovic
2024-10-31 12:01:01 +01:00
parent fff113de65
commit 1b6a241bbe
2 changed files with 670 additions and 615 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
import {useMutation, useQueryClient} from "react-query";
import firestore from "@react-native-firebase/firestore";
export const useDeleteEvent = () => {
const queryClient = useQueryClient();
return useMutation({
mutationKey: ["deleteEvent"],
mutationFn: async ({eventId, docId}: { eventId?: string; docId?: string }) => {
try {
if (docId) {
await firestore()
.collection("Events")
.doc(docId)
.delete();
} else if (eventId) {
const snapshot = await firestore()
.collection("Events")
.where("id", "==", eventId)
.get();
const doc = snapshot.docs[0];
if (doc) {
await doc.ref.delete();
} else {
console.warn("Event not found");
}
} else {
console.warn("No identifier provided");
}
} catch (e) {
console.error(e);
}
},
onSuccess: () => {
queryClient.invalidateQueries("events");
}
});
};