asb_cloud_front/src/components/DownloadLink.tsx

46 lines
1.1 KiB
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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