2025-12-12 14:22:00 +07:00
|
|
|
'use client';
|
|
|
|
|
|
2025-12-26 16:10:42 +07:00
|
|
|
import { useState, useMemo, useEffect, ReactNode } from 'react';
|
2025-12-12 14:22:00 +07:00
|
|
|
import {
|
|
|
|
|
useReactTable,
|
|
|
|
|
getCoreRowModel,
|
|
|
|
|
getSortedRowModel,
|
|
|
|
|
getPaginationRowModel,
|
|
|
|
|
getFilteredRowModel,
|
|
|
|
|
ColumnDef,
|
|
|
|
|
SortingState,
|
|
|
|
|
ColumnFiltersState,
|
|
|
|
|
} from '@tanstack/react-table';
|
2026-01-29 16:28:05 +07:00
|
|
|
import { IconEye, IconDoubleArrowRight, IconArrowRight, IconDoubleArrowLeft, IconArrowLeft, IconArrowUp, IconArrowDown, IconFilter, IconFileDownload, IconShieldExclamation } from '@/app/ui/icons/icons';
|
2026-01-15 12:27:39 +07:00
|
|
|
import { useTranslations, useLocale } from 'next-intl';
|
2026-02-04 15:13:17 +07:00
|
|
|
import DropDownList from '@/app/components/DropDownList';
|
2025-12-29 14:00:02 +07:00
|
|
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
2026-01-28 18:53:08 +07:00
|
|
|
import { getUserFilesData, removeUserFile, viewFileInfo } from '@/app/actions/fileEntity';
|
2026-02-04 15:13:17 +07:00
|
|
|
import ModalWindow from '@/app/components/ModalWindow';
|
2025-12-29 14:00:02 +07:00
|
|
|
import { toast } from 'sonner';
|
2026-01-14 15:01:30 +07:00
|
|
|
import { pluralize } from '@/app/lib/pluralize';
|
2026-01-20 20:09:46 +07:00
|
|
|
import { convertBytes } from '@/app/lib/convertBytes';
|
2026-01-28 18:53:08 +07:00
|
|
|
import { FileInfoModalWindow } from '@/app/ui/modal-windows/file-info-modal-window';
|
2026-01-29 16:28:05 +07:00
|
|
|
import { FileTypeIcon } from '@/app/components/FileTypeIcon';
|
2025-12-12 14:22:00 +07:00
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
type FileType = 'image' | 'video' | 'audio';
|
2025-12-29 14:00:02 +07:00
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
type FileItem = {
|
2025-12-26 14:03:57 +07:00
|
|
|
id: string;
|
2025-12-12 20:28:59 +07:00
|
|
|
fileName: string;
|
2025-12-29 14:00:02 +07:00
|
|
|
fileType: string;
|
2025-12-26 14:03:57 +07:00
|
|
|
violations?: number | undefined;
|
2026-01-20 20:09:46 +07:00
|
|
|
size?: number | undefined;
|
|
|
|
|
uploadDate?: number;
|
|
|
|
|
status?: string;
|
2026-01-26 16:09:39 +07:00
|
|
|
protectStatus: string;
|
2025-12-29 14:00:02 +07:00
|
|
|
_original?: ApiFile;
|
2026-01-26 16:38:24 +07:00
|
|
|
supportId: number;
|
2025-12-29 14:00:02 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ApiFile = {
|
|
|
|
|
id: string;
|
|
|
|
|
originalFileName: string;
|
|
|
|
|
mimeType: string;
|
|
|
|
|
violations: number;
|
2026-01-20 20:09:46 +07:00
|
|
|
fileSize: number;
|
2025-12-29 14:00:02 +07:00
|
|
|
updatedAt: string;
|
2026-01-20 20:09:46 +07:00
|
|
|
status: string;
|
2026-01-26 16:09:39 +07:00
|
|
|
protectStatus: string;
|
2026-01-26 16:38:24 +07:00
|
|
|
supportId: number;
|
2026-02-12 16:45:29 +07:00
|
|
|
fileName: string;
|
2025-12-29 14:00:02 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ApiResponse = {
|
|
|
|
|
files?: ApiFile[];
|
2025-12-12 14:22:00 +07:00
|
|
|
};
|
|
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
// Форматирование даты из timestamp
|
|
|
|
|
const formatDate = (timestamp: number) => {
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
const year = date.getFullYear();
|
2025-12-26 14:03:57 +07:00
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
return `${day}.${month}.${year}`;
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-26 14:03:57 +07:00
|
|
|
const formatDateTime = (timestamp: number) => {
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
const hours = date.getHours().toString().padStart(2, '0');
|
|
|
|
|
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
|
|
|
|
|
return `${hours}:${minutes}`;
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-04 17:43:58 +07:00
|
|
|
const cutFileName = (fileName: string) => {
|
2026-01-09 12:35:48 +07:00
|
|
|
const MAX_FILE_NAME_LENGTH = 26;
|
2026-01-04 17:43:58 +07:00
|
|
|
const lastDotIndex = fileName.lastIndexOf('.');
|
|
|
|
|
|
|
|
|
|
if (lastDotIndex <= 0) {
|
2026-01-04 17:44:42 +07:00
|
|
|
return fileName.length > MAX_FILE_NAME_LENGTH ? fileName.substring(0, MAX_FILE_NAME_LENGTH - 3) + '...' : fileName;
|
2026-01-04 17:43:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nameWithoutExtension = fileName.substring(0, lastDotIndex);
|
|
|
|
|
const extension = fileName.substring(lastDotIndex);
|
|
|
|
|
|
2026-01-04 17:44:42 +07:00
|
|
|
if (fileName.length <= MAX_FILE_NAME_LENGTH) {
|
2026-01-21 15:05:02 +07:00
|
|
|
return fileName;
|
2026-01-04 17:43:58 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-04 17:44:42 +07:00
|
|
|
const maxNameLength = MAX_FILE_NAME_LENGTH - extension.length - 3;
|
2026-01-04 17:43:58 +07:00
|
|
|
|
|
|
|
|
if (maxNameLength <= 0) {
|
2026-01-20 20:09:46 +07:00
|
|
|
return '...' /* + extension */;
|
2026-01-04 17:43:58 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-20 20:09:46 +07:00
|
|
|
return nameWithoutExtension.substring(0, maxNameLength) + '...' /* + extension */;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cutFileExtension = (fileName: string) => {
|
|
|
|
|
const lastDotIndex = fileName.lastIndexOf('.');
|
|
|
|
|
const extension = fileName.substring(lastDotIndex + 1);
|
|
|
|
|
return extension;
|
2026-01-04 17:43:58 +07:00
|
|
|
}
|
|
|
|
|
|
2025-12-29 16:08:38 +07:00
|
|
|
export default function TanstakFilesTable({ fileType }: { fileType: string }) {
|
2025-12-26 14:03:57 +07:00
|
|
|
const {
|
2025-12-29 14:00:02 +07:00
|
|
|
data: tableData,
|
2025-12-26 14:03:57 +07:00
|
|
|
isLoading,
|
|
|
|
|
isError,
|
2025-12-26 16:10:42 +07:00
|
|
|
error,
|
2026-01-09 12:35:48 +07:00
|
|
|
} = useQuery<ApiResponse, Error, FileItem[], ['userFilesData', number, number]>({
|
|
|
|
|
queryKey: ['userFilesData', 1, 10000],
|
|
|
|
|
queryFn: () => getUserFilesData(1, 10000),
|
2025-12-26 14:03:57 +07:00
|
|
|
|
2025-12-29 14:00:02 +07:00
|
|
|
select: (data: ApiResponse): FileItem[] => {
|
|
|
|
|
if (!data?.files) return [];
|
2025-12-26 14:03:57 +07:00
|
|
|
|
2025-12-29 14:00:02 +07:00
|
|
|
return data.files.map((item: ApiFile) => {
|
2026-02-10 17:29:36 +07:00
|
|
|
const newDate = new Date(item.updatedAt).getTime();
|
2025-12-26 16:10:42 +07:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: item.id,
|
|
|
|
|
fileName: item.originalFileName,
|
|
|
|
|
fileType: item.mimeType.toLocaleLowerCase(),
|
|
|
|
|
violations: item.violations,
|
2026-01-20 20:09:46 +07:00
|
|
|
size: item.fileSize,
|
|
|
|
|
uploadDate: newDate,
|
|
|
|
|
status: item.status,
|
2026-01-26 16:09:39 +07:00
|
|
|
protectStatus: item.protectStatus,
|
2026-01-26 16:38:24 +07:00
|
|
|
supportId: item.supportId,
|
2025-12-29 14:00:02 +07:00
|
|
|
_original: item
|
2025-12-26 16:10:42 +07:00
|
|
|
};
|
|
|
|
|
});
|
2025-12-29 14:00:02 +07:00
|
|
|
},
|
|
|
|
|
});
|
2025-12-26 16:10:42 +07:00
|
|
|
|
2025-12-29 14:00:02 +07:00
|
|
|
const queryClient = useQueryClient();
|
2025-12-26 14:03:57 +07:00
|
|
|
|
2025-12-12 14:22:00 +07:00
|
|
|
// Состояния
|
|
|
|
|
const [sorting, setSorting] = useState<SortingState>([]);
|
|
|
|
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
2025-12-12 20:28:59 +07:00
|
|
|
const [dateFilter, setDateFilter] = useState<string>('all');
|
2025-12-29 16:08:38 +07:00
|
|
|
const [typeFilter, setTypeFilter] = useState<string>(fileType);
|
2025-12-26 16:10:42 +07:00
|
|
|
const [pagination, setPagination] = useState({
|
|
|
|
|
pageIndex: 0,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
});
|
|
|
|
|
const [openWindow, setOpenWindow] = useState<boolean>(false);
|
|
|
|
|
const [openWindowChildren, setOpenWindowChildren] = useState<ReactNode>(null);
|
2025-12-12 20:28:59 +07:00
|
|
|
|
2026-01-02 12:52:01 +07:00
|
|
|
const [isFileLoading, setIsFileLoading] = useState(false);
|
|
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
const t = useTranslations("Global");
|
2026-01-15 12:27:39 +07:00
|
|
|
const locale = useLocale();
|
2025-12-12 14:22:00 +07:00
|
|
|
|
|
|
|
|
// Определение колонок
|
2025-12-12 20:28:59 +07:00
|
|
|
const columns = useMemo<ColumnDef<FileItem>[]>(
|
2025-12-12 14:22:00 +07:00
|
|
|
() => [
|
2026-01-26 16:38:24 +07:00
|
|
|
{
|
|
|
|
|
accessorKey: 'id',
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<div className="column">
|
|
|
|
|
<span>
|
|
|
|
|
ID
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
|
|
|
className="sort-button"
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
column.getIsSorted() === 'asc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowUp />
|
|
|
|
|
</span>
|
|
|
|
|
: column.getIsSorted() === 'desc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowDown />
|
|
|
|
|
</span>
|
|
|
|
|
: <span>
|
|
|
|
|
<IconFilter />
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="text-center table-item table-item-id">
|
2026-01-27 19:52:01 +07:00
|
|
|
{row.original.supportId ? row.original.supportId : '-'}
|
2026-01-26 16:38:24 +07:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-12-12 14:22:00 +07:00
|
|
|
{
|
2025-12-12 20:28:59 +07:00
|
|
|
accessorKey: 'fileName',
|
|
|
|
|
header: ({ column }) => (
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="column start">
|
2025-12-12 20:28:59 +07:00
|
|
|
<span>
|
|
|
|
|
{t('file')}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
2025-12-30 13:35:20 +07:00
|
|
|
className="sort-button"
|
2025-12-12 20:28:59 +07:00
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
column.getIsSorted() === 'asc' ?
|
|
|
|
|
<span>
|
2025-12-17 16:41:07 +07:00
|
|
|
<IconArrowUp />
|
2025-12-12 20:28:59 +07:00
|
|
|
</span>
|
|
|
|
|
: column.getIsSorted() === 'desc' ?
|
|
|
|
|
<span>
|
2025-12-17 16:41:07 +07:00
|
|
|
<IconArrowDown />
|
2025-12-12 20:28:59 +07:00
|
|
|
</span>
|
|
|
|
|
: <span>
|
2025-12-17 16:41:07 +07:00
|
|
|
<IconFilter />
|
2025-12-12 20:28:59 +07:00
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-12-12 14:22:00 +07:00
|
|
|
),
|
|
|
|
|
cell: ({ row }) => (
|
2026-01-21 15:05:02 +07:00
|
|
|
<div className="flex items-center space-x-2 table-item">
|
2025-12-12 20:28:59 +07:00
|
|
|
<FileTypeIcon type={row.original.fileType} />
|
|
|
|
|
<div>
|
2026-01-04 17:43:58 +07:00
|
|
|
<div className="font-medium w-full truncate" title={row.original.fileName}>
|
2026-01-21 15:05:02 +07:00
|
|
|
<span className="font-semibold">
|
|
|
|
|
{cutFileName(row.original.fileName)}
|
|
|
|
|
</span>
|
2026-01-20 20:09:46 +07:00
|
|
|
<br />
|
2026-02-02 15:09:29 +07:00
|
|
|
<span className="table-item-extension">{cutFileExtension(row.original.fileName)}</span> <span className="table-item-protected">
|
|
|
|
|
{row.original?.protectStatus ? t(row.original?.protectStatus) : t('error')}
|
|
|
|
|
</span>
|
2026-01-04 17:43:58 +07:00
|
|
|
</div>
|
2025-12-12 20:28:59 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-12-12 14:22:00 +07:00
|
|
|
),
|
|
|
|
|
enableColumnFilter: false,
|
|
|
|
|
},
|
2026-01-20 20:09:46 +07:00
|
|
|
/* {
|
|
|
|
|
accessorKey: 'violations',
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<div className="column">
|
|
|
|
|
<span>
|
|
|
|
|
{t('violations')}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
|
|
|
className="sort-button"
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
column.getIsSorted() === 'asc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowUp />
|
|
|
|
|
</span>
|
|
|
|
|
: column.getIsSorted() === 'desc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowDown />
|
|
|
|
|
</span>
|
|
|
|
|
: <span>
|
|
|
|
|
<IconFilter />
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
let classCollor = () => {
|
|
|
|
|
let result = ''
|
|
|
|
|
if (row.original.violations !== undefined) {
|
|
|
|
|
result = row.original.violations > 0 ? 'text-red-600' : 'text-green-600'
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className={`text-center font-semibold ${classCollor()}`}>
|
|
|
|
|
{row.original.violations !== undefined ? row.original.violations : '-'}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
}, */
|
|
|
|
|
{
|
|
|
|
|
accessorKey: 'size',
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<div className="column">
|
|
|
|
|
<span>
|
|
|
|
|
{t('size')}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
|
|
|
className="sort-button"
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
column.getIsSorted() === 'asc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowUp />
|
|
|
|
|
</span>
|
|
|
|
|
: column.getIsSorted() === 'desc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowDown />
|
|
|
|
|
</span>
|
|
|
|
|
: <span>
|
|
|
|
|
<IconFilter />
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
cell: ({ row }) => (
|
2026-01-21 15:05:02 +07:00
|
|
|
<div className="text-center table-item">
|
2026-01-20 20:09:46 +07:00
|
|
|
{row.original.size !== undefined ? convertBytes(row.original.size) : '-'}
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
accessorKey: 'uploadDate',
|
|
|
|
|
header: ({ column }) => (
|
|
|
|
|
<div className="column">
|
|
|
|
|
<span>
|
|
|
|
|
{t('upload-date')}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
|
|
|
className="sort-button"
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
column.getIsSorted() === 'asc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowUp />
|
|
|
|
|
</span>
|
|
|
|
|
: column.getIsSorted() === 'desc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowDown />
|
|
|
|
|
</span>
|
|
|
|
|
: <span>
|
|
|
|
|
<IconFilter />
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
return (
|
2026-01-21 15:05:02 +07:00
|
|
|
<div className="text-center table-item">
|
2026-01-20 20:09:46 +07:00
|
|
|
{row.original.uploadDate ? (
|
|
|
|
|
<>
|
|
|
|
|
{formatDate(row.original.uploadDate)}
|
|
|
|
|
<br />
|
|
|
|
|
{formatDateTime(row.original.uploadDate)}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<div>-</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
enableColumnFilter: false,
|
|
|
|
|
},
|
2025-12-26 14:03:57 +07:00
|
|
|
{
|
|
|
|
|
accessorKey: 'status',
|
|
|
|
|
header: ({ column }) => (
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="column">
|
2025-12-26 14:03:57 +07:00
|
|
|
<span>
|
2026-01-08 11:16:59 +07:00
|
|
|
{t('status')}
|
2025-12-26 14:03:57 +07:00
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
2025-12-30 13:35:20 +07:00
|
|
|
className="sort-button"
|
2025-12-26 14:03:57 +07:00
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
column.getIsSorted() === 'asc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowUp />
|
|
|
|
|
</span>
|
|
|
|
|
: column.getIsSorted() === 'desc' ?
|
|
|
|
|
<span>
|
|
|
|
|
<IconArrowDown />
|
|
|
|
|
</span>
|
|
|
|
|
: <span>
|
|
|
|
|
<IconFilter />
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
return (
|
2026-01-21 15:05:02 +07:00
|
|
|
<div className="text-center font-semibold table-item">
|
|
|
|
|
<span className="table-item-status">
|
2026-01-26 16:09:39 +07:00
|
|
|
{row.original.status}
|
2026-01-21 15:05:02 +07:00
|
|
|
</span>
|
2025-12-26 14:03:57 +07:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-12-12 14:22:00 +07:00
|
|
|
{
|
2025-12-12 20:28:59 +07:00
|
|
|
id: 'actions',
|
|
|
|
|
header: () => {
|
|
|
|
|
return (
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="column">
|
2025-12-12 20:28:59 +07:00
|
|
|
{t('actions')}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
cell: ({ row }) => (
|
2026-01-04 13:27:59 +07:00
|
|
|
<div className="actions">
|
2026-01-21 15:05:02 +07:00
|
|
|
<div className="actions-group" style={{ display: "none" }}>
|
2026-01-04 17:08:28 +07:00
|
|
|
<button
|
|
|
|
|
onClick={() => handleProtect(row.original)}
|
|
|
|
|
className="bg-violet-500 hover:bg-violet-600"
|
|
|
|
|
>
|
|
|
|
|
<IconShieldExclamation />
|
|
|
|
|
</button>
|
2026-01-27 19:52:01 +07:00
|
|
|
{/* <button
|
2026-01-04 17:08:28 +07:00
|
|
|
onClick={() => handleOpenWindowForRemove(row.original)}
|
2026-01-21 15:05:02 +07:00
|
|
|
className="table-action-delete"
|
2026-01-04 17:08:28 +07:00
|
|
|
>
|
|
|
|
|
<IconDelete />
|
2026-01-21 15:05:02 +07:00
|
|
|
<span>
|
|
|
|
|
{t('delete')}
|
|
|
|
|
</span>
|
2026-01-27 19:52:01 +07:00
|
|
|
</button> */}
|
2026-01-04 17:08:28 +07:00
|
|
|
</div>
|
2026-01-28 18:53:08 +07:00
|
|
|
<div className="actions-group">
|
|
|
|
|
{row.original.protectStatus === 'PROTECTED' && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => handleDownload(row.original)}
|
|
|
|
|
disabled={isFileLoading}
|
|
|
|
|
className="table-action-download"
|
|
|
|
|
>
|
|
|
|
|
<IconFileDownload />
|
|
|
|
|
<span>
|
|
|
|
|
{t('download')}
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
handleView(row.original)
|
|
|
|
|
}}
|
|
|
|
|
className="table-action-view"
|
|
|
|
|
>
|
|
|
|
|
<IconEye />
|
|
|
|
|
<span>
|
|
|
|
|
{t('make-check')}
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-01-04 17:08:28 +07:00
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
enableColumnFilter: false,
|
2025-12-12 14:22:00 +07:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
[]
|
|
|
|
|
);
|
|
|
|
|
|
2026-01-28 18:53:08 +07:00
|
|
|
const handleView = async (file: FileItem) => {
|
2025-12-12 20:28:59 +07:00
|
|
|
console.log(`Просмотр файла: ${file.fileName}`);
|
2026-01-28 18:53:08 +07:00
|
|
|
console.log(file);
|
|
|
|
|
|
|
|
|
|
const fileInfo = await viewFileInfo(file.id);
|
|
|
|
|
console.log(fileInfo);
|
|
|
|
|
|
|
|
|
|
setOpenWindowChildren(() => {
|
|
|
|
|
return (
|
|
|
|
|
<FileInfoModalWindow fileInfo={fileInfo} setWindowClose={setOpenWindow} setWindowChildren={setOpenWindowChildren} />
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
setOpenWindow(true);
|
2025-12-12 20:28:59 +07:00
|
|
|
};
|
|
|
|
|
|
2026-01-02 12:52:01 +07:00
|
|
|
const handleDownload = async (file: FileItem) => {
|
|
|
|
|
setIsFileLoading(true);
|
2026-01-02 13:00:37 +07:00
|
|
|
|
2026-01-02 12:52:01 +07:00
|
|
|
try {
|
2026-02-12 16:45:29 +07:00
|
|
|
const response = await fetch(`/api/download/${file.id}`);
|
2026-01-02 12:52:01 +07:00
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`error: ${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const blob = await response.blob();
|
|
|
|
|
const url = window.URL.createObjectURL(blob);
|
|
|
|
|
const a = document.createElement('a');
|
|
|
|
|
a.href = url;
|
2026-02-12 16:45:29 +07:00
|
|
|
a.download = file._original?.fileName || file.fileName || `file-${file.id}`;
|
2026-01-02 12:52:01 +07:00
|
|
|
document.body.appendChild(a);
|
|
|
|
|
a.click();
|
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
|
document.body.removeChild(a);
|
2026-01-02 13:00:37 +07:00
|
|
|
toast.success(`${t('file-is-downloading')} - ${file.fileName}`);
|
2026-01-02 12:52:01 +07:00
|
|
|
} catch (error) {
|
2026-01-02 13:00:37 +07:00
|
|
|
toast.error(t('failed-to-download-file'))
|
2026-01-02 12:52:01 +07:00
|
|
|
} finally {
|
|
|
|
|
setIsFileLoading(false);
|
|
|
|
|
}
|
2025-12-12 20:28:59 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleProtect = (file: FileItem) => {
|
|
|
|
|
console.log(`Щиток: ${file.fileName}`);
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-29 14:00:02 +07:00
|
|
|
const handleOpenWindowForRemove = async (file: FileItem) => {
|
2025-12-26 16:10:42 +07:00
|
|
|
|
|
|
|
|
setOpenWindowChildren(() => {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<h3 className="text-2xl">
|
|
|
|
|
{t('you-sure-you-want-to-delete')}
|
|
|
|
|
</h3>
|
|
|
|
|
<div className="mt-2 mb-8 text-center">{file.fileName}</div>
|
|
|
|
|
<div className="flex justify-center gap-4">
|
|
|
|
|
<button className="btn-primary btn-modal"
|
2025-12-29 14:00:02 +07:00
|
|
|
onClick={() => {
|
2026-01-27 19:52:01 +07:00
|
|
|
deleteMutation.mutate({
|
|
|
|
|
fileId: file.id,
|
|
|
|
|
removeParam: 1,
|
|
|
|
|
})
|
2025-12-26 16:10:42 +07:00
|
|
|
}}
|
2025-12-29 14:00:02 +07:00
|
|
|
disabled={deleteMutation.isPending}
|
2025-12-26 16:10:42 +07:00
|
|
|
>
|
2025-12-29 14:00:02 +07:00
|
|
|
{deleteMutation.isPending ? '...' : t('yes')}
|
2025-12-26 16:10:42 +07:00
|
|
|
</button>
|
|
|
|
|
<button className="btn-primary btn-modal"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setOpenWindow(false);
|
|
|
|
|
setOpenWindowChildren(null);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t('no')}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
setOpenWindow(true);
|
2025-12-26 14:03:57 +07:00
|
|
|
};
|
|
|
|
|
|
2025-12-29 14:00:02 +07:00
|
|
|
const deleteMutation = useMutation({
|
2026-01-27 19:52:01 +07:00
|
|
|
mutationFn: ({ fileId, removeParam }: { fileId: string; removeParam: number }) =>
|
|
|
|
|
removeUserFile(fileId, removeParam),
|
2025-12-29 14:00:02 +07:00
|
|
|
|
2026-01-27 19:52:01 +07:00
|
|
|
onMutate: async ({ fileId, removeParam }: { fileId: string; removeParam: number }) => {
|
2025-12-29 14:00:02 +07:00
|
|
|
await queryClient.cancelQueries({ queryKey: ['userFilesData'] });
|
|
|
|
|
|
|
|
|
|
queryClient.setQueryData<ApiResponse>(['userFilesData'], (old) => {
|
|
|
|
|
if (!old?.files) return old;
|
|
|
|
|
return {
|
|
|
|
|
...old,
|
|
|
|
|
files: old.files.filter(file => file.id !== fileId)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onError: () => {
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['userFilesData'] });
|
|
|
|
|
toast.error(t('error'));
|
|
|
|
|
},
|
|
|
|
|
|
2026-01-27 19:52:01 +07:00
|
|
|
onSuccess: (response, { fileId }) => {
|
2025-12-29 14:00:02 +07:00
|
|
|
if (response === fileId) {
|
2025-12-29 16:08:38 +07:00
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ['userFilesData'],
|
|
|
|
|
refetchType: 'active'
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-09 12:35:48 +07:00
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ['userFilesInfo']
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-29 14:00:02 +07:00
|
|
|
setOpenWindow(false);
|
|
|
|
|
setOpenWindowChildren(null);
|
|
|
|
|
toast.success(t('file-has-been-deleted'));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-12 20:28:59 +07:00
|
|
|
// Фильтрация по типу файла и дате
|
|
|
|
|
const filteredData = useMemo(() => {
|
2025-12-26 14:03:57 +07:00
|
|
|
let result = tableData;
|
2025-12-29 14:00:02 +07:00
|
|
|
if (!result) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2025-12-12 20:28:59 +07:00
|
|
|
|
|
|
|
|
// Фильтр по типу файла
|
|
|
|
|
if (typeFilter !== 'all') {
|
|
|
|
|
result = result.filter(item => item.fileType === typeFilter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Фильтр по дате
|
|
|
|
|
if (dateFilter !== 'all') {
|
|
|
|
|
const now = Date.now();
|
|
|
|
|
const oneDay = 24 * 60 * 60 * 1000;
|
|
|
|
|
const sevenDays = 7 * oneDay;
|
|
|
|
|
const thirtyDays = 30 * oneDay;
|
|
|
|
|
|
|
|
|
|
switch (dateFilter) {
|
|
|
|
|
case 'today':
|
|
|
|
|
const todayStart = new Date().setHours(0, 0, 0, 0);
|
2025-12-26 14:03:57 +07:00
|
|
|
result = result.filter(item => {
|
2026-01-20 20:09:46 +07:00
|
|
|
if (item.uploadDate) {
|
|
|
|
|
return item.uploadDate >= todayStart
|
2025-12-26 14:03:57 +07:00
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-12-12 20:28:59 +07:00
|
|
|
break;
|
|
|
|
|
case 'week':
|
|
|
|
|
const weekAgo = now - sevenDays;
|
2025-12-26 14:03:57 +07:00
|
|
|
result = result.filter(item => {
|
2026-01-20 20:09:46 +07:00
|
|
|
if (item.uploadDate) {
|
|
|
|
|
return item.uploadDate >= weekAgo;
|
2025-12-26 14:03:57 +07:00
|
|
|
}
|
|
|
|
|
});
|
2025-12-12 20:28:59 +07:00
|
|
|
break;
|
|
|
|
|
case 'month':
|
|
|
|
|
const monthAgo = now - thirtyDays;
|
2025-12-26 14:03:57 +07:00
|
|
|
result = result.filter(item => {
|
2026-01-20 20:09:46 +07:00
|
|
|
if (item.uploadDate) {
|
|
|
|
|
return item.uploadDate >= monthAgo;
|
2025-12-26 14:03:57 +07:00
|
|
|
}
|
|
|
|
|
});
|
2025-12-12 20:28:59 +07:00
|
|
|
break;
|
|
|
|
|
case 'older':
|
|
|
|
|
const monthAgo2 = now - thirtyDays;
|
2025-12-26 14:03:57 +07:00
|
|
|
result = result.filter(item => {
|
2026-01-20 20:09:46 +07:00
|
|
|
if (item.uploadDate) {
|
|
|
|
|
return item.uploadDate < monthAgo2;
|
2025-12-26 14:03:57 +07:00
|
|
|
}
|
|
|
|
|
});
|
2025-12-12 20:28:59 +07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2025-12-26 14:03:57 +07:00
|
|
|
}, [tableData, typeFilter, dateFilter]);
|
2025-12-12 20:28:59 +07:00
|
|
|
|
2025-12-26 16:10:42 +07:00
|
|
|
useEffect(() => {
|
|
|
|
|
const currentPageRows = table.getRowModel().rows;
|
|
|
|
|
const pageCount = table.getPageCount();
|
|
|
|
|
|
|
|
|
|
if (currentPageRows.length === 0 && pagination.pageIndex > 0 && pageCount > 0) {
|
|
|
|
|
table.setPageIndex(pagination.pageIndex - 1);
|
|
|
|
|
}
|
|
|
|
|
}, [filteredData, pagination.pageIndex]);
|
|
|
|
|
|
2025-12-12 14:22:00 +07:00
|
|
|
// Создание таблицы
|
|
|
|
|
const table = useReactTable({
|
2025-12-12 20:28:59 +07:00
|
|
|
data: filteredData,
|
2025-12-12 14:22:00 +07:00
|
|
|
columns,
|
|
|
|
|
state: {
|
|
|
|
|
sorting,
|
|
|
|
|
columnFilters,
|
2025-12-26 16:10:42 +07:00
|
|
|
pagination
|
2025-12-12 14:22:00 +07:00
|
|
|
},
|
2025-12-26 16:10:42 +07:00
|
|
|
autoResetPageIndex: false,
|
|
|
|
|
onPaginationChange: setPagination,
|
2025-12-12 14:22:00 +07:00
|
|
|
onSortingChange: setSorting,
|
|
|
|
|
onColumnFiltersChange: setColumnFilters,
|
|
|
|
|
getCoreRowModel: getCoreRowModel(),
|
|
|
|
|
getSortedRowModel: getSortedRowModel(),
|
|
|
|
|
getPaginationRowModel: getPaginationRowModel(),
|
|
|
|
|
getFilteredRowModel: getFilteredRowModel(),
|
2025-12-12 20:28:59 +07:00
|
|
|
initialState: {
|
|
|
|
|
pagination: {
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-12-12 14:22:00 +07:00
|
|
|
});
|
|
|
|
|
|
2026-01-14 15:01:30 +07:00
|
|
|
const pluralizeFiles = (number: number) => {
|
|
|
|
|
const translate = [t('file'), t('files-few'), t('files')];
|
2026-01-15 12:27:39 +07:00
|
|
|
return pluralize(number, translate[0], translate[1], translate[2], locale);
|
2026-01-14 15:01:30 +07:00
|
|
|
};
|
|
|
|
|
|
2025-12-12 14:22:00 +07:00
|
|
|
return (
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="tanstak-table-wrapper">
|
2026-01-21 15:05:02 +07:00
|
|
|
<h3
|
|
|
|
|
className="tanstak-table-title"
|
|
|
|
|
>
|
|
|
|
|
{(() => {
|
|
|
|
|
switch (fileType) {
|
|
|
|
|
case 'image':
|
|
|
|
|
return t('protected-image')
|
|
|
|
|
case 'video':
|
|
|
|
|
return t('protected-video')
|
|
|
|
|
case 'audio':
|
|
|
|
|
return t('protected-audio')
|
|
|
|
|
default:
|
|
|
|
|
return t('table-description')
|
|
|
|
|
}
|
|
|
|
|
})()}
|
|
|
|
|
</h3>
|
|
|
|
|
<ModalWindow children={openWindowChildren} state={openWindow} callBack={setOpenWindow} />
|
2025-12-12 20:28:59 +07:00
|
|
|
{/* Фильтры */}
|
2026-01-21 15:05:02 +07:00
|
|
|
<div className="tanstak-table-filtres" style={{ display: "none" }}>
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="table-filtres-wrapper">
|
|
|
|
|
<div className="table-filtres-item">
|
|
|
|
|
<div className="table-filtres-label">{t('date-filter')}:</div>
|
2025-12-12 20:28:59 +07:00
|
|
|
<DropDownList
|
2025-12-19 13:05:50 +07:00
|
|
|
value={dateFilter}
|
|
|
|
|
translatedValue={(() => {
|
2025-12-15 11:24:07 +07:00
|
|
|
switch (dateFilter) {
|
|
|
|
|
case 'all':
|
|
|
|
|
return t('all-dates')
|
|
|
|
|
case 'week':
|
|
|
|
|
return t('for-a-week')
|
|
|
|
|
case 'month':
|
|
|
|
|
return t('for-a-month')
|
|
|
|
|
case 'older':
|
|
|
|
|
return t('older-than-a-month')
|
|
|
|
|
default:
|
|
|
|
|
return t('today')
|
|
|
|
|
}
|
|
|
|
|
})()}
|
2025-12-12 20:28:59 +07:00
|
|
|
callBack={setDateFilter}
|
|
|
|
|
>
|
|
|
|
|
<li value="all">
|
|
|
|
|
{t('all-dates')}
|
|
|
|
|
</li>
|
|
|
|
|
<li value="today">
|
|
|
|
|
{t('today')}
|
|
|
|
|
</li>
|
|
|
|
|
<li value="week">
|
|
|
|
|
{t('for-a-week')}
|
|
|
|
|
</li>
|
|
|
|
|
<li value="month">
|
|
|
|
|
{t('for-a-month')}
|
|
|
|
|
</li>
|
|
|
|
|
<li value="older">
|
|
|
|
|
{t('older-than-a-month')}
|
|
|
|
|
</li>
|
|
|
|
|
</DropDownList>
|
|
|
|
|
</div>
|
2025-12-12 14:22:00 +07:00
|
|
|
|
2025-12-29 16:08:38 +07:00
|
|
|
{fileType === "all" && (
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="table-filtres-item">
|
|
|
|
|
<div className="table-filtres-label">{t('type-filter')}:</div>
|
2025-12-29 16:08:38 +07:00
|
|
|
<DropDownList
|
|
|
|
|
value={typeFilter}
|
|
|
|
|
translatedValue={
|
|
|
|
|
(() => {
|
|
|
|
|
switch (typeFilter) {
|
|
|
|
|
case 'image':
|
|
|
|
|
return t('images')
|
|
|
|
|
case 'video':
|
|
|
|
|
return t('videos')
|
|
|
|
|
case 'audio':
|
|
|
|
|
return t('audios')
|
|
|
|
|
default:
|
|
|
|
|
return t('all-types')
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
}
|
|
|
|
|
callBack={setTypeFilter}
|
|
|
|
|
>
|
|
|
|
|
<li value="all">
|
|
|
|
|
{t('all-types')}
|
|
|
|
|
</li>
|
|
|
|
|
<li value="image">
|
2026-01-08 17:21:09 +07:00
|
|
|
{t('images-few')}
|
2025-12-29 16:08:38 +07:00
|
|
|
</li>
|
|
|
|
|
<li value="video">
|
|
|
|
|
{t('videos')}
|
|
|
|
|
</li>
|
|
|
|
|
<li value="audio">
|
|
|
|
|
{t('audios')}
|
|
|
|
|
</li>
|
|
|
|
|
</DropDownList>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-12-12 20:28:59 +07:00
|
|
|
</div>
|
2025-12-12 14:22:00 +07:00
|
|
|
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="table-filtres-item">
|
|
|
|
|
<div className="table-filtres-label">{t('items-per-page')}:</div>
|
2025-12-12 20:28:59 +07:00
|
|
|
<DropDownList
|
|
|
|
|
value={table.getState().pagination.pageSize}
|
|
|
|
|
//@ts-ignore сделал так потому что для table.setPageSize нужна цифра
|
|
|
|
|
callBack={table.setPageSize}
|
|
|
|
|
>
|
|
|
|
|
{[5, 10, 20, 50, 100].map(pageSize => (
|
|
|
|
|
<li key={pageSize} value={pageSize}>
|
|
|
|
|
{t('show')} {pageSize}
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</DropDownList>
|
|
|
|
|
</div>
|
2025-12-12 14:22:00 +07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Таблица */}
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="tanstak-table-block">
|
|
|
|
|
<table className="tanstak-table">
|
|
|
|
|
<thead className="tanstak-table-head">
|
|
|
|
|
{table.getHeaderGroups().map(headerGroup => (
|
|
|
|
|
<tr key={headerGroup.id}>
|
|
|
|
|
{headerGroup.headers.map(header => (
|
|
|
|
|
<th
|
|
|
|
|
key={header.id}
|
|
|
|
|
>
|
|
|
|
|
{header.isPlaceholder
|
|
|
|
|
? null
|
|
|
|
|
: typeof header.column.columnDef.header === 'function'
|
|
|
|
|
? header.column.columnDef.header(header.getContext())
|
|
|
|
|
: header.column.columnDef.header as string}
|
|
|
|
|
</th>
|
|
|
|
|
))}
|
|
|
|
|
</tr>
|
|
|
|
|
))}
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody className="tanstak-table-body">
|
|
|
|
|
{table.getRowModel().rows.length > 0 ? (
|
|
|
|
|
table.getRowModel().rows.map(row => (
|
|
|
|
|
<tr key={row.id}>
|
|
|
|
|
{row.getVisibleCells().map(cell => (
|
|
|
|
|
<td key={cell.id}>
|
|
|
|
|
{typeof cell.column.columnDef.cell === 'function'
|
|
|
|
|
? cell.column.columnDef.cell(cell.getContext())
|
|
|
|
|
: cell.getValue() as string}
|
|
|
|
|
</td>
|
2025-12-12 20:28:59 +07:00
|
|
|
))}
|
|
|
|
|
</tr>
|
2025-12-30 13:35:20 +07:00
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<tr>
|
|
|
|
|
<td colSpan={columns.length} className="text-center">
|
|
|
|
|
{t('no-data-for-selected-filters')}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2025-12-12 14:22:00 +07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Пагинация */}
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="tanstak-table-pagination">
|
|
|
|
|
<div className="pagination-info">
|
|
|
|
|
<span className="pagination-info-pages">
|
2025-12-12 20:28:59 +07:00
|
|
|
{t('page')}{' '}
|
|
|
|
|
<strong>
|
2025-12-19 13:05:50 +07:00
|
|
|
{table.getState().pagination.pageIndex + 1} {t('out-of')} {table.getPageCount() ? table.getPageCount() : 1}
|
2025-12-12 20:28:59 +07:00
|
|
|
</strong>
|
|
|
|
|
</span>
|
2025-12-30 13:35:20 +07:00
|
|
|
<span className="pagination-info-files">
|
2026-01-14 15:01:30 +07:00
|
|
|
| {t('shown')} {table.getRowModel().rows.length} {t('out-of')} {filteredData.length} {pluralizeFiles(filteredData.length || 0)}
|
2025-12-12 20:28:59 +07:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="pagination-controls">
|
2026-01-21 15:05:02 +07:00
|
|
|
{table.getCanPreviousPage() && (
|
|
|
|
|
<button
|
|
|
|
|
className="arrow"
|
|
|
|
|
onClick={() => table.firstPage()}
|
|
|
|
|
disabled={!table.getCanPreviousPage()}
|
|
|
|
|
>
|
|
|
|
|
<IconDoubleArrowLeft />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{table.getCanPreviousPage() && (
|
|
|
|
|
<button
|
|
|
|
|
className="arrow"
|
|
|
|
|
onClick={() => table.previousPage()}
|
|
|
|
|
disabled={!table.getCanPreviousPage()}
|
|
|
|
|
>
|
|
|
|
|
<IconArrowLeft />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2025-12-12 20:28:59 +07:00
|
|
|
|
2025-12-30 13:35:20 +07:00
|
|
|
<div className="pagination-controls-pages">
|
2025-12-12 20:28:59 +07:00
|
|
|
{Array.from({ length: Math.min(5, table.getPageCount()) }, (_, i) => {
|
|
|
|
|
const pageIndex = Math.max(
|
|
|
|
|
0,
|
|
|
|
|
Math.min(
|
|
|
|
|
table.getPageCount() - 5,
|
|
|
|
|
table.getState().pagination.pageIndex - 2
|
|
|
|
|
)
|
|
|
|
|
) + i;
|
|
|
|
|
|
|
|
|
|
if (pageIndex < table.getPageCount()) {
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
key={pageIndex}
|
2025-12-30 13:35:20 +07:00
|
|
|
className={`${table.getState().pagination.pageIndex === pageIndex
|
|
|
|
|
? 'current'
|
|
|
|
|
: 'other'
|
2025-12-12 20:28:59 +07:00
|
|
|
}`}
|
|
|
|
|
onClick={() => table.setPageIndex(pageIndex)}
|
|
|
|
|
>
|
|
|
|
|
{pageIndex + 1}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-21 15:05:02 +07:00
|
|
|
{table.getCanNextPage() && (
|
|
|
|
|
<button
|
|
|
|
|
className="arrow"
|
|
|
|
|
onClick={() => table.nextPage()}
|
|
|
|
|
disabled={!table.getCanNextPage()}
|
|
|
|
|
>
|
|
|
|
|
<IconArrowRight />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{table.getCanNextPage() && (
|
|
|
|
|
<button
|
|
|
|
|
className="arrow"
|
|
|
|
|
onClick={() => table.lastPage()}
|
|
|
|
|
disabled={!table.getCanNextPage()}
|
|
|
|
|
>
|
|
|
|
|
<IconDoubleArrowRight />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2025-12-12 14:22:00 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-21 15:05:02 +07:00
|
|
|
</div >
|
2025-12-12 14:22:00 +07:00
|
|
|
);
|
|
|
|
|
}
|