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

218 lines
5.8 KiB
TypeScript
Raw Normal View History

2026-03-16 17:12:52 +07:00
'use client'
import { useTranslations } from 'next-intl';
2026-03-17 12:17:26 +07:00
import Link from 'next/link';
2026-03-27 17:22:09 +07:00
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
import { useState } from 'react';
import FilePageViolationInfo from '@/app/ui/file-page/violation-table/file-page-violation-info';
import { useFileViolations } from '@/app/hooks/react-query/useFileViolations';
import { ViolationFileDetail } from '@/app/hooks/react-query/useFileViolations';
2026-03-27 17:22:09 +07:00
import DropDownList from '@/app/components/DropDownList';
import { IconArrowLeft, IconArrowRight } from '@/app/ui/icons/icons';
2026-03-16 17:12:52 +07:00
2026-03-26 11:56:36 +07:00
export default function FilePageViolationsList({
2026-03-16 17:12:52 +07:00
currentPage,
2026-03-27 17:22:09 +07:00
fileId,
status
2026-03-16 17:12:52 +07:00
}: {
currentPage: number,
2026-03-27 17:22:09 +07:00
fileId: string,
status: string | undefined
2026-03-16 17:12:52 +07:00
}) {
const t = useTranslations('Global');
2026-03-27 12:53:52 +07:00
const tStatus = useTranslations('Match-status');
2026-03-16 17:12:52 +07:00
const router = useRouter();
const pathname = usePathname();
2026-03-27 17:22:09 +07:00
const searchParams = useSearchParams();
2026-03-17 18:41:02 +07:00
const [selectedViolation, setSelectedViolation] = useState<ViolationFileDetail | null>(null);
2026-03-27 17:22:09 +07:00
const { data: fileViolations } = useFileViolations(fileId, currentPage, status);
2026-03-16 17:12:52 +07:00
if (!fileViolations?.violations) {
return null;
}
const handlePageChange = (page: number) => {
2026-03-27 17:22:09 +07:00
const params = new URLSearchParams(searchParams);
params.set('page', page.toString());
router.push(`${pathname}?${params.toString()}`, { scroll: false });
};
const handleStatusChange = (status: string) => {
const params = new URLSearchParams(searchParams);
if (status) {
params.set('status', status);
} else {
params.delete('status');
}
setSelectedViolation(null);
2026-03-27 17:22:09 +07:00
params.set('page', '1');
router.push(`${pathname}?${params.toString()}`, { 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>
2026-03-27 17:22:09 +07:00
<div className="flex items-center gap-4">
<div
className="status-filter-select"
>
<DropDownList
value={status ? tStatus(status) : t('all-statuses')}
callBack={handleStatusChange}
>
<li value=''>{t('all-statuses')}</li>
<li value="NEW">{tStatus('NEW')}</li>
<li value="SHOWED">{tStatus('SHOWED')}</li>
<li value="LEGAL_IN_WORK">{tStatus('LEGAL_IN_WORK')}</li>
<li value="COMPLAINT_IN_WORK">{tStatus('COMPLAINT_IN_WORK')}</li>
<li value="COMPLAINT_AND_LEGAL_IN_WORK">{tStatus('COMPLAINT_AND_LEGAL_IN_WORK')}</li>
<li value="AUTHORIZED_USE">{tStatus('AUTHORIZED_USE')}</li>
</DropDownList>
</div>
</div>
2026-03-02 18:57:52 +07:00
</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-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"
>
2026-03-27 12:53:52 +07:00
{item.status === "COMPLAINT_AND_LEGAL_IN_WORK" ? (
<>
<span className="source-status legal_in_work">
2026-03-27 13:50:41 +07:00
{tStatus('LEGAL_IN_WORK')}
2026-03-27 12:53:52 +07:00
</span>
<span className="source-status complaint_in_work">
2026-03-27 13:50:41 +07:00
{tStatus('COMPLAINT_IN_WORK')}
2026-03-27 12:53:52 +07:00
</span>
</>
) : (
<span className={`source-status ${item.status.toLowerCase()}`}>
{tStatus(item.status)}
</span>
)}
2026-03-17 18:41:02 +07:00
<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>
{/* general info for match */}
<FilePageViolationInfo selectedViolation={selectedViolation} />
2026-03-17 18:41:02 +07:00
</div>
<div
className="sources-list-pagination"
>
<span>
{t('total-violations')}: {fileViolations.total_elements} | {t('page')} {fileViolations.current_page} {t('out-of')} {fileViolations.total_pages}
</span>
{fileViolations.total_pages > 1 && (
<div className="pagination-controls">
2026-03-16 17:12:52 +07:00
<button
onClick={() => handlePageChange(currentPage - 1)}
className="arrow"
disabled={!fileViolations.has_previous}
2026-03-16 17:12:52 +07:00
>
<IconArrowLeft />
2026-03-16 17:12:52 +07:00
</button>
<div
className="pagination-controls-pages"
>
{getPageNumbers().map(pageNum => (
<button
key={pageNum}
onClick={() => handlePageChange(pageNum)}
/* className={`pagination-item ${currentPage === pageNum ? 'pagination-item-active' : ''}`} */
className={currentPage === pageNum ? 'current' : 'other'}
>
{pageNum}
</button>
))}
</div>
<button
onClick={() => handlePageChange(currentPage + 1)}
className="arrow"
disabled={!fileViolations.has_next}
>
<IconArrowRight />
</button>
</div>
)}
</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
}