preview-error.js 4.7 KB

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