mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
27 lines
1011 B
TypeScript
27 lines
1011 B
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import functions from '@react-native-firebase/functions';
|
|
import { ProfileType, useAuthContext } from "@/contexts/AuthContext";
|
|
import { HttpsCallableResult } from "@firebase/functions";
|
|
|
|
export const useRemoveSubUser = () => {
|
|
const queryClient = useQueryClient();
|
|
const { profileType, profileData } = useAuthContext();
|
|
|
|
return useMutation({
|
|
mutationKey: ["removeSubUser"],
|
|
mutationFn: async (userId: string) => {
|
|
if (profileType === ProfileType.PARENT) {
|
|
return await functions().httpsCallable("removeSubUser")({
|
|
userId,
|
|
familyId: profileData?.familyId!,
|
|
}) as HttpsCallableResult<{ success: boolean }>;
|
|
} else {
|
|
throw Error("Can't remove sub-users as a non-parent.");
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["getChildrenByParentId"] });
|
|
queryClient.invalidateQueries({ queryKey: ["familyMembers"] });
|
|
},
|
|
});
|
|
}; |