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) {
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: {
@@ -183,3 +185,40 @@ export async function getFileViolations(fileId: string, page: number) {
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'
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 (
<div className="analytics-card">
+1 -1
View File
@@ -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(() => {