download-pdf.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { useTranslation } from 'react-i18next'
  2. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  3. import { useProjectContext } from '../../../shared/context/project-context'
  4. import * as eventTracking from '../../../infrastructure/event-tracking'
  5. import { isSmallDevice } from '../../../infrastructure/event-tracking'
  6. import MaterialIcon from '@/shared/components/material-icon'
  7. import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
  8. export default function DownloadPDF() {
  9. const { t } = useTranslation()
  10. const { pdfDownloadUrl, pdfUrl } = useCompileContext()
  11. const { projectId } = useProjectContext()
  12. function sendDownloadEvent() {
  13. eventTracking.sendMB('download-pdf-button-click', {
  14. projectId,
  15. location: 'left-menu',
  16. isSmallDevice,
  17. })
  18. }
  19. if (pdfUrl) {
  20. return (
  21. <a
  22. href={pdfDownloadUrl || pdfUrl}
  23. target="_blank"
  24. rel="noreferrer"
  25. onClick={sendDownloadEvent}
  26. >
  27. <MaterialIcon type="picture_as_pdf" size="2x" />
  28. <br />
  29. PDF
  30. </a>
  31. )
  32. } else {
  33. return (
  34. <OLTooltip
  35. id="disabled-pdf-download"
  36. description={t('please_compile_pdf_before_download')}
  37. overlayProps={{ placement: 'bottom' }}
  38. >
  39. <div className="link-disabled">
  40. <MaterialIcon type="picture_as_pdf" size="2x" />
  41. <br />
  42. PDF
  43. </div>
  44. </OLTooltip>
  45. )
  46. }
  47. }