preview-error.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. }
  58. return errorTitle ? (
  59. <>
  60. <PreviewLogsPaneEntry
  61. headerTitle={errorTitle}
  62. formattedContent={errorContent}
  63. entryAriaLabel={t('compile_error_entry_description')}
  64. level="error"
  65. />
  66. {name === 'timedout' &&
  67. window.ExposedSettings.enableSubscriptions &&
  68. !hasPremiumCompile ? (
  69. <TimeoutUpgradePrompt isProjectOwner={isProjectOwner} />
  70. ) : null}
  71. </>
  72. ) : null
  73. }
  74. function TimeoutUpgradePrompt({ isProjectOwner }) {
  75. const { t } = useTranslation()
  76. const timeoutUpgradePromptContent = (
  77. <>
  78. <p>{t('free_accounts_have_timeout_upgrade_to_increase')}</p>
  79. <p>{t('plus_upgraded_accounts_receive')}:</p>
  80. <div>
  81. <ul className="list-unstyled">
  82. <li>
  83. <Icon type="check" />
  84. &nbsp;
  85. {t('unlimited_projects')}
  86. </li>
  87. <li>
  88. <Icon type="check" />
  89. &nbsp;
  90. {t('collabs_per_proj', { collabcount: 'Multiple' })}
  91. </li>
  92. <li>
  93. <Icon type="check" />
  94. &nbsp;
  95. {t('full_doc_history')}
  96. </li>
  97. <li>
  98. <Icon type="check" />
  99. &nbsp;
  100. {t('sync_to_dropbox')}
  101. </li>
  102. <li>
  103. <Icon type="check" />
  104. &nbsp;
  105. {t('sync_to_github')}
  106. </li>
  107. <li>
  108. <Icon type="check" />
  109. &nbsp;
  110. {t('compile_larger_projects')}
  111. </li>
  112. </ul>
  113. </div>
  114. {isProjectOwner ? (
  115. <p className="text-center">
  116. <StartFreeTrialButton
  117. source="compile-timeout"
  118. buttonStyle="success"
  119. classes={{ button: 'row-spaced-small' }}
  120. />
  121. </p>
  122. ) : null}
  123. </>
  124. )
  125. return (
  126. <PreviewLogsPaneEntry
  127. headerTitle={
  128. isProjectOwner
  129. ? t('upgrade_for_longer_compiles')
  130. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  131. }
  132. formattedContent={timeoutUpgradePromptContent}
  133. entryAriaLabel={
  134. isProjectOwner
  135. ? t('upgrade_for_longer_compiles')
  136. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  137. }
  138. level="success"
  139. />
  140. )
  141. }
  142. PreviewError.propTypes = {
  143. name: PropTypes.string.isRequired,
  144. }
  145. TimeoutUpgradePrompt.propTypes = {
  146. isProjectOwner: PropTypes.bool.isRequired,
  147. }
  148. export default PreviewError