mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 09:45:20 +00:00
26 lines
959 B
TypeScript
26 lines
959 B
TypeScript
import { useMutation, useQueryClient } from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { useAuthContext } from "@/contexts/AuthContext";
|
|
import { IToDo } from "@/hooks/firebase/types/todoData";
|
|
|
|
export const useCreateTodo = () => {
|
|
const { user: currentUser, profileData } = useAuthContext();
|
|
const queryClients = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationKey: ["createTodo"],
|
|
mutationFn: async (todoData: Partial<IToDo>) => {
|
|
try {
|
|
const newDoc = firestore().collection('Todos').doc();
|
|
await firestore()
|
|
.collection("Todos")
|
|
.add({...todoData, id: newDoc.id, familyId: profileData?.familyId, creatorId: currentUser?.uid})
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClients.invalidateQueries("todos")
|
|
}
|
|
})
|
|
} |