continue: work on violation page
This commit is contained in:
@@ -5,7 +5,6 @@ import { API_BASE_URL } from '@/app/actions/definitions';
|
|||||||
|
|
||||||
export async function getViolationSearchStatus() {
|
export async function getViolationSearchStatus() {
|
||||||
const token = await getSessionData('token');
|
const token = await getSessionData('token');
|
||||||
console.log('getViolationSearchStatus');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/actual-task`, {
|
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/actual-task`, {
|
||||||
@@ -16,14 +15,25 @@ export async function getViolationSearchStatus() {
|
|||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* console.log(response); */
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
console.log('parsed');
|
const text = await response.text();
|
||||||
const parsed = await response.json();
|
|
||||||
console.log(parsed);
|
if (text) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(text);
|
||||||
|
console.log('Parsed:', parsed);
|
||||||
|
return parsed;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Not JSON, raw text:', text);
|
||||||
|
return {
|
||||||
|
status: text === 'Task not found' ? 'task-not-found' : text
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return parsed
|
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -40,19 +50,25 @@ export async function startGlobalMonitoring(monitoringType: 'monitoring' | 'all_
|
|||||||
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/start`, {
|
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/start`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
searchType: monitoringType
|
searchType: monitoringType,
|
||||||
|
...(monitoringType === 'all_files' && { fileIds: [] })
|
||||||
|
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(response);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const parsed = await response.json();
|
const parsed: {
|
||||||
|
taskId: string,
|
||||||
|
status: string,
|
||||||
|
totalFiles: number
|
||||||
|
} = await response.json();
|
||||||
|
|
||||||
console.log(parsed);
|
console.log(parsed);
|
||||||
if (parsed?.message_code === 0) {
|
if (parsed?.status === 'ACCEPTED') {
|
||||||
return parsed
|
return parsed
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -1,11 +1,32 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { getViolationSearchStatus, startGlobalMonitoring } from '@/app/actions/violationActions';
|
import { getViolationSearchStatus, startGlobalMonitoring } from '@/app/actions/violationActions';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import ModalWindow from '@/app/components/ModalWindow';
|
import ModalWindow from '@/app/components/ModalWindow';
|
||||||
import { fa } from 'zod/v4/locales';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
/* {
|
||||||
|
taskId: "9647fcd6-cf9b-4503-b399-b8d53794cd49",
|
||||||
|
userId: 1,
|
||||||
|
searchType: "all_files",
|
||||||
|
status: "PROCESSING",
|
||||||
|
totalFiles: 2,
|
||||||
|
processedFiles: 0,
|
||||||
|
createdAt: "2026-03-13T05:21:39.850518",
|
||||||
|
updatedAt: null
|
||||||
|
} */
|
||||||
|
interface violationSearchStatus {
|
||||||
|
taskId?: string,
|
||||||
|
userId?: number,
|
||||||
|
searchType?: 'all_files' | 'monitoring',
|
||||||
|
status: string,
|
||||||
|
totalFiles?: number,
|
||||||
|
processedFiles?: number,
|
||||||
|
createdAt?: string,
|
||||||
|
updatedAt?: null
|
||||||
|
}
|
||||||
|
|
||||||
export default function ViolationsCheckAllSection() {
|
export default function ViolationsCheckAllSection() {
|
||||||
const {
|
const {
|
||||||
@@ -18,20 +39,32 @@ export default function ViolationsCheckAllSection() {
|
|||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
return getViolationSearchStatus();
|
return getViolationSearchStatus();
|
||||||
},
|
},
|
||||||
select: (data) => {
|
select: (data: violationSearchStatus) => {
|
||||||
/* console.log(data); */
|
console.log('violationSearchStatus');
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
refetchInterval: (query) => {
|
||||||
|
const status = query.state.data?.status;
|
||||||
|
if (status === 'PROCESSING') {
|
||||||
|
return 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const t = useTranslations('Global');
|
const queryClient = useQueryClient();
|
||||||
const [isProcessing, setIsProcessing] = useState<boolean>(false);
|
const [isProcessing, setIsProcessing] = useState<boolean>(false);
|
||||||
const [openWindow, setOpenWindow] = useState<boolean>(false);
|
const [openWindow, setOpenWindow] = useState<boolean>(false);
|
||||||
|
const t = useTranslations('Global');
|
||||||
|
|
||||||
function openModalWindow() {
|
async function openModalWindow() {
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['violationSearchStatus'] });
|
||||||
setOpenWindow(true);
|
setOpenWindow(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +73,14 @@ export default function ViolationsCheckAllSection() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await startGlobalMonitoring(type);
|
const response = await startGlobalMonitoring(type);
|
||||||
|
if (response?.taskId) {
|
||||||
|
toast.success(t('file-verification-started-successfully'));
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['violationSearchStatus'] });
|
||||||
|
} else {
|
||||||
|
throw 'error'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
toast.error(t('an-error-occurred-while-starting-file-verification'));
|
||||||
} finally {
|
} finally {
|
||||||
setIsProcessing(false);
|
setIsProcessing(false);
|
||||||
setOpenWindow(false);
|
setOpenWindow(false);
|
||||||
@@ -96,6 +135,11 @@ export default function ViolationsCheckAllSection() {
|
|||||||
<div className="check-all-description">
|
<div className="check-all-description">
|
||||||
Поиск нарушений во всех ваших изображениях. Проверка только точных совпадений (95%+).
|
Поиск нарушений во всех ваших изображениях. Проверка только точных совпадений (95%+).
|
||||||
</div>
|
</div>
|
||||||
|
{violationSearchStatus?.status && (
|
||||||
|
<div>
|
||||||
|
{violationSearchStatus?.status}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -299,7 +299,9 @@
|
|||||||
"select-a-token-package": "Select a token package",
|
"select-a-token-package": "Select a token package",
|
||||||
"package-selected-tokens-price": "Package selected: {tokens} tokens for {price}₽",
|
"package-selected-tokens-price": "Package selected: {tokens} tokens for {price}₽",
|
||||||
"purchasing-tokens": "Purchasing tokens",
|
"purchasing-tokens": "Purchasing tokens",
|
||||||
"payment-of-the-tariff": "Payment of the tariff"
|
"payment-of-the-tariff": "Payment of the tariff",
|
||||||
|
"file-verification-started-successfully": "File verification started successfully.",
|
||||||
|
"an-error-occurred-while-starting-file-verification": "An error occurred while starting file verification."
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "and",
|
"and": "and",
|
||||||
|
|||||||
@@ -299,7 +299,9 @@
|
|||||||
"select-a-token-package": "Выберите пакет токенов",
|
"select-a-token-package": "Выберите пакет токенов",
|
||||||
"package-selected-tokens-price": "Выбран пакет: {tokens} токенов за {price}₽",
|
"package-selected-tokens-price": "Выбран пакет: {tokens} токенов за {price}₽",
|
||||||
"purchasing-tokens": "Покупка токенов",
|
"purchasing-tokens": "Покупка токенов",
|
||||||
"payment-of-the-tariff": "Оплата тарифа"
|
"payment-of-the-tariff": "Оплата тарифа",
|
||||||
|
"file-verification-started-successfully": "Проверка файлов успешно запущена.",
|
||||||
|
"an-error-occurred-while-starting-file-verification": "При запуске проверки файлов произошла ошибка."
|
||||||
},
|
},
|
||||||
"Login-register-form": {
|
"Login-register-form": {
|
||||||
"and": "и",
|
"and": "и",
|
||||||
|
|||||||
Reference in New Issue
Block a user