mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 18:16:17 +00:00
Fix profile type
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import React, {useEffect, useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {Button, Text, TextInput} from "react-native";
|
import {Button, TextInput} from "react-native";
|
||||||
import {Checkbox, Picker, TextField, View} from "react-native-ui-lib";
|
import {Checkbox, Picker, TextField, View, Text} from "react-native-ui-lib";
|
||||||
import useAuth from "@/hooks/firebase/useAuth";
|
import useAuth from "@/hooks/firebase/useAuth";
|
||||||
import useChildren from "@/hooks/firebase/useChildren";
|
import useChildren from "@/hooks/firebase/useChildren";
|
||||||
import useCaregivers from "@/hooks/firebase/useCaregivers";
|
import useCaregivers from "@/hooks/firebase/useCaregivers";
|
||||||
@ -25,20 +25,17 @@ const Screen: React.FC = () => {
|
|||||||
} = useAuth();
|
} = useAuth();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
children,
|
|
||||||
child,
|
child,
|
||||||
setChild,
|
setChild,
|
||||||
handleNewChild,
|
|
||||||
} = useChildren(user);
|
} = useChildren(user);
|
||||||
|
|
||||||
const {data: childrenByParentId} = useGetChildrenByParentId()
|
const {data: children} = useGetChildrenByParentId()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
caregivers,
|
caregivers,
|
||||||
caregiver,
|
caregiver,
|
||||||
setCaregiver,
|
setCaregiver,
|
||||||
fetchCaregivers,
|
fetchCaregivers,
|
||||||
handleNewCaregiver,
|
|
||||||
} = useCaregivers();
|
} = useCaregivers();
|
||||||
|
|
||||||
const {mutateAsync: createSubUser} = useCreateSubUser()
|
const {mutateAsync: createSubUser} = useCreateSubUser()
|
||||||
@ -121,13 +118,15 @@ const Screen: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log(profileType, profileData)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
{user ? (
|
{user ? (
|
||||||
<View paddingH-20>
|
<View paddingH-20 marginT-20>
|
||||||
{profileType === ProfileType.parent && <Text>Parent</Text>}
|
{profileType === ProfileType.PARENT && <Text>Parent</Text>}
|
||||||
{profileType === ProfileType.child && <Text>Child</Text>}
|
{profileType === ProfileType.CHILD && <Text>Child</Text>}
|
||||||
{profileType === ProfileType.caregiver && <Text>Caregiver</Text>}
|
{profileType === ProfileType.CAREGIVER && <Text>Caregiver</Text>}
|
||||||
<Button title="Sign Out" onPress={handleSignOut}/>
|
<Button title="Sign Out" onPress={handleSignOut}/>
|
||||||
<TextField
|
<TextField
|
||||||
placeholder={"Child Name"}
|
placeholder={"Child Name"}
|
||||||
@ -198,7 +197,7 @@ const Screen: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
<View margin-20>
|
<View margin-20>
|
||||||
<Text>Children:</Text>
|
<Text>Children:</Text>
|
||||||
{children.map((child) => (
|
{children?.map((child) => (
|
||||||
<View key={child.name} row>
|
<View key={child.name} row>
|
||||||
<Text>Name: {child.name} </Text>
|
<Text>Name: {child.name} </Text>
|
||||||
<Picker label="Pick Caregiver">
|
<Picker label="Pick Caregiver">
|
||||||
|
@ -5,7 +5,11 @@ import {useRouter} from "expo-router";
|
|||||||
import firestore from "@react-native-firebase/firestore";
|
import firestore from "@react-native-firebase/firestore";
|
||||||
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||||
|
|
||||||
export enum ProfileType { "parent", "child", "caregiver" }
|
export enum ProfileType {
|
||||||
|
"PARENT" = "parent",
|
||||||
|
"CHILD" = "child",
|
||||||
|
"CAREGIVER" = "caregiver"
|
||||||
|
}
|
||||||
|
|
||||||
interface IAuthContext {
|
interface IAuthContext {
|
||||||
user: FirebaseAuthTypes.User | null,
|
user: FirebaseAuthTypes.User | null,
|
||||||
@ -37,7 +41,7 @@ export const AuthContextProvider: FC<{ children: ReactNode }> = ({children}) =>
|
|||||||
.doc(user.uid)
|
.doc(user.uid)
|
||||||
.get();
|
.get();
|
||||||
if (documentSnapshot.exists) {
|
if (documentSnapshot.exists) {
|
||||||
setProfileType(documentSnapshot.data()?.profileType);
|
setProfileType(documentSnapshot.data()?.userType);
|
||||||
setProfileData(documentSnapshot.data() as UserProfile)
|
setProfileData(documentSnapshot.data() as UserProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
import {ProfileType} from "@/contexts/AuthContext";
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
uid: string;
|
uid: string;
|
||||||
email: string | null;
|
email: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserProfile {
|
export interface UserProfile {
|
||||||
userType: "parent" | "child" | "caregiver";
|
userType: ProfileType;
|
||||||
name: string;
|
name: string;
|
||||||
childrenIds?: string[];
|
childrenIds?: string[];
|
||||||
birthday?: Date;
|
birthday?: Date;
|
||||||
@ -15,18 +17,17 @@ export interface User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ParentProfile extends UserProfile {
|
export interface ParentProfile extends UserProfile {
|
||||||
userType: "parent";
|
userType: ProfileType.PARENT;
|
||||||
childrenIds: string[];
|
childrenIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChildProfile extends UserProfile {
|
export interface ChildProfile extends UserProfile {
|
||||||
userType: "child";
|
userType: ProfileType.CHILD;
|
||||||
birthday: Date;
|
birthday: Date;
|
||||||
parentId: string;
|
parentId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CaregiverProfile extends UserProfile {
|
export interface CaregiverProfile extends UserProfile {
|
||||||
userType: "caregiver";
|
userType: ProfileType.CAREGIVER;
|
||||||
//assignedChildrenId: string[];
|
|
||||||
contact: string;
|
contact: string;
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import {useMutation} from "react-query";
|
import {useMutation} from "react-query";
|
||||||
import auth from "@react-native-firebase/auth";
|
import auth from "@react-native-firebase/auth";
|
||||||
import {useUpdateUserData} from "@/hooks/firebase/useUpdateUserData";
|
import {useUpdateUserData} from "@/hooks/firebase/useUpdateUserData";
|
||||||
|
import {ProfileType} from "@/contexts/AuthContext";
|
||||||
|
|
||||||
export const useSignUp = () => {
|
export const useSignUp = () => {
|
||||||
const { mutateAsync: updateUserData } = useUpdateUserData()
|
const { mutateAsync: updateUserData } = useUpdateUserData()
|
||||||
@ -9,7 +10,7 @@ export const useSignUp = () => {
|
|||||||
mutationKey: ["signUp"],
|
mutationKey: ["signUp"],
|
||||||
mutationFn: async ({email, password}: { email: string, password: string }) => {
|
mutationFn: async ({email, password}: { email: string, password: string }) => {
|
||||||
await auth().createUserWithEmailAndPassword(email, password)
|
await auth().createUserWithEmailAndPassword(email, password)
|
||||||
await updateUserData({userType: "parent", email, password})
|
await updateUserData({userType: ProfileType.PARENT, email, password})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
Reference in New Issue
Block a user