import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { InfoCircleFilled, CloseCircleOutlined } from '@ant-design/icons'
import { Button, Result, Typography } from 'antd'
import { downloadFile, invokeWebApiWrapperAsync } from '@components/factory'
import { withPermissions } from '@utils'
import { FileService } from '@api'
const { Paragraph, Text } = Typography
export const getLinkToFile = (fileInfo) => `/file_download/${fileInfo.id}`
const FileDownload = memo(function FileDownload() {
const { idFile } = useParams()
const [file, setFile] = useState({})
const [isError, setIsError] = useState(false)
const navigate = useNavigate()
const location = useLocation()
const isFirstOpenApp = useMemo(() => location.key === 'default', [location])
useEffect(() => {
invokeWebApiWrapperAsync(
async () => {
const file = await FileService.getFileInfo(idFile)
setFile(file)
},
null,
() => {
setIsError(true)
return 'Не удалось получить информацию о файле'
},
{ actionName: 'Получение информации о файле' }
)
}, [idFile])
const download = useCallback(async () => {
if (!file || !await downloadFile(file))
setIsError(true)
}, [file])
return (
Файл "{file?.name ?? ('№' + idFile)}".
>
)}
// subTitle={}
extra={(
<>
{isFirstOpenApp
?
:
}
>
)}
>
{isError && (