error-boundary-fallback.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import PropTypes from 'prop-types'
  2. import { Alert } from 'react-bootstrap'
  3. import { Trans, useTranslation } from 'react-i18next'
  4. function ErrorBoundaryFallback({ type }) {
  5. const { t } = useTranslation()
  6. // we create each instance of `<Trans/>` individually so `i18next-scanner` can detect hardcoded `i18nKey` values
  7. let content
  8. if (type === 'pdf') {
  9. content = (
  10. <>
  11. <p>{t('pdf_viewer_error')}</p>
  12. <p>
  13. <Trans
  14. i18nKey="try_recompile_project_or_troubleshoot"
  15. components={[
  16. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  17. <a href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems" />,
  18. ]}
  19. />
  20. </p>
  21. </>
  22. )
  23. } else if (type === 'logs') {
  24. content = (
  25. <>
  26. <p>{t('log_viewer_error')}</p>
  27. <p>
  28. <Trans
  29. i18nKey="try_recompile_project_or_troubleshoot"
  30. components={[
  31. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  32. <a href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems" />,
  33. ]}
  34. />
  35. </p>
  36. </>
  37. )
  38. } else {
  39. content = (
  40. <>
  41. <p>{t('pdf_preview_error')}</p>
  42. <p>
  43. <Trans
  44. i18nKey="try_recompile_project_or_troubleshoot"
  45. components={[
  46. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  47. <a href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems" />,
  48. ]}
  49. />
  50. </p>
  51. </>
  52. )
  53. }
  54. return (
  55. <div className="pdf-error-alert">
  56. <Alert bsStyle="danger">{content}</Alert>
  57. </div>
  58. )
  59. }
  60. ErrorBoundaryFallback.propTypes = {
  61. type: PropTypes.oneOf(['preview', 'pdf', 'logs']).isRequired,
  62. }
  63. export default ErrorBoundaryFallback