overleaf/services/web/frontend/js/features/pdf-preview/components/pdf-hybrid-download-button.tsx
Miguel Serrano 9ecc84f0b0 [web] download-pdf-button-click event tracking (#12059)
* [web] `download-pdf-button-click` event tracking

GitOrigin-RevId: 20baae4fff989b5120ae03f81cc47f7d6874dd7b
2023-03-14 09:04:44 +00:00

44 lines
1.3 KiB
TypeScript

import { useTranslation } from 'react-i18next'
import { Button } from 'react-bootstrap'
import Tooltip from '../../../shared/components/tooltip'
import Icon from '../../../shared/components/icon'
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
import { useProjectContext } from '../../../shared/context/project-context'
import * as eventTracking from '../../../infrastructure/event-tracking'
function PdfHybridDownloadButton() {
const { pdfDownloadUrl } = useCompileContext()
const { _id: projectId } = useProjectContext()
const { t } = useTranslation()
const description = pdfDownloadUrl
? t('download_pdf')
: t('please_compile_pdf_before_download')
function handleOnClick() {
eventTracking.sendMB('download-pdf-button-click', { projectId })
}
return (
<Tooltip
id="logs-toggle"
description={description}
overlayProps={{ placement: 'bottom' }}
>
<Button
onClick={handleOnClick}
bsStyle="link"
disabled={!pdfDownloadUrl}
download
href={pdfDownloadUrl || '#'}
target="_blank"
style={{ pointerEvents: 'auto' }}
>
<Icon type="download" fw />
</Button>
</Tooltip>
)
}
export default PdfHybridDownloadButton