mirror of
https://github.com/urosran/cally.git
synced 2025-07-14 17:25:46 +00:00
Microsoft sync added
This commit is contained in:
@ -5,26 +5,36 @@ import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||
import {FirebaseAuthTypes} from "@react-native-firebase/auth";
|
||||
|
||||
export const useUpdateUserData = () => {
|
||||
const {user: currentUser, setProfileData} = useAuthContext()
|
||||
const {user: currentUser, setProfileData, refreshProfileData} = useAuthContext();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["updateUserData"],
|
||||
mutationFn: async ({newUserData, customUser}: {newUserData: Partial<UserProfile>, customUser?: FirebaseAuthTypes.User }) => {
|
||||
const user = currentUser ?? customUser
|
||||
mutationFn: async ({newUserData, customUser}: {newUserData: Partial<UserProfile>, customUser?: FirebaseAuthTypes.User }) => {
|
||||
console.log("Mutation function called with data:", { newUserData, customUser });
|
||||
|
||||
const user = currentUser ?? customUser;
|
||||
|
||||
if (user) {
|
||||
console.log("Updating user data for UID:", user.uid);
|
||||
try {
|
||||
console.log("New user data:", newUserData);
|
||||
|
||||
await firestore()
|
||||
.collection("Profiles")
|
||||
.doc(user.uid)
|
||||
.update(newUserData);
|
||||
|
||||
const profileData = await firestore().collection("Profiles").doc(user?.uid!).get()
|
||||
setProfileData(profileData.data() as UserProfile)
|
||||
console.log("User data updated successfully, fetching updated profile...");
|
||||
|
||||
await refreshProfileData()
|
||||
|
||||
console.log("Profile data updated in context.");
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error("Error updating user data:", e);
|
||||
}
|
||||
} else {
|
||||
console.warn("No user found: currentUser and customUser are both undefined.");
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user