add token for fetch violation list

This commit is contained in:
smanylov
2026-03-18 18:09:33 +07:00
parent 89e288c591
commit 9907213dd8
4 changed files with 67 additions and 2 deletions
+40 -1
View File
@@ -148,6 +148,7 @@ export async function fetchViolationStats() {
} }
export async function getFileViolations(fileId: string, page: number) { export async function getFileViolations(fileId: string, page: number) {
const token = await getSessionData('token');
try { try {
const response = await fetch(`${API_BASE_URL}/api/v1/data`, { 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, file_id: fileId,
page: page, page: page,
size: 5, size: 5,
sort_direction: "desc" sort_direction: "desc",
token: token
} }
}), }),
headers: { headers: {
@@ -182,4 +184,41 @@ export async function getFileViolations(fileId: string, page: number) {
} catch (error) { } catch (error) {
return null 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
}
} }
@@ -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
});
};
@@ -1,9 +1,11 @@
'use client' 'use client'
import { useTranslations } from 'next-intl' import { useTranslations } from 'next-intl'
import {useViolationGeography} from '@/app/hooks/react-query/useViolationGeography';
export default function AnalyticsCardGeography() { export default function AnalyticsCardGeography() {
const t = useTranslations('Global'); const t = useTranslations('Global');
const { data: violationGeography, isLoading, isError, error } = useViolationGeography();
return ( return (
<div className="analytics-card"> <div className="analytics-card">
+1 -1
View File
@@ -5,7 +5,7 @@ import { useTranslations } from 'next-intl';
import { useEffect } from 'react'; import { useEffect } from 'react';
export function SearchStats() { export function SearchStats() {
const { data: userSearchData, isLoading, isError, error, } = useUserSearchData(); const { data: userSearchData, isLoading, isError, error } = useUserSearchData();
const t = useTranslations('Global'); const t = useTranslations('Global');
useEffect(() => { useEffect(() => {