export-document-toasts.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 ExportDocumentSuccessToast = ({ data }: { data?: any }) => {
  25. const type = data?.type
  26. if (type === 'docx') {
  27. return (
  28. <Trans
  29. i18nKey="docx_export_feedback_message"
  30. components={[
  31. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  32. <a
  33. href="https://forms.gle/Fg4BUXV2yv61hStX8"
  34. target="_BLANK"
  35. rel="noopener noreferrer"
  36. />,
  37. ]}
  38. />
  39. )
  40. } else if (type === 'markdown') {
  41. return (
  42. <Trans
  43. i18nKey="markdown_export_feedback_message"
  44. components={[
  45. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  46. <a
  47. href="https://forms.gle/wc43zEukeqpec9mAA"
  48. target="_BLANK"
  49. rel="noopener noreferrer"
  50. />,
  51. ]}
  52. />
  53. )
  54. } else {
  55. return (
  56. <Trans
  57. i18nKey="generic_export_feedback_message"
  58. components={[
  59. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  60. <a href="/contact" target="_BLANK" rel="noopener noreferrer" />,
  61. ]}
  62. />
  63. )
  64. }
  65. }
  66. const generators: GlobalToastGeneratorEntry[] = [
  67. {
  68. key: 'export-document:error',
  69. generator: () => ({
  70. content: <ExportDocumentErrorToast />,
  71. type: 'error',
  72. autoHide: true,
  73. delay: 5000,
  74. isDismissible: true,
  75. }),
  76. },
  77. {
  78. key: 'export-document:preparing',
  79. generator: () => ({
  80. content: <PreparingExportToast />,
  81. type: 'info',
  82. autoHide: false,
  83. isDismissible: true,
  84. }),
  85. },
  86. {
  87. key: 'export-document:success',
  88. generator: (data: any) => ({
  89. content: <ExportDocumentSuccessToast data={data} />,
  90. type: 'success',
  91. autoHide: true,
  92. delay: 45000,
  93. isDismissible: true,
  94. }),
  95. },
  96. ]
  97. export default generators
  98. export const showExportDocumentError = () => {
  99. window.dispatchEvent(
  100. new CustomEvent('ide:show-toast', {
  101. detail: { key: 'export-document:error' },
  102. })
  103. )
  104. }
  105. export const showPreparingExportToast = () => {
  106. const handle = `export-document-preparing-${Date.now()}`
  107. window.dispatchEvent(
  108. new CustomEvent('ide:show-toast', {
  109. detail: { key: 'export-document:preparing', handle },
  110. })
  111. )
  112. return handle
  113. }
  114. export const hidePreparingExportToast = (handle: string) => {
  115. window.dispatchEvent(
  116. new CustomEvent('ide:dismiss-toast', {
  117. detail: { key: 'export-document:preparing', handle },
  118. })
  119. )
  120. }
  121. export const showExportDocumentSuccess = (type: 'docx' | 'markdown') => {
  122. window.dispatchEvent(
  123. new CustomEvent('ide:show-toast', {
  124. detail: { key: 'export-document:success', type },
  125. })
  126. )
  127. }