Improve the frontend 2

This commit is contained in:
Urtzi Alfaro
2025-10-29 06:58:05 +01:00
parent 858d985c92
commit 36217a2729
98 changed files with 6652 additions and 4230 deletions

View File

@@ -6,7 +6,7 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { toast } from 'react-hot-toast';
import { equipmentService } from '../services/equipment';
import type { Equipment } from '../types/equipment';
import type { Equipment, EquipmentDeletionSummary } from '../types/equipment';
// Query Keys
export const equipmentKeys = {
@@ -114,7 +114,7 @@ export function useUpdateEquipment(tenantId: string) {
}
/**
* Hook to delete equipment
* Hook to delete equipment (soft delete)
*/
export function useDeleteEquipment(tenantId: string) {
const queryClient = useQueryClient();
@@ -139,3 +139,46 @@ export function useDeleteEquipment(tenantId: string) {
},
});
}
/**
* Hook to hard delete equipment (permanent deletion)
*/
export function useHardDeleteEquipment(tenantId: string) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (equipmentId: string) =>
equipmentService.hardDeleteEquipment(tenantId, equipmentId),
onSuccess: (_, equipmentId) => {
// Remove from cache
queryClient.removeQueries({
queryKey: equipmentKeys.detail(tenantId, equipmentId)
});
// Invalidate lists to refresh
queryClient.invalidateQueries({ queryKey: equipmentKeys.lists() });
toast.success('Equipment permanently deleted');
},
onError: (error: any) => {
console.error('Error hard deleting equipment:', error);
toast.error(error.response?.data?.detail || 'Error permanently deleting equipment');
},
});
}
/**
* Hook to get equipment deletion summary
*/
export function useEquipmentDeletionSummary(
tenantId: string,
equipmentId: string,
options?: { enabled?: boolean }
) {
return useQuery({
queryKey: [...equipmentKeys.detail(tenantId, equipmentId), 'deletion-summary'],
queryFn: () => equipmentService.getEquipmentDeletionSummary(tenantId, equipmentId),
enabled: !!tenantId && !!equipmentId && (options?.enabled ?? true),
staleTime: 0, // Always fetch fresh data for dependency checks
});
}