From 9907213dd8415eadeac2636a61b3a0bbf0604055 Mon Sep 17 00:00:00 2001 From: smanylov Date: Wed, 18 Mar 2026 18:09:33 +0700 Subject: [PATCH] add token for fetch violation list --- src/app/actions/violationActions.ts | 41 ++++++++++++++++++- .../react-query/useViolationGeography.ts | 24 +++++++++++ .../ui/reports/analytics-carв-geography.tsx | 2 + src/app/ui/search/search-stats.tsx | 2 +- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/app/hooks/react-query/useViolationGeography.ts diff --git a/src/app/actions/violationActions.ts b/src/app/actions/violationActions.ts index 784cccb..5419470 100644 --- a/src/app/actions/violationActions.ts +++ b/src/app/actions/violationActions.ts @@ -148,6 +148,7 @@ export async function fetchViolationStats() { } export async function getFileViolations(fileId: string, page: number) { + const token = await getSessionData('token'); try { const response = await fetch(`${API_BASE_URL}/api/v1/data`, { @@ -159,7 +160,8 @@ export async function getFileViolations(fileId: string, page: number) { file_id: fileId, page: page, size: 5, - sort_direction: "desc" + sort_direction: "desc", + token: token } }), headers: { @@ -182,4 +184,41 @@ export async function getFileViolations(fileId: string, page: number) { } catch (error) { return null } +} + +export async function fetchViolationGeography() { + const token = await getSessionData('token'); + + /* "group_by": "tld" */ + + try { + const response = await fetch(`${API_BASE_URL}/api/v1/data`, { + method: 'POST', + body: JSON.stringify({ + version: 1, + msg_id: 30009, + message_body: { + group_by: "domain", + token: token + } + }), + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }); + + if (response.ok) { + let parsed = await response.json(); + if (parsed) { + return parsed; + } else { + throw null; + } + } else { + throw (`${response.status}`); + } + } catch (error) { + return null + } } \ No newline at end of file diff --git a/src/app/hooks/react-query/useViolationGeography.ts b/src/app/hooks/react-query/useViolationGeography.ts new file mode 100644 index 0000000..9d758b2 --- /dev/null +++ b/src/app/hooks/react-query/useViolationGeography.ts @@ -0,0 +1,24 @@ +import { useQuery } from '@tanstack/react-query'; +import { fetchViolationGeography } from '@/app/actions/violationActions'; + +export interface UseViolationGeography { + ru: number; + usa: number; + uk: number; + ge: number; +} + +export const useViolationGeography = () => { + return useQuery({ + queryKey: ['violationGeography'], + queryFn: fetchViolationGeography, + select: (data): any | null => { + if (!data) { + return [] + } + + return data; + }, + retry: false + }); +}; \ No newline at end of file diff --git a/src/app/ui/reports/analytics-carв-geography.tsx b/src/app/ui/reports/analytics-carв-geography.tsx index 01e63b8..32fbb0a 100644 --- a/src/app/ui/reports/analytics-carв-geography.tsx +++ b/src/app/ui/reports/analytics-carв-geography.tsx @@ -1,9 +1,11 @@ 'use client' import { useTranslations } from 'next-intl' +import {useViolationGeography} from '@/app/hooks/react-query/useViolationGeography'; export default function AnalyticsCardGeography() { const t = useTranslations('Global'); + const { data: violationGeography, isLoading, isError, error } = useViolationGeography(); return (
diff --git a/src/app/ui/search/search-stats.tsx b/src/app/ui/search/search-stats.tsx index 07b4011..b9d0019 100644 --- a/src/app/ui/search/search-stats.tsx +++ b/src/app/ui/search/search-stats.tsx @@ -5,7 +5,7 @@ import { useTranslations } from 'next-intl'; import { useEffect } from 'react'; export function SearchStats() { - const { data: userSearchData, isLoading, isError, error, } = useUserSearchData(); + const { data: userSearchData, isLoading, isError, error } = useUserSearchData(); const t = useTranslations('Global'); useEffect(() => {