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

- Added creatorId to the grocery item in db and showed the name of the user that requested to add the new grocery
26 lines
990 B
TypeScript
26 lines
990 B
TypeScript
import { useMutation, useQueryClient } from "react-query";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
import { useAuthContext } from "@/contexts/AuthContext";
|
|
import {IGrocery} from "@/hooks/firebase/types/groceryData";
|
|
|
|
export const useCreateGrocery = () => {
|
|
const { user: currentUser, profileData } = useAuthContext();
|
|
const queryClients = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationKey: ["createGrocery"],
|
|
mutationFn: async (groceryData: Partial<IGrocery>) => {
|
|
try {
|
|
const newDoc = firestore().collection('Groceries').doc();
|
|
await firestore()
|
|
.collection("Groceries")
|
|
.add({...groceryData, id: newDoc.id, familyId: profileData?.familyId, creatorId: currentUser?.uid})
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClients.invalidateQueries("groceries")
|
|
}
|
|
})
|
|
} |