export-document-toasts.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { GlobalToastGeneratorEntry } from '@/features/ide-react/components/global-toasts'
  2. import { Trans, useTranslation } from 'react-i18next'
  3. const PreparingExportToast = () => {
  4. const { t } = useTranslation()
  5. return <span>{t('preparing_for_export')}</span>
  6. }
  7. const ExportDocumentErrorToast = () => {
  8. const { t } = useTranslation()
  9. return (
  10. <>
  11. <p>
  12. <b>{t('we_couldnt_export_this_document')}</b>
  13. </p>
  14. <Trans
  15. i18nKey="the_document_contains_formatting_we_werent_able_to_convert_contact_support_if_you_need_help"
  16. components={[
  17. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  18. <a href="/contact" target="_BLANK" rel="noopener noreferrer" />,
  19. ]}
  20. />
  21. </>
  22. )
  23. }
  24. const generators: GlobalToastGeneratorEntry[] = [
  25. {
  26. key: 'export-document:error',
  27. generator: () => ({
  28. content: <ExportDocumentErrorToast />,
  29. type: 'error',
  30. autoHide: true,
  31. delay: 5000,
  32. isDismissible: true,
  33. }),
  34. },
  35. {
  36. key: 'export-document:preparing',
  37. generator: () => ({
  38. content: <PreparingExportToast />,
  39. type: 'info',
  40. autoHide: false,
  41. isDismissible: true,
  42. }),
  43. },
  44. ]
  45. export default generators
  46. export const showExportDocumentError = () => {
  47. window.dispatchEvent(
  48. new CustomEvent('ide:show-toast', {
  49. detail: { key: 'export-document:error' },
  50. })
  51. )
  52. }
  53. export const showPreparingExportToast = () => {
  54. const handle = `export-document-preparing-${Date.now()}`
  55. window.dispatchEvent(
  56. new CustomEvent('ide:show-toast', {
  57. detail: { key: 'export-document:preparing', handle },
  58. })
  59. )
  60. return handle
  61. }
  62. export const hidePreparingExportToast = (handle: string) => {
  63. window.dispatchEvent(
  64. new CustomEvent('ide:dismiss-toast', {
  65. detail: { key: 'export-document:preparing', handle },
  66. })
  67. )
  68. }