mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
Shopping List backend implementation
- Implemented fetching, create and update of groceries in db
This commit is contained in:
25
hooks/firebase/useUpdateGrocery.ts
Normal file
25
hooks/firebase/useUpdateGrocery.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {useMutation, useQueryClient} from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {IGrocery} from "@/hooks/firebase/types/groceryData";
|
||||
|
||||
export const useUpdateGrocery = () => {
|
||||
const queryClients = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["updateGrocery"],
|
||||
mutationFn: async (groceryData: Partial<IGrocery>) => {
|
||||
console.log(groceryData);
|
||||
try {
|
||||
await firestore()
|
||||
.collection("Groceries")
|
||||
.doc(groceryData.id)
|
||||
.update(groceryData);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClients.invalidateQueries("events")
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user