add permission change button
This commit is contained in:
@@ -118,6 +118,46 @@ export async function fetchDocumentInfo(fileId: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Error(`${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function filePermisionChange(fileId: string, permissions: boolean) {
|
||||
const token = await getSessionData('token');
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
version: 1,
|
||||
msg_id: 20005,
|
||||
message_body: {
|
||||
file_id: fileId,
|
||||
token: token,
|
||||
action: 'change_permission',
|
||||
permissions: {
|
||||
DOWNLOAD: permissions
|
||||
}
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const parsed = await response.json();
|
||||
|
||||
if (parsed.message_code === 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Error(`${response.status}`);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import { useDebouncedCallback } from 'use-debounce';
|
||||
import Link from 'next/link';
|
||||
import { SelectedFilesAction } from '@/app/components/tanstak-table/SelectedFilesActions';
|
||||
import Image from 'next/image';
|
||||
import { filePermisionChange } from '@/app/actions/trackingActions';
|
||||
|
||||
export type FileItem = {
|
||||
id: string;
|
||||
@@ -45,7 +46,10 @@ export type FileItem = {
|
||||
protectStatus: string;
|
||||
_original?: ApiFile;
|
||||
supportId: number;
|
||||
thumbnailFileUrl: string
|
||||
thumbnailFileUrl: string;
|
||||
permissions: {
|
||||
DOWNLOAD: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
type ApiFile = {
|
||||
@@ -61,6 +65,9 @@ type ApiFile = {
|
||||
supportId: number;
|
||||
fileName: string;
|
||||
thumbnailFileUrl: string;
|
||||
permissions: {
|
||||
DOWNLOAD: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
type ApiResponse = {
|
||||
@@ -190,7 +197,10 @@ export default function TanstakFilesTable({ fileType, showFileLink }: { fileType
|
||||
protectStatus: item.protectStatus,
|
||||
supportId: item.supportId,
|
||||
_original: item,
|
||||
thumbnailFileUrl: item.thumbnailFileUrl
|
||||
thumbnailFileUrl: item.thumbnailFileUrl,
|
||||
permissions: {
|
||||
DOWNLOAD: item.permissions.DOWNLOAD,
|
||||
}
|
||||
}));
|
||||
|
||||
return {
|
||||
@@ -553,6 +563,33 @@ export default function TanstakFilesTable({ fileType, showFileLink }: { fileType
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'downloadPermision',
|
||||
header: ({ column }) => (
|
||||
<div className="column">
|
||||
<span>
|
||||
Можно скачать по ссылке
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="text-center font-semibold table-item">
|
||||
<button
|
||||
onClick={() => changeDownloadPermition(row.original.id, row.original.permissions.DOWNLOAD)}
|
||||
disabled={isFileLoading}
|
||||
className={`toggle-switch ${row.original.permissions?.DOWNLOAD ? 'active' : 'inactive'}`}
|
||||
title={'change-permission'}
|
||||
>
|
||||
<span className="toggle-slider"></span>
|
||||
<span className="toggle-label">
|
||||
{row.original.permissions?.DOWNLOAD ? 'Да' : 'Нет'}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: () => {
|
||||
@@ -564,15 +601,8 @@ export default function TanstakFilesTable({ fileType, showFileLink }: { fileType
|
||||
},
|
||||
cell: ({ row }) => (
|
||||
<div className="actions">
|
||||
<div className="actions-group">
|
||||
<Link
|
||||
href={`/pages/file/${row.original.id}`}
|
||||
className="bg-violet-500 hover:bg-violet-600"
|
||||
title={t('view')}
|
||||
>
|
||||
<IconEye />
|
||||
</Link>
|
||||
{(showFileLink && row.original.fileType === 'document') && (
|
||||
{(showFileLink && row.original.fileType === 'document') ? (
|
||||
<div className="actions-group">
|
||||
<Link
|
||||
href={`/watch-doc?docid=${row.original.id}`}
|
||||
className="bg-indigo-500 hover:bg-indigo-600"
|
||||
@@ -581,30 +611,41 @@ export default function TanstakFilesTable({ fileType, showFileLink }: { fileType
|
||||
>
|
||||
<IconLink />
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
<div className="actions-group">
|
||||
{row.original.protectStatus === 'PROTECTED' && (
|
||||
<button
|
||||
onClick={() => handleDownload(row.original)}
|
||||
disabled={isFileLoading}
|
||||
className="table-action-download"
|
||||
title={t('download')}
|
||||
>
|
||||
<IconFileDownload />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => {
|
||||
handleView(row.original)
|
||||
}}
|
||||
className="table-action-view"
|
||||
title={t('make-check')}
|
||||
>
|
||||
<IconInfo />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="actions-group">
|
||||
<Link
|
||||
href={`/pages/file/${row.original.id}`}
|
||||
className="bg-violet-500 hover:bg-violet-600"
|
||||
title={t('view')}
|
||||
>
|
||||
<IconEye />
|
||||
</Link>
|
||||
</div>
|
||||
<div className="actions-group">
|
||||
{row.original.protectStatus === 'PROTECTED' && (
|
||||
<button
|
||||
onClick={() => handleDownload(row.original)}
|
||||
disabled={isFileLoading}
|
||||
className="table-action-download"
|
||||
title={t('download')}
|
||||
>
|
||||
<IconFileDownload />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => {
|
||||
handleView(row.original)
|
||||
}}
|
||||
className="table-action-view"
|
||||
title={t('make-check')}
|
||||
>
|
||||
<IconInfo />
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
enableSorting: false,
|
||||
@@ -659,6 +700,16 @@ export default function TanstakFilesTable({ fileType, showFileLink }: { fileType
|
||||
}
|
||||
}
|
||||
|
||||
const changeDownloadPermition = async (fileId: string, permission: boolean) => {
|
||||
const response = await filePermisionChange(fileId, !permission);
|
||||
if (response) {
|
||||
queryClient.invalidateQueries({ queryKey: ['userFilesData'] });
|
||||
toast.success('Разрешение на скачивание изменено.');
|
||||
} else {
|
||||
toast.warning('Не удалось изменить разрешение на скачивание.');
|
||||
}
|
||||
}
|
||||
|
||||
// Фильтрация по типу файла и дате
|
||||
const filteredData = useMemo(() => {
|
||||
let result = tableData;
|
||||
@@ -735,6 +786,10 @@ export default function TanstakFilesTable({ fileType, showFileLink }: { fileType
|
||||
state: {
|
||||
sorting,
|
||||
pagination,
|
||||
columnVisibility: {
|
||||
monitoring: showFileLink ? false : true,
|
||||
downloadPermision: showFileLink ? true : false,
|
||||
}
|
||||
},
|
||||
pageCount: totalPages,
|
||||
manualPagination: true,
|
||||
|
||||
@@ -1027,6 +1027,67 @@
|
||||
background-color: #155dfc;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 60px;
|
||||
height: 28px;
|
||||
padding: 0 6px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
background-color: #615fff;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.toggle-switch.active {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.toggle-switch.inactive {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.toggle-switch .toggle-slider {
|
||||
position: absolute;
|
||||
width: 30px;
|
||||
height: 28px;
|
||||
background-color: white;
|
||||
border: 1px solid #615fff;
|
||||
border-radius: 8px;
|
||||
transition: transform 0.3s ease;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.toggle-switch.active .toggle-slider {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.toggle-switch.inactive .toggle-slider {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.toggle-switch .toggle-label {
|
||||
z-index: 1;
|
||||
color: v.$text-p;
|
||||
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
width: 30px;
|
||||
height: 26px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.toggle-switch:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.table-item-checkbox {
|
||||
|
||||
@@ -251,9 +251,9 @@
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
/* margin-bottom: 14px; */
|
||||
overflow: hidden;
|
||||
box-shadow: var(--shadow);
|
||||
height: 100%;
|
||||
|
||||
.card-head {
|
||||
padding: 14px 20px;
|
||||
|
||||
Reference in New Issue
Block a user