mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
Calendar settings page changes
This commit is contained in:
@ -1,39 +1,43 @@
|
||||
import { ProfileType } from "@/contexts/AuthContext";
|
||||
import {ProfileType} from "@/contexts/AuthContext";
|
||||
|
||||
export interface User {
|
||||
uid: string;
|
||||
email: string | null;
|
||||
uid: string;
|
||||
email: string | null;
|
||||
}
|
||||
|
||||
export interface UserProfile {
|
||||
userType: ProfileType;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
childrenIds?: string[];
|
||||
birthday?: Date;
|
||||
parentId?: string;
|
||||
contact?: string;
|
||||
email: string;
|
||||
password: string;
|
||||
familyId?: string;
|
||||
uid?: string;
|
||||
googleToken?: string;
|
||||
microsoftToken?: string;
|
||||
eventColor?: string
|
||||
userType: ProfileType;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
childrenIds?: string[];
|
||||
birthday?: Date;
|
||||
parentId?: string;
|
||||
contact?: string;
|
||||
email: string;
|
||||
password: string;
|
||||
familyId?: string;
|
||||
uid?: string;
|
||||
googleToken?: string | null;
|
||||
microsoftToken?: string | null;
|
||||
appleToken?: string | null;
|
||||
eventColor?: string | null;
|
||||
googleMail?: string | null;
|
||||
outlookMail?: string | null;
|
||||
appleMail?: string | null;
|
||||
}
|
||||
|
||||
export interface ParentProfile extends UserProfile {
|
||||
userType: ProfileType.PARENT;
|
||||
childrenIds: string[];
|
||||
userType: ProfileType.PARENT;
|
||||
childrenIds: string[];
|
||||
}
|
||||
|
||||
export interface ChildProfile extends UserProfile {
|
||||
userType: ProfileType.CHILD;
|
||||
birthday: Date;
|
||||
parentId: string;
|
||||
userType: ProfileType.CHILD;
|
||||
birthday: Date;
|
||||
parentId: string;
|
||||
}
|
||||
|
||||
export interface CaregiverProfile extends UserProfile {
|
||||
userType: ProfileType.CAREGIVER;
|
||||
contact: string;
|
||||
userType: ProfileType.CAREGIVER;
|
||||
contact: string;
|
||||
}
|
||||
|
||||
@ -1,33 +1,46 @@
|
||||
import {useAuthContext} from "@/contexts/AuthContext";
|
||||
import {useMutation, useQueryClient} from "react-query";
|
||||
import firestore from "@react-native-firebase/firestore";
|
||||
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||
import {FirebaseAuthTypes} from "@react-native-firebase/auth";
|
||||
import { FirebaseAuthTypes } from "@react-native-firebase/auth";
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import { useAuthContext } from "@/contexts/AuthContext";
|
||||
import { UserProfile } from "@/hooks/firebase/types/profileTypes";
|
||||
|
||||
export const useUpdateUserData = () => {
|
||||
const {user: currentUser, refreshProfileData} = useAuthContext();
|
||||
const queryClient = useQueryClient()
|
||||
const { user: currentUser, refreshProfileData } = useAuthContext();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["updateUserData"],
|
||||
mutationFn: async ({newUserData, customUser}: {newUserData: Partial<UserProfile>, customUser?: FirebaseAuthTypes.User }) => {
|
||||
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);
|
||||
const updatedUserData = Object.fromEntries(
|
||||
Object.entries(newUserData).map(([key, value]) =>
|
||||
[key, value === null ? firestore.FieldValue.delete() : value]
|
||||
)
|
||||
);
|
||||
|
||||
console.log("Updated user data with deletions:", updatedUserData);
|
||||
|
||||
await firestore()
|
||||
.collection("Profiles")
|
||||
.doc(user.uid)
|
||||
.update(newUserData);
|
||||
.update(updatedUserData);
|
||||
|
||||
console.log("User data updated successfully, fetching updated profile...");
|
||||
|
||||
await refreshProfileData()
|
||||
await refreshProfileData();
|
||||
|
||||
console.log("Profile data updated in context.");
|
||||
} catch (e) {
|
||||
@ -38,7 +51,7 @@ export const useUpdateUserData = () => {
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries("events")
|
||||
}
|
||||
queryClient.invalidateQueries("events");
|
||||
},
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user