mirror of
https://github.com/urosran/cally.git
synced 2025-07-15 17:47:08 +00:00
Update logic for profile creation
This commit is contained in:
28
hooks/firebase/useUpdateUserData.ts
Normal file
28
hooks/firebase/useUpdateUserData.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useMutation} from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||
|
||||
export const useUpdateUserData = () => {
|
||||
const {user, setProfileData} = useAuthContext()
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["updateUserData"],
|
||||
mutationFn: async (newProfileData: Partial<UserProfile>) => {
|
||||
if (user) {
|
||||
try {
|
||||
await firestore()
|
||||
.collection("Profiles")
|
||||
.doc(user.uid)
|
||||
.set(newProfileData);
|
||||
|
||||
const profileData = await firestore().collection("Profiles").doc(user?.uid!).get()
|
||||
|
||||
setProfileData(profileData.data() as UserProfile)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user