51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { detectionsApi, DetectionsListResponse } from '../api/client';
|
|
|
|
interface UseDetectionsParams {
|
|
page?: number;
|
|
page_size?: number;
|
|
threat_level?: string;
|
|
model_name?: string;
|
|
country_code?: string;
|
|
asn_number?: string;
|
|
search?: string;
|
|
sort_by?: string;
|
|
sort_order?: string;
|
|
group_by_ip?: boolean;
|
|
}
|
|
|
|
export function useDetections(params: UseDetectionsParams = {}) {
|
|
const [data, setData] = useState<DetectionsListResponse | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<Error | null>(null);
|
|
|
|
useEffect(() => {
|
|
const fetchDetections = async () => {
|
|
setLoading(true);
|
|
try {
|
|
const response = await detectionsApi.getDetections(params);
|
|
setData(response.data);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err : new Error('Erreur inconnue'));
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
fetchDetections();
|
|
}, [
|
|
params.page,
|
|
params.page_size,
|
|
params.threat_level,
|
|
params.model_name,
|
|
params.country_code,
|
|
params.asn_number,
|
|
params.search,
|
|
params.sort_by,
|
|
params.sort_order,
|
|
params.group_by_ip,
|
|
]);
|
|
|
|
return { data, loading, error };
|
|
}
|