birthday through qr, deleteFam function

This commit is contained in:
ivic00
2025-02-12 00:05:39 +01:00
parent 6ada9470c3
commit a8957c7ac7
6 changed files with 247 additions and 196 deletions

View File

@ -0,0 +1,32 @@
import { useAuthContext } from "@/contexts/AuthContext";
import { useMutation } from "@tanstack/react-query";
import functions from '@react-native-firebase/functions';
import { Alert } from 'react-native';
export const useDeleteFamily = () => {
const { user } = useAuthContext();
return useMutation({
mutationKey: ["deleteFamily"],
mutationFn: async ({ familyId }: { familyId: string }) => {
if (!user) {
throw new Error('User must be logged in');
}
try {
const deleteFamilyFunction = functions().httpsCallable('deleteFamily');
const result = await deleteFamilyFunction({ familyId });
return result.data;
} catch (error: any) {
if (error.code === 'permission-denied') {
Alert.alert('Error', 'Only parents can delete families');
} else if (error.code === 'unauthenticated') {
Alert.alert('Error', 'Please log in to perform this action');
} else {
Alert.alert('Error', 'Failed to delete family. Please try again.');
}
throw error;
}
}
});
};