/
softailor
/
gridient
Обзор
Документация
Войти
/
softailor
/
gridient
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/src/modules/ViewItemModal/components/ViewForm/FileField/FileField.tsx
77 строк
2 KB
Jenkins
Auto add
18 фев 2026, 10:19
18 фев 2026, 10:19
1e6c4f8
Код
Авторство
О чём код?
import { FC } from "react"; import { useDownloadFileMutation, useGetFilesNameQuery } from "services"; import "./FileField.scss"; interface FileFieldProps { listId?: number; itemId?: number; value?: string; } export const FileField: FC<FileFieldProps> = ({ listId, itemId, value }) => { const fileIds = value ? value.split(";") : []; // const { getAccessToken } = useAuth(); const [downloadFile] = useDownloadFileMutation(); const { data, isLoading } = useGetFilesNameQuery( { listId: listId!, itemId: itemId!, ids: fileIds }, { skip: fileIds.length === 0 || !listId || !itemId }, ); if (isLoading) { return null; } // const handleDownload = async (id: number, name: string) => { // try { // const token = await getAccessToken(); // const headers: Record<string, string> = {}; // if (token) { // headers.Authorization = `${JWT_AUTH.AuthorizationPattern}${token}`; // } // const response = await axios.get(`/api/Attachment/downloadDocument/${id}`, { // responseType: "blob", // headers, // }); // const url = window.URL.createObjectURL(response.data); // const a = document.createElement("a"); // a.href = url; // a.download = name; // document.body.appendChild(a); // a.click(); // a.remove(); // window.URL.revokeObjectURL(url); // } catch (err) { // console.error("Fetch error:", err); // } // }; return ( <ul className="file-field"> {data?.map((file) => ( <li key={file.id}> <button type="button" onClick={() => downloadFile({ listId: listId!, itemId: itemId!, attachmentId: Number(file.id), fileName: file.name, }) } className="text-blue-600 hover:underline" > {file.name} </button> </li> ))} </ul> ); };