mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
25 lines
833 B
TypeScript
25 lines
833 B
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")
|
|
}
|
|
})
|
|
} |