mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
- Introduced attribute id in the eventData type
- 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
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useMutation, useQueryClient} from "react-query";
|
||||
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";
|
||||
import { EventData } from "@/hooks/firebase/types/eventData";
|
||||
|
||||
export const useCreateEvent = () => {
|
||||
const {user: currentUser} = useAuthContext()
|
||||
@ -22,4 +22,32 @@ export const useCreateEvent = () => {
|
||||
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")
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user