Files
no-copy-frontend/src/app/ui/violations/file-page/violation-page-violations-list.tsx
T

256 lines
6.1 KiB
TypeScript
Raw Normal View History

2026-03-16 17:12:52 +07:00
// app/ui/violations/file-page/violation-page-violations-list.tsx
'use client'
import { useTranslations } from 'next-intl';
2026-03-17 12:17:26 +07:00
import Link from 'next/link';
2026-03-16 17:12:52 +07:00
import { useRouter, usePathname } from 'next/navigation';
2026-03-17 18:41:02 +07:00
import { useEffect, useState } from 'react';
import { formatDate } from '@/app/lib/formatDate';
import ViolationPageNote from '@/app/ui/violations/file-page/violation-page-note';
2026-03-16 17:12:52 +07:00
interface ViolationFileDetail {
id: number;
url: string;
page_url: string;
page_title: string;
host: string;
status: string;
created_date: string;
file_id: string;
}
interface ViolationFile {
violations: ViolationFileDetail[],
total_elements: number,
total_pages: number,
current_page: number,
page_size: number,
has_next: boolean,
has_previous: boolean
}
export default function ViolationPageViolationsList({
fileViolations,
currentPage,
fileId
}: {
fileViolations: ViolationFile,
currentPage: number,
fileId: string
}) {
const t = useTranslations('Global');
const router = useRouter();
const pathname = usePathname();
2026-03-17 18:41:02 +07:00
const [selectedViolation, setSelectedViolation] = useState<ViolationFileDetail | null>(null);
2026-03-16 17:12:52 +07:00
if (!fileViolations?.violations) {
return null;
}
const handlePageChange = (page: number) => {
2026-03-17 18:41:02 +07:00
router.push(`${pathname}?page=${page}`, { scroll: false });
2026-03-16 17:12:52 +07:00
};
const getPageNumbers = () => {
const pages = [];
const maxVisible = 5;
const total = fileViolations.total_pages;
let start = Math.max(1, currentPage - Math.floor(maxVisible / 2));
let end = Math.min(total, start + maxVisible - 1);
if (end - start + 1 < maxVisible) {
start = Math.max(1, end - maxVisible + 1);
}
for (let i = start; i <= end; i++) {
pages.push(i);
}
return pages;
};
2026-03-17 18:41:02 +07:00
function selectHandler(violation: ViolationFileDetail) {
setSelectedViolation(violation);
}
2026-03-02 18:57:52 +07:00
return (
2026-03-16 17:12:52 +07:00
<div className="block-wrapper">
2026-03-02 18:57:52 +07:00
<div className="card-header">
<h3 className="card-title">
2026-03-17 18:41:02 +07:00
{t('all-file-violations')}
2026-03-02 18:57:52 +07:00
</h3>
<span>
2026-03-17 18:41:02 +07:00
{t('total-violations')}: {fileViolations.total_elements} | {t('page')} {fileViolations.current_page} {t('out-of')} {fileViolations.total_pages}
2026-03-02 18:57:52 +07:00
</span>
</div>
2026-03-17 18:41:02 +07:00
<div
className="sources-list-wrapper"
>
<div className="sources-list">
{fileViolations.violations.map(item => {
return (
<div
className={`source-card ${selectedViolation?.id === item.id ? 'selected' : ''}`}
key={item.id}
onClick={() => {
selectHandler(item);
}}
>
{/* <div className="source-header">
<div className="source-image">
<img src={item.url} alt="" />
</div>
</div> */}
<div
className="source-header-left"
>
<div className="source-image">
<img src={item.url} alt="" />
</div>
<div>
<span
className="source-meta"
>
{t('source')}:
</span>
<span className="source-url">
{item.host}
</span>
</div>
</div>
<div
className="source-header-right"
>
<span className="source-status new">
{item.status}
</span>
<div className="source-actions">
<Link
href={item.page_url}
className="btn-small btn-primary-small"
target="_blank"
scroll={false}
>
{t('open')}
</Link>
</div>
</div>
2026-03-16 17:12:52 +07:00
</div>
2026-03-17 18:41:02 +07:00
);
})}
</div>
<div
className="violation-info"
>
<div
className="violation-info-grid"
>
<div
className="violation-info-content"
>
<h3
className="violation-info-title"
>
{selectedViolation?.page_title}
</h3>
<div
className="violation-info-image"
>
<img src={selectedViolation?.url} alt={selectedViolation?.page_title} />
</div>
<div
className="violation-info-source"
>
<span>
{t('source')}:
2026-03-16 17:12:52 +07:00
</span>
2026-03-17 12:17:26 +07:00
<Link
2026-03-17 18:41:02 +07:00
href={selectedViolation?.page_url ? selectedViolation?.page_url : '#'}
className="source"
2026-03-16 17:12:52 +07:00
target="_blank"
2026-03-17 12:17:26 +07:00
scroll={false}
2026-03-16 17:12:52 +07:00
>
2026-03-17 18:41:02 +07:00
{selectedViolation?.page_url}
2026-03-17 12:17:26 +07:00
</Link>
2026-03-16 17:12:52 +07:00
</div>
2026-03-17 18:41:02 +07:00
<div
className="violation-info-source"
>
<span>
{t('date')} {selectedViolation?.created_date ? formatDate(selectedViolation?.created_date) : '#'}
</span>
</div>
<div>
{selectedViolation?.status}
</div>
2026-03-02 18:57:52 +07:00
2026-03-17 18:59:04 +07:00
<div
className="mt-auto"
>
Тут думаю нужно будет отображать инфу о работе с нарушением и её статус
</div>
2026-03-17 18:41:02 +07:00
</div>
<div
className="violation-info-actions"
>
<div className="action-buttons">
<button type="button" className="btn-action btn-warning">
Взять в работу
</button>
<button type="button" className="btn-action btn-success">
Отметить решенным
</button>
<button type="button" className="btn-action btn-secondary">
Ложное срабатывание
</button>
</div>
</div>
</div>
2026-03-17 18:59:04 +07:00
{/* <ViolationPageNote /> */}
2026-03-17 18:41:02 +07:00
</div>
</div>
2026-03-16 17:12:52 +07:00
{fileViolations.total_pages > 1 && (
<div className="pagination">
2026-03-17 18:41:02 +07:00
<button
onClick={() => handlePageChange(currentPage - 1)}
className="pagination-item pagination-item-prev"
disabled={!fileViolations.has_previous}
>
{t('previous')}
</button>
2026-03-16 17:12:52 +07:00
{getPageNumbers().map(pageNum => (
<button
key={pageNum}
onClick={() => handlePageChange(pageNum)}
2026-03-17 18:41:02 +07:00
className={`pagination-item ${currentPage === pageNum ? 'pagination-item-active' : ''}`}
2026-03-16 17:12:52 +07:00
>
{pageNum}
</button>
))}
2026-03-17 18:41:02 +07:00
<button
onClick={() => handlePageChange(currentPage + 1)}
className="pagination-item pagination-item-next"
disabled={!fileViolations.has_next}
>
{t('next')}
</button>
2026-03-16 17:12:52 +07:00
</div>
)}
2026-03-02 18:57:52 +07:00
</div>
2026-03-16 17:12:52 +07:00
);
2026-03-02 18:57:52 +07:00
}