Adding and displaying family members

This commit is contained in:
Milan Paunovic
2024-09-28 19:08:09 +02:00
parent 594e54b11b
commit 92f335543f
7 changed files with 189 additions and 149 deletions

View File

@ -5,13 +5,16 @@ import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
export const useCreateSubUser = () => {
const queryClient = useQueryClient()
const { profileType } = useAuthContext()
const {profileType, profileData} = useAuthContext()
return useMutation({
mutationKey: ["createSubUser"],
mutationFn: async ({email, ...userProfile}: { email: string } & UserProfile) => {
if(profileType === ProfileType.PARENT) {
return await functions().httpsCallable("createSubUser")({email, ...userProfile})
if (profileType === ProfileType.PARENT) {
return await functions().httpsCallable("createSubUser")({
email,
userProfile: {...userProfile, familyId: profileData?.familyId}
})
} else {
throw Error("Can't create sub-users as a non-parent.")
}