2021-10-12 04:47:46 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2022-05-18 09:46:10 -04:00
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import Tooltip from '../../../shared/components/tooltip'
|
2021-10-12 04:47:46 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2023-03-13 10:11:43 -04:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
2021-10-12 04:47:46 -04:00
|
|
|
|
|
|
|
function PdfHybridDownloadButton() {
|
2021-10-15 05:39:56 -04:00
|
|
|
const { pdfDownloadUrl } = useCompileContext()
|
2021-10-12 04:47:46 -04:00
|
|
|
|
2023-03-13 10:11:43 -04:00
|
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
const { t } = useTranslation()
|
2022-05-18 09:46:10 -04:00
|
|
|
const description = pdfDownloadUrl
|
|
|
|
? t('download_pdf')
|
|
|
|
: t('please_compile_pdf_before_download')
|
2021-10-12 04:47:46 -04:00
|
|
|
|
2023-03-13 10:11:43 -04:00
|
|
|
function handleOnClick() {
|
2023-08-22 09:33:19 -04:00
|
|
|
eventTracking.sendMB('download-pdf-button-click', {
|
|
|
|
projectId,
|
|
|
|
location: 'pdf-preview',
|
|
|
|
})
|
2023-03-13 10:11:43 -04:00
|
|
|
}
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
return (
|
2022-05-19 08:45:20 -04:00
|
|
|
<Tooltip
|
2023-05-16 08:16:28 -04:00
|
|
|
id="download-pdf"
|
2022-05-19 08:45:20 -04:00
|
|
|
description={description}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
|
|
|
>
|
2021-10-12 04:47:46 -04:00
|
|
|
<Button
|
2023-03-13 10:11:43 -04:00
|
|
|
onClick={handleOnClick}
|
2021-10-12 04:47:46 -04:00
|
|
|
bsStyle="link"
|
2023-09-12 11:30:02 -04:00
|
|
|
draggable="false"
|
2021-10-12 04:47:46 -04:00
|
|
|
disabled={!pdfDownloadUrl}
|
|
|
|
download
|
|
|
|
href={pdfDownloadUrl || '#'}
|
|
|
|
target="_blank"
|
2021-12-07 05:06:38 -05:00
|
|
|
style={{ pointerEvents: 'auto' }}
|
2023-09-15 03:14:01 -04:00
|
|
|
aria-label={t('download_pdf')}
|
2021-10-12 04:47:46 -04:00
|
|
|
>
|
2022-01-19 06:56:57 -05:00
|
|
|
<Icon type="download" fw />
|
2021-10-12 04:47:46 -04:00
|
|
|
</Button>
|
2022-05-18 09:46:10 -04:00
|
|
|
</Tooltip>
|
2021-10-12 04:47:46 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-18 09:46:10 -04:00
|
|
|
export default PdfHybridDownloadButton
|