file-view-refresh-error.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import type { ElementType } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
  4. import { BinaryFile, hasProvider } from '../types/binary-file'
  5. const tprLinkedFileRefreshError = importOverleafModules(
  6. 'tprLinkedFileRefreshError'
  7. ) as {
  8. import: { LinkedFileRefreshError: ElementType }
  9. path: string
  10. }[]
  11. type FileViewRefreshErrorProps = {
  12. file: BinaryFile
  13. refreshError: string
  14. }
  15. export default function FileViewRefreshError({
  16. file,
  17. refreshError,
  18. }: FileViewRefreshErrorProps) {
  19. const isMendeleyOrZotero =
  20. hasProvider(file, 'mendeley') || hasProvider(file, 'zotero')
  21. return (
  22. <div className="row">
  23. <br />
  24. {isMendeleyOrZotero ? (
  25. <FileViewMendeleyOrZoteroRefreshError file={file} />
  26. ) : (
  27. <FileViewDefaultRefreshError refreshError={refreshError} />
  28. )}
  29. </div>
  30. )
  31. }
  32. type FileViewMendeleyOrZoteroRefreshErrorProps = {
  33. file: BinaryFile
  34. }
  35. function FileViewMendeleyOrZoteroRefreshError({
  36. file,
  37. }: FileViewMendeleyOrZoteroRefreshErrorProps) {
  38. const { t } = useTranslation()
  39. return (
  40. <div
  41. className="alert alert-danger col-md-10 col-md-offset-1"
  42. style={{ display: 'flex', alignItems: 'center', gap: '10px' }}
  43. >
  44. <div>
  45. {t('something_not_right')}!&nbsp;
  46. {tprLinkedFileRefreshError.map(
  47. ({ import: { LinkedFileRefreshError }, path }) => (
  48. <LinkedFileRefreshError key={path} file={file} />
  49. )
  50. )}
  51. </div>
  52. <div className="text-center">
  53. <button className="btn btn-danger">
  54. <a
  55. href="/user/settings"
  56. target="_blank"
  57. style={{ fontWeight: 'bold', textDecoration: 'none' }}
  58. >
  59. {t('go_to_settings')}
  60. </a>
  61. </button>
  62. </div>
  63. </div>
  64. )
  65. }
  66. type FileViewDefaultRefreshErrorProps = {
  67. refreshError: string
  68. }
  69. function FileViewDefaultRefreshError({
  70. refreshError,
  71. }: FileViewDefaultRefreshErrorProps) {
  72. const { t } = useTranslation()
  73. return (
  74. <div className="alert alert-danger col-md-6 col-md-offset-3">
  75. {t('access_denied')}: {refreshError}
  76. </div>
  77. )
  78. }