2022-06-29 16:45:38 +05:00
|
|
|
|
import { memo, ReactNode } from 'react'
|
|
|
|
|
import { Link, LinkProps } from 'react-router-dom'
|
2022-02-22 15:27:30 +05:00
|
|
|
|
import { FileWordOutlined } from '@ant-design/icons'
|
|
|
|
|
|
|
|
|
|
import { FileInfoDto } from '@api'
|
|
|
|
|
import { downloadFile } from './factory'
|
|
|
|
|
|
2022-06-29 16:45:38 +05:00
|
|
|
|
import { getLinkToFile } from '@pages/FileDownload'
|
|
|
|
|
|
|
|
|
|
import '@styles/index.css'
|
|
|
|
|
|
|
|
|
|
export type DownloadLinkProps = LinkProps & {
|
2022-02-22 15:27:30 +05:00
|
|
|
|
file?: FileInfoDto
|
|
|
|
|
name?: string
|
2022-06-29 16:45:38 +05:00
|
|
|
|
icon?: ReactNode
|
2022-02-22 15:27:30 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 16:45:38 +05:00
|
|
|
|
export const DownloadLink = memo<DownloadLinkProps>(({
|
|
|
|
|
className = '',
|
|
|
|
|
file,
|
|
|
|
|
name,
|
|
|
|
|
icon = <FileWordOutlined />,
|
|
|
|
|
...other
|
|
|
|
|
}) => (
|
|
|
|
|
<Link
|
|
|
|
|
title={'Чтобы поделиться файлом с другим сотрудником скопируйте ссылку'}
|
2022-02-22 15:27:30 +05:00
|
|
|
|
{...other}
|
2022-06-29 16:45:38 +05:00
|
|
|
|
className={`download-link ${className}`}
|
|
|
|
|
|
|
|
|
|
to={getLinkToFile(file)}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
if (file)
|
|
|
|
|
downloadFile(file)
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
return false
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{icon}
|
|
|
|
|
<span style={{ marginLeft: 8 }}>{name ?? file?.name ?? '-'}</span>
|
|
|
|
|
</Link>
|
2022-02-22 15:27:30 +05:00
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
export default DownloadLink
|