2022-10-24 12:21:36 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2023-08-22 09:33:19 -04:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
2022-10-24 12:21:36 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import Tooltip from '../../../shared/components/tooltip'
|
2023-08-22 09:33:19 -04:00
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
2022-10-24 12:21:36 -04:00
|
|
|
|
|
|
|
export default function DownloadPDF() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { pdfDownloadUrl, pdfUrl } = useCompileContext()
|
2023-08-22 09:33:19 -04:00
|
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
|
|
|
|
function sendDownloadEvent() {
|
|
|
|
eventTracking.sendMB('download-pdf-button-click', {
|
|
|
|
projectId,
|
|
|
|
location: 'left-menu',
|
|
|
|
})
|
|
|
|
}
|
2022-10-24 12:21:36 -04:00
|
|
|
|
|
|
|
if (pdfUrl) {
|
|
|
|
return (
|
2023-08-22 09:33:19 -04:00
|
|
|
<a
|
|
|
|
href={pdfDownloadUrl || pdfUrl}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
onClick={sendDownloadEvent}
|
|
|
|
>
|
2022-10-24 12:21:36 -04:00
|
|
|
<Icon type="file-pdf-o" modifier="2x" />
|
|
|
|
<br />
|
|
|
|
PDF
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
id="disabled-pdf-download"
|
|
|
|
description={t('please_compile_pdf_before_download')}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
|
|
|
>
|
|
|
|
<div className="link-disabled">
|
|
|
|
<Icon type="file-pdf-o" modifier="2x" />
|
|
|
|
<br />
|
|
|
|
PDF
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|