sso-alert.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { useState } from 'react'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import getMeta from '../../../../utils/meta'
  4. import OLNotification from '@/shared/components/ol/ol-notification'
  5. export function SSOAlert() {
  6. const { t } = useTranslation()
  7. const institutionLinked = getMeta('ol-institutionLinked')
  8. const institutionEmailNonCanonical = getMeta(
  9. 'ol-institutionEmailNonCanonical'
  10. )
  11. const samlError = getMeta('ol-samlError')
  12. const [infoClosed, setInfoClosed] = useState(false)
  13. const [warningClosed, setWarningClosed] = useState(false)
  14. const [errorClosed, setErrorClosed] = useState(false)
  15. const handleInfoClosed = () => setInfoClosed(true)
  16. const handleWarningClosed = () => setWarningClosed(true)
  17. const handleErrorClosed = () => setErrorClosed(true)
  18. if (samlError) {
  19. const content =
  20. samlError.name === 'SAMLCommonsReconfirmationUnableToFindUserError' ? (
  21. <Trans
  22. i18nKey="saml_commons_reconfirmation_unable_to_find_user"
  23. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  24. components={[<a href="/contact" target="_blank" />]}
  25. />
  26. ) : (
  27. <>
  28. {samlError.translatedMessage
  29. ? samlError.translatedMessage
  30. : samlError.message}
  31. {samlError.tryAgain && <p>{t('try_again')}</p>}
  32. </>
  33. )
  34. return !errorClosed ? (
  35. <OLNotification
  36. type="error"
  37. content={content}
  38. isDismissible
  39. onDismiss={handleErrorClosed}
  40. />
  41. ) : null
  42. }
  43. if (!institutionLinked) {
  44. return null
  45. }
  46. return (
  47. <>
  48. {!infoClosed && (
  49. <OLNotification
  50. type="info"
  51. content={
  52. <>
  53. <p>
  54. <Trans
  55. i18nKey="institution_acct_successfully_linked_2"
  56. components={[<strong />]} // eslint-disable-line react/jsx-key
  57. values={{ institutionName: institutionLinked.universityName }}
  58. shouldUnescape
  59. tOptions={{ interpolation: { escapeValue: true } }}
  60. />
  61. </p>
  62. {institutionLinked.hasEntitlement && (
  63. <p>
  64. <Trans
  65. i18nKey="this_grants_access_to_features_2"
  66. components={[<strong />]} // eslint-disable-line react/jsx-key
  67. values={{ featureType: t('commons') }}
  68. shouldUnescape
  69. tOptions={{ interpolation: { escapeValue: true } }}
  70. />
  71. </p>
  72. )}
  73. </>
  74. }
  75. isDismissible
  76. onDismiss={handleInfoClosed}
  77. />
  78. )}
  79. {!warningClosed && institutionEmailNonCanonical && (
  80. <OLNotification
  81. type="warning"
  82. content={
  83. <Trans
  84. i18nKey="in_order_to_match_institutional_metadata_2"
  85. components={[<strong />]} // eslint-disable-line react/jsx-key
  86. values={{ email: institutionEmailNonCanonical }}
  87. shouldUnescape
  88. tOptions={{ interpolation: { escapeValue: true } }}
  89. />
  90. }
  91. isDismissible
  92. onDismiss={handleWarningClosed}
  93. />
  94. )}
  95. </>
  96. )
  97. }