preview-error.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import { useTranslation } from 'react-i18next'
  4. import PreviewLogsPaneEntry from './preview-logs-pane-entry'
  5. import Icon from '../../../shared/components/icon'
  6. import { useEditorContext } from '../../../shared/context/editor-context'
  7. import StartFreeTrialButton from '../../../shared/components/start-free-trial-button'
  8. function PreviewError({ name }) {
  9. const { hasPremiumCompile, isProjectOwner } = useEditorContext({
  10. isProjectOwner: PropTypes.bool,
  11. })
  12. const { t } = useTranslation()
  13. let errorTitle
  14. let errorContent
  15. if (name === 'error') {
  16. errorTitle = t('server_error')
  17. errorContent = <>{t('somthing_went_wrong_compiling')}</>
  18. } else if (name === 'renderingError') {
  19. errorTitle = t('pdf_rendering_error')
  20. errorContent = <>{t('something_went_wrong_rendering_pdf')}</>
  21. } else if (name === 'clsiMaintenance') {
  22. errorTitle = t('server_error')
  23. errorContent = <>{t('clsi_maintenance')}</>
  24. } else if (name === 'clsiUnavailable') {
  25. errorTitle = t('server_error')
  26. errorContent = <>{t('clsi_unavailable')}</>
  27. } else if (name === 'tooRecentlyCompiled') {
  28. errorTitle = t('server_error')
  29. errorContent = <>{t('too_recently_compiled')}</>
  30. } else if (name === 'compileTerminated') {
  31. errorTitle = t('terminated')
  32. errorContent = <>{t('compile_terminated_by_user')}</>
  33. } else if (name === 'rateLimited') {
  34. errorTitle = t('pdf_compile_rate_limit_hit')
  35. errorContent = <>{t('project_flagged_too_many_compiles')}</>
  36. } else if (name === 'compileInProgress') {
  37. errorTitle = t('pdf_compile_in_progress_error')
  38. errorContent = <>{t('pdf_compile_try_again')}</>
  39. } else if (name === 'timedout') {
  40. errorTitle = t('timedout')
  41. errorContent = (
  42. <>
  43. {t('proj_timed_out_reason')}
  44. <div>
  45. <a
  46. href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F"
  47. target="_blank"
  48. >
  49. {t('learn_how_to_make_documents_compile_quickly')}
  50. </a>
  51. </div>
  52. </>
  53. )
  54. } else if (name === 'autoCompileDisabled') {
  55. errorTitle = t('autocompile_disabled')
  56. errorContent = <>{t('autocompile_disabled_reason')}</>
  57. } else if (name === 'projectTooLarge') {
  58. errorTitle = t('project_too_large')
  59. errorContent = <>{t('project_too_much_editable_text')}</>
  60. }
  61. return errorTitle ? (
  62. <>
  63. <PreviewLogsPaneEntry
  64. headerTitle={errorTitle}
  65. formattedContent={errorContent}
  66. entryAriaLabel={t('compile_error_entry_description')}
  67. level="error"
  68. />
  69. {name === 'timedout' &&
  70. window.ExposedSettings.enableSubscriptions &&
  71. !hasPremiumCompile ? (
  72. <TimeoutUpgradePrompt isProjectOwner={isProjectOwner} />
  73. ) : null}
  74. </>
  75. ) : null
  76. }
  77. function TimeoutUpgradePrompt({ isProjectOwner }) {
  78. const { t } = useTranslation()
  79. const timeoutUpgradePromptContent = (
  80. <>
  81. <p>{t('free_accounts_have_timeout_upgrade_to_increase')}</p>
  82. <p>{t('plus_upgraded_accounts_receive')}:</p>
  83. <div>
  84. <ul className="list-unstyled">
  85. <li>
  86. <Icon type="check" />
  87. &nbsp;
  88. {t('unlimited_projects')}
  89. </li>
  90. <li>
  91. <Icon type="check" />
  92. &nbsp;
  93. {t('collabs_per_proj', { collabcount: 'Multiple' })}
  94. </li>
  95. <li>
  96. <Icon type="check" />
  97. &nbsp;
  98. {t('full_doc_history')}
  99. </li>
  100. <li>
  101. <Icon type="check" />
  102. &nbsp;
  103. {t('sync_to_dropbox')}
  104. </li>
  105. <li>
  106. <Icon type="check" />
  107. &nbsp;
  108. {t('sync_to_github')}
  109. </li>
  110. <li>
  111. <Icon type="check" />
  112. &nbsp;
  113. {t('compile_larger_projects')}
  114. </li>
  115. </ul>
  116. </div>
  117. {isProjectOwner ? (
  118. <p className="text-center">
  119. <StartFreeTrialButton
  120. source="compile-timeout"
  121. buttonStyle="success"
  122. classes={{ button: 'row-spaced-small' }}
  123. />
  124. </p>
  125. ) : null}
  126. </>
  127. )
  128. return (
  129. <PreviewLogsPaneEntry
  130. headerTitle={
  131. isProjectOwner
  132. ? t('upgrade_for_longer_compiles')
  133. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  134. }
  135. formattedContent={timeoutUpgradePromptContent}
  136. entryAriaLabel={
  137. isProjectOwner
  138. ? t('upgrade_for_longer_compiles')
  139. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  140. }
  141. level="success"
  142. />
  143. )
  144. }
  145. PreviewError.propTypes = {
  146. name: PropTypes.string.isRequired,
  147. }
  148. TimeoutUpgradePrompt.propTypes = {
  149. isProjectOwner: PropTypes.bool.isRequired,
  150. }
  151. export default PreviewError