mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 01:56:16 +00:00
birthday through qr, deleteFam function
This commit is contained in:
32
hooks/firebase/useDeleteFamily.ts
Normal file
32
hooks/firebase/useDeleteFamily.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user