sso-alert.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { useState } from 'react'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import getMeta from '../../../../utils/meta'
  4. import OLNotification from '@/features/ui/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. return !errorClosed ? (
  20. <OLNotification
  21. type="error"
  22. content={
  23. <>
  24. {samlError.translatedMessage
  25. ? samlError.translatedMessage
  26. : samlError.message}
  27. {samlError.tryAgain && <p>{t('try_again')}</p>}
  28. </>
  29. }
  30. isDismissible
  31. onDismiss={handleErrorClosed}
  32. />
  33. ) : null
  34. }
  35. if (!institutionLinked) {
  36. return null
  37. }
  38. return (
  39. <>
  40. {!infoClosed && (
  41. <OLNotification
  42. type="info"
  43. content={
  44. <>
  45. <p>
  46. <Trans
  47. i18nKey="institution_acct_successfully_linked_2"
  48. components={[<strong />]} // eslint-disable-line react/jsx-key
  49. values={{ institutionName: institutionLinked.universityName }}
  50. shouldUnescape
  51. tOptions={{ interpolation: { escapeValue: true } }}
  52. />
  53. </p>
  54. {institutionLinked.hasEntitlement && (
  55. <p>
  56. <Trans
  57. i18nKey="this_grants_access_to_features_2"
  58. components={[<strong />]} // eslint-disable-line react/jsx-key
  59. values={{ featureType: t('professional') }}
  60. shouldUnescape
  61. tOptions={{ interpolation: { escapeValue: true } }}
  62. />
  63. </p>
  64. )}
  65. </>
  66. }
  67. isDismissible
  68. onDismiss={handleInfoClosed}
  69. />
  70. )}
  71. {!warningClosed && institutionEmailNonCanonical && (
  72. <OLNotification
  73. type="warning"
  74. content={
  75. <Trans
  76. i18nKey="in_order_to_match_institutional_metadata_2"
  77. components={[<strong />]} // eslint-disable-line react/jsx-key
  78. values={{ email: institutionEmailNonCanonical }}
  79. shouldUnescape
  80. tOptions={{ interpolation: { escapeValue: true } }}
  81. />
  82. }
  83. isDismissible
  84. onDismiss={handleWarningClosed}
  85. />
  86. )}
  87. </>
  88. )
  89. }