preview-error.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 { useApplicationContext } from '../../../shared/context/application-context'
  7. import { useEditorContext } from '../../../shared/context/editor-context'
  8. import { startFreeTrial } from '../../../main/account-upgrade'
  9. function PreviewError({ name }) {
  10. const { isProjectOwner } = useEditorContext()
  11. const {
  12. exposedSettings: { enableSubscriptions }
  13. } = useApplicationContext()
  14. const { t } = useTranslation()
  15. let errorTitle
  16. let errorContent
  17. if (name === 'error') {
  18. errorTitle = t('server_error')
  19. errorContent = <>{t('somthing_went_wrong_compiling')}</>
  20. } else if (name === 'renderingError') {
  21. errorTitle = t('pdf_rendering_error')
  22. errorContent = <>{t('something_went_wrong_rendering_pdf')}</>
  23. } else if (name === 'clsiMaintenance') {
  24. errorTitle = t('server_error')
  25. errorContent = <>{t('clsi_maintenance')}</>
  26. } else if (name === 'clsiUnavailable') {
  27. errorTitle = t('server_error')
  28. errorContent = <>{t('clsi_unavailable')}</>
  29. } else if (name === 'tooRecentlyCompiled') {
  30. errorTitle = t('server_error')
  31. errorContent = <>{t('too_recently_compiled')}</>
  32. } else if (name === 'compileTerminated') {
  33. errorTitle = t('terminated')
  34. errorContent = <>{t('compile_terminated_by_user')}</>
  35. } else if (name === 'rateLimited') {
  36. errorTitle = t('pdf_compile_rate_limit_hit')
  37. errorContent = <>{t('project_flagged_too_many_compiles')}</>
  38. } else if (name === 'compileInProgress') {
  39. errorTitle = t('pdf_compile_in_progress_error')
  40. errorContent = <>{t('pdf_compile_try_again')}</>
  41. } else if (name === 'timedout') {
  42. errorTitle = t('timedout')
  43. errorContent = (
  44. <>
  45. {t('proj_timed_out_reason')}
  46. <div>
  47. <a
  48. href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F"
  49. target="_blank"
  50. >
  51. {t('learn_how_to_make_documents_compile_quickly')}
  52. </a>
  53. </div>
  54. </>
  55. )
  56. } else if (name === 'autoCompileDisabled') {
  57. errorTitle = t('autocompile_disabled')
  58. errorContent = <>{t('autocompile_disabled_reason')}</>
  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' && enableSubscriptions ? (
  69. <TimeoutUpgradePrompt isProjectOwner={isProjectOwner} />
  70. ) : null}
  71. </>
  72. ) : null
  73. }
  74. function TimeoutUpgradePrompt({ isProjectOwner }) {
  75. const { t } = useTranslation()
  76. function handleStartFreeTrialClick() {
  77. startFreeTrial('compile-timeout')
  78. }
  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. <button
  120. className="btn btn-success row-spaced-small"
  121. onClick={handleStartFreeTrialClick}
  122. >
  123. {t('start_free_trial')}
  124. </button>
  125. </p>
  126. ) : null}
  127. </>
  128. )
  129. return (
  130. <PreviewLogsPaneEntry
  131. headerTitle={
  132. isProjectOwner
  133. ? t('upgrade_for_longer_compiles')
  134. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  135. }
  136. formattedContent={timeoutUpgradePromptContent}
  137. entryAriaLabel={
  138. isProjectOwner
  139. ? t('upgrade_for_longer_compiles')
  140. : t('ask_proj_owner_to_upgrade_for_longer_compiles')
  141. }
  142. level="success"
  143. />
  144. )
  145. }
  146. PreviewError.propTypes = {
  147. name: PropTypes.string.isRequired
  148. }
  149. TimeoutUpgradePrompt.propTypes = {
  150. isProjectOwner: PropTypes.bool.isRequired
  151. }
  152. export default PreviewError