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() {
|
|
|
|
eventTracking.sendMB('download-pdf-button-click', { projectId })
|
|
|
|
}
|
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
return (
|
2022-05-19 08:45:20 -04:00
|
|
|
<Tooltip
|
|
|
|
id="logs-toggle"
|
|
|
|
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"
|
|
|
|
disabled={!pdfDownloadUrl}
|
|
|
|
download
|
|
|
|
href={pdfDownloadUrl || '#'}
|
|
|
|
target="_blank"
|
2021-12-07 05:06:38 -05:00
|
|
|
style={{ pointerEvents: 'auto' }}
|
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
|