2026-03-12 17:44:02 +07:00
|
|
|
|
'use client'
|
|
|
|
|
|
|
2026-03-13 13:42:07 +07:00
|
|
|
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
2026-03-12 17:44:02 +07:00
|
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
|
|
|
import { getViolationSearchStatus, startGlobalMonitoring } from '@/app/actions/violationActions';
|
2026-03-16 17:12:52 +07:00
|
|
|
|
import { useEffect, useRef, useState } from 'react';
|
2026-03-12 17:44:02 +07:00
|
|
|
|
import ModalWindow from '@/app/components/ModalWindow';
|
2026-03-13 13:42:07 +07:00
|
|
|
|
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
|
|
|
|
|
|
}
|
2026-03-12 17:44:02 +07:00
|
|
|
|
|
2026-01-15 14:18:08 +07:00
|
|
|
|
export default function ViolationsCheckAllSection() {
|
2026-03-12 17:44:02 +07:00
|
|
|
|
const {
|
|
|
|
|
|
data: violationSearchStatus,
|
|
|
|
|
|
isLoading,
|
|
|
|
|
|
isError,
|
|
|
|
|
|
error
|
|
|
|
|
|
} = useQuery({
|
|
|
|
|
|
queryKey: ['violationSearchStatus'],
|
|
|
|
|
|
queryFn: () => {
|
|
|
|
|
|
return getViolationSearchStatus();
|
|
|
|
|
|
},
|
2026-03-13 13:42:07 +07:00
|
|
|
|
select: (data: violationSearchStatus) => {
|
2026-03-12 17:44:02 +07:00
|
|
|
|
if (data) {
|
|
|
|
|
|
return data;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
2026-03-13 13:42:07 +07:00
|
|
|
|
},
|
|
|
|
|
|
refetchInterval: (query) => {
|
|
|
|
|
|
const status = query.state.data?.status;
|
|
|
|
|
|
if (status === 'PROCESSING') {
|
|
|
|
|
|
return 10000;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
2026-03-12 17:44:02 +07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-03-13 13:42:07 +07:00
|
|
|
|
const queryClient = useQueryClient();
|
2026-03-12 17:44:02 +07:00
|
|
|
|
const [isProcessing, setIsProcessing] = useState<boolean>(false);
|
|
|
|
|
|
const [openWindow, setOpenWindow] = useState<boolean>(false);
|
2026-03-13 13:42:07 +07:00
|
|
|
|
const t = useTranslations('Global');
|
2026-03-16 17:12:52 +07:00
|
|
|
|
const previousStatusRef = useRef<string | undefined>('');
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const currentStatus = violationSearchStatus?.status;
|
|
|
|
|
|
const previousStatus = previousStatusRef.current;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentStatus === 'task-not-found' && previousStatus === 'PROCESSING') {
|
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['violationData'] });
|
|
|
|
|
|
toast.success(t('violation-data-updated'));
|
|
|
|
|
|
}
|
|
|
|
|
|
previousStatusRef.current = currentStatus;
|
|
|
|
|
|
}, [violationSearchStatus?.status, queryClient]);
|
2026-03-12 17:44:02 +07:00
|
|
|
|
|
2026-03-13 13:42:07 +07:00
|
|
|
|
async function openModalWindow() {
|
|
|
|
|
|
await queryClient.invalidateQueries({ queryKey: ['violationSearchStatus'] });
|
2026-03-12 17:44:02 +07:00
|
|
|
|
setOpenWindow(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function handlerStartMonitoring(type: 'monitoring' | 'all_files') {
|
|
|
|
|
|
setIsProcessing(true);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await startGlobalMonitoring(type);
|
2026-03-13 13:42:07 +07:00
|
|
|
|
if (response?.taskId) {
|
|
|
|
|
|
toast.success(t('file-verification-started-successfully'));
|
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['violationSearchStatus'] });
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw 'error'
|
|
|
|
|
|
}
|
2026-03-12 17:44:02 +07:00
|
|
|
|
} catch (error) {
|
2026-03-13 13:42:07 +07:00
|
|
|
|
toast.error(t('an-error-occurred-while-starting-file-verification'));
|
2026-03-12 17:44:02 +07:00
|
|
|
|
} finally {
|
|
|
|
|
|
setIsProcessing(false);
|
|
|
|
|
|
setOpenWindow(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ConfirmationModal() {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="modal-window-confirm-payment">
|
|
|
|
|
|
<h3 className="modal-window-confirm-payment-title">
|
|
|
|
|
|
Поиск нарушений во всех ваших изображениях
|
|
|
|
|
|
</h3>
|
|
|
|
|
|
<div className="modal-window-confirm-payment-price">
|
|
|
|
|
|
<div>Варианты проверки.</div>
|
2026-01-15 14:18:08 +07:00
|
|
|
|
</div>
|
2026-03-12 17:44:02 +07:00
|
|
|
|
<div className="flex justify-center gap-4">
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="btn-primary btn-cancel"
|
|
|
|
|
|
disabled={isProcessing}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handlerStartMonitoring('all_files');
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Проверить все
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="btn-primary btn-cancel"
|
|
|
|
|
|
disabled={isProcessing}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handlerStartMonitoring('monitoring');
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Проверить файлы с мониторингом
|
|
|
|
|
|
</button>
|
2026-01-15 14:18:08 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-03-12 17:44:02 +07:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<ModalWindow state={openWindow} callBack={setOpenWindow}>
|
|
|
|
|
|
<ConfirmationModal />
|
|
|
|
|
|
</ModalWindow>
|
|
|
|
|
|
<div className="violation-check-all-section">
|
|
|
|
|
|
|
|
|
|
|
|
<div className="check-all-left">
|
|
|
|
|
|
<div className="check-all-header">
|
|
|
|
|
|
{/* <div className="check-all-icon">🔍</div> */}
|
|
|
|
|
|
<div className="check-all-title">Глобальная проверка контента</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="check-all-description">
|
|
|
|
|
|
Поиск нарушений во всех ваших изображениях. Проверка только точных совпадений (95%+).
|
|
|
|
|
|
</div>
|
2026-03-16 17:12:52 +07:00
|
|
|
|
{(violationSearchStatus?.status !== 'task-not-found') && (
|
2026-03-13 13:42:07 +07:00
|
|
|
|
<div>
|
2026-03-16 17:12:52 +07:00
|
|
|
|
{t('content-verification-status')}: {violationSearchStatus?.status}
|
2026-03-13 13:42:07 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-03-12 17:44:02 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className="check-all-btn"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
openModalWindow()
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Проверить все
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
2026-01-15 14:18:08 +07:00
|
|
|
|
)
|
|
|
|
|
|
}
|