mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
Add event deletion
This commit is contained in:
File diff suppressed because it is too large
Load Diff
39
hooks/firebase/useDeleteEvent.ts
Normal file
39
hooks/firebase/useDeleteEvent.ts
Normal 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");
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user