Fix profile type

This commit is contained in:
Milan Paunovic
2024-08-21 20:30:07 +02:00
parent 6b42476ef0
commit 55a3091023
4 changed files with 24 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import React, {useEffect, useState} from "react";
import {Button, Text, TextInput} from "react-native";
import {Checkbox, Picker, TextField, View} from "react-native-ui-lib";
import {Button, TextInput} from "react-native";
import {Checkbox, Picker, TextField, View, Text} from "react-native-ui-lib";
import useAuth from "@/hooks/firebase/useAuth";
import useChildren from "@/hooks/firebase/useChildren";
import useCaregivers from "@/hooks/firebase/useCaregivers";
@ -25,20 +25,17 @@ const Screen: React.FC = () => {
} = useAuth();
const {
children,
child,
setChild,
handleNewChild,
} = useChildren(user);
const {data: childrenByParentId} = useGetChildrenByParentId()
const {data: children} = useGetChildrenByParentId()
const {
caregivers,
caregiver,
setCaregiver,
fetchCaregivers,
handleNewCaregiver,
} = useCaregivers();
const {mutateAsync: createSubUser} = useCreateSubUser()
@ -121,13 +118,15 @@ const Screen: React.FC = () => {
</View>
);
console.log(profileType, profileData)
return (
<View>
{user ? (
<View paddingH-20>
{profileType === ProfileType.parent && <Text>Parent</Text>}
{profileType === ProfileType.child && <Text>Child</Text>}
{profileType === ProfileType.caregiver && <Text>Caregiver</Text>}
<View paddingH-20 marginT-20>
{profileType === ProfileType.PARENT && <Text>Parent</Text>}
{profileType === ProfileType.CHILD && <Text>Child</Text>}
{profileType === ProfileType.CAREGIVER && <Text>Caregiver</Text>}
<Button title="Sign Out" onPress={handleSignOut}/>
<TextField
placeholder={"Child Name"}
@ -198,7 +197,7 @@ const Screen: React.FC = () => {
/>
<View margin-20>
<Text>Children:</Text>
{children.map((child) => (
{children?.map((child) => (
<View key={child.name} row>
<Text>Name: {child.name} </Text>
<Picker label="Pick Caregiver">

View File

@ -5,7 +5,11 @@ import {useRouter} from "expo-router";
import firestore from "@react-native-firebase/firestore";
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
export enum ProfileType { "parent", "child", "caregiver" }
export enum ProfileType {
"PARENT" = "parent",
"CHILD" = "child",
"CAREGIVER" = "caregiver"
}
interface IAuthContext {
user: FirebaseAuthTypes.User | null,
@ -37,7 +41,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
.doc(user.uid)
.get();
if (documentSnapshot.exists) {
setProfileType(documentSnapshot.data()?.profileType);
setProfileType(documentSnapshot.data()?.userType);
setProfileData(documentSnapshot.data() as UserProfile)
}

View File

@ -1,10 +1,12 @@
import {ProfileType} from "@/contexts/AuthContext";
export interface User {
uid: string;
email: string | null;
}
export interface UserProfile {
userType: "parent" | "child" | "caregiver";
userType: ProfileType;
name: string;
childrenIds?: string[];
birthday?: Date;
@ -15,18 +17,17 @@ export interface User {
}
export interface ParentProfile extends UserProfile {
userType: "parent";
userType: ProfileType.PARENT;
childrenIds: string[];
}
export interface ChildProfile extends UserProfile {
userType: "child";
userType: ProfileType.CHILD;
birthday: Date;
parentId: string;
}
export interface CaregiverProfile extends UserProfile {
userType: "caregiver";
//assignedChildrenId: string[];
userType: ProfileType.CAREGIVER;
contact: string;
}

View File

@ -1,6 +1,7 @@
import {useMutation} from "react-query";
import auth from "@react-native-firebase/auth";
import {useUpdateUserData} from "@/hooks/firebase/useUpdateUserData";
import {ProfileType} from "@/contexts/AuthContext";
export const useSignUp = () => {
const { mutateAsync: updateUserData } = useUpdateUserData()
@ -9,7 +10,7 @@ export const useSignUp = () => {
mutationKey: ["signUp"],
mutationFn: async ({email, password}: { email: string, password: string }) => {
await auth().createUserWithEmailAndPassword(email, password)
await updateUserData({userType: "parent", email, password})
await updateUserData({userType: ProfileType.PARENT, email, password})
}
});
}