download-pdf.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Icon from '../../../shared/components/icon'
  5. import Tooltip from '../../../shared/components/tooltip'
  6. import * as eventTracking from '../../../infrastructure/event-tracking'
  7. export default function DownloadPDF() {
  8. const { t } = useTranslation()
  9. const { pdfDownloadUrl, pdfUrl } = useCompileContext()
  10. const { _id: projectId } = useProjectContext()
  11. function sendDownloadEvent() {
  12. eventTracking.sendMB('download-pdf-button-click', {
  13. projectId,
  14. location: 'left-menu',
  15. })
  16. }
  17. if (pdfUrl) {
  18. return (
  19. <a
  20. href={pdfDownloadUrl || pdfUrl}
  21. target="_blank"
  22. rel="noreferrer"
  23. onClick={sendDownloadEvent}
  24. >
  25. <Icon type="file-pdf-o" modifier="2x" />
  26. <br />
  27. PDF
  28. </a>
  29. )
  30. } else {
  31. return (
  32. <Tooltip
  33. id="disabled-pdf-download"
  34. description={t('please_compile_pdf_before_download')}
  35. overlayProps={{ placement: 'bottom' }}
  36. >
  37. <div className="link-disabled">
  38. <Icon type="file-pdf-o" modifier="2x" />
  39. <br />
  40. PDF
  41. </div>
  42. </Tooltip>
  43. )
  44. }
  45. }