preview-error.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import PropTypes from 'prop-types'
  2. import { useTranslation, Trans } 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. } else if (name === 'failure') {
  60. errorTitle = t('no_pdf_error_title')
  61. errorContent = (
  62. <>
  63. <Trans i18nKey="no_pdf_error_explanation" />
  64. <ul className="log-entry-formatted-content-list">
  65. <li>
  66. <Trans i18nKey="no_pdf_error_reason_unrecoverable_error" />
  67. </li>
  68. <li>
  69. <Trans
  70. i18nKey="no_pdf_error_reason_no_content"
  71. components={{ code: <code /> }}
  72. />
  73. </li>
  74. <li>
  75. <Trans
  76. i18nKey="no_pdf_error_reason_output_pdf_already_exists"
  77. components={{ code: <code /> }}
  78. />
  79. </li>
  80. </ul>
  81. </>
  82. )
  83. }
  84. return errorTitle ? (
  85. <>
  86. <PreviewLogsPaneEntry
  87. headerTitle={errorTitle}
  88. formattedContent={errorContent}
  89. entryAriaLabel={t('compile_error_entry_description')}
  90. level="error"
  91. />
  92. {name === 'timedout' &&
  93. window.ExposedSettings.enableSubscriptions &&
  94. !hasPremiumCompile ? (
  95. <TimeoutUpgradePrompt isProjectOwner={isProjectOwner} />
  96. ) : null}
  97. </>
  98. ) : null
  99. }
  100. function TimeoutUpgradePrompt({ isProjectOwner }) {
  101. const { t } = useTranslation()
  102. const timeoutUpgradePromptContent = (
  103. <>
  104. <p>{t('free_accounts_have_timeout_upgrade_to_increase')}</p>
  105. <p>{t('plus_upgraded_accounts_receive')}:</p>
  106. <div>
  107. <ul className="list-unstyled">
  108. <li>
  109. <Icon type="check" />
  110. &nbsp;
  111. {t('unlimited_projects')}
  112. </li>
  113. <li>
  114. <Icon type="check" />
  115. &nbsp;
  116. {t('collabs_per_proj', { collabcount: 'Multiple' })}
  117. </li>
  118. <li>
  119. <Icon type="check" />
  120. &nbsp;
  121. {t('full_doc_history')}
  122. </li>
  123. <li>
  124. <Icon type="check" />
  125. &nbsp;
  126. {t('sync_to_dropbox')}
  127. </li>
  128. <li>
  129. <Icon type="check" />
  130. &nbsp;
  131. {t('sync_to_github')}
  132. </li>
  133. <li>
  134. <Icon type="check" />
  135. &nbsp;
  136. {t('compile_larger_projects')}
  137. </li>
  138. </ul>
  139. </div>
  140. {isProjectOwner ? (
  141. <p className="text-center">
  142. <StartFreeTrialButton
  143. source="compile-timeout"
  144. buttonStyle="success"
  145. classes={{ button: 'row-spaced-small' }}
  146. />
  147. </p>
  148. ) : null}
  149. </>
  150. )
  151. return (
  152. <PreviewLogsPaneEntry
  153. headerTitle={
  154. isProjectOwner
  155. ? t('upgrade_for_longer_compiles')
  156. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  157. }
  158. formattedContent={timeoutUpgradePromptContent}
  159. entryAriaLabel={
  160. isProjectOwner
  161. ? t('upgrade_for_longer_compiles')
  162. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  163. }
  164. level="success"
  165. />
  166. )
  167. }
  168. PreviewError.propTypes = {
  169. name: PropTypes.string.isRequired,
  170. }
  171. TimeoutUpgradePrompt.propTypes = {
  172. isProjectOwner: PropTypes.bool.isRequired,
  173. }
  174. export default PreviewError