mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00

- INtroduced new method to save the event data from the google and microsoft providers only if there isn't already an event with the same id
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { useAuthContext } from "@/contexts/AuthContext";
|
|
import { useMutation, useQueryClient } from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { EventData } from "@/hooks/firebase/types/eventData";
|
|
|
|
export const useCreateEvent = () => {
|
|
const {user: currentUser} = useAuthContext()
|
|
const queryClients = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationKey: ["createEvent"],
|
|
mutationFn: async (eventData: Partial<EventData>) => {
|
|
try {
|
|
await firestore()
|
|
.collection("Events")
|
|
.add({...eventData, creatorId: currentUser?.uid})
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClients.invalidateQueries("events")
|
|
}
|
|
})
|
|
}
|
|
|
|
export const useCreateEventFromProvider = () => {
|
|
const {user: currentUser} = useAuthContext()
|
|
const queryClients = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationKey: ["createEventFromProvider"],
|
|
mutationFn: async (eventData: Partial<EventData>) => {
|
|
try {
|
|
const snapshot = await firestore()
|
|
.collection("Events")
|
|
.where("id", "==", eventData.id)
|
|
.get();
|
|
|
|
if (snapshot.empty) {
|
|
await firestore()
|
|
.collection("Events")
|
|
.add({...eventData, creatorId: currentUser?.uid})
|
|
}
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClients.invalidateQueries("events")
|
|
}
|
|
})
|
|
} |