add token for fetch violation list
This commit is contained in:
@@ -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: {
|
||||||
@@ -183,3 +185,40 @@ export async function getFileViolations(fileId: string, page: number) {
|
|||||||
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">
|
||||||
|
|||||||
@@ -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(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user