leavers-survey-alert.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useEffect } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import usePersistedState from '../../../shared/hooks/use-persisted-state'
  4. import { useUserEmailsContext } from '../context/user-email-context'
  5. import { sendMB } from '../../../infrastructure/event-tracking'
  6. import OLNotification from '@/features/ui/components/ol/ol-notification'
  7. function sendMetrics(segmentation: 'view' | 'click' | 'close') {
  8. sendMB('institutional-leavers-survey-notification', { type: segmentation })
  9. }
  10. export function LeaversSurveyAlert() {
  11. const { t } = useTranslation()
  12. const {
  13. showInstitutionalLeaversSurveyUntil,
  14. setShowInstitutionalLeaversSurveyUntil,
  15. } = useUserEmailsContext()
  16. const [hide, setHide] = usePersistedState(
  17. 'hideInstitutionalLeaversSurvey',
  18. false,
  19. { listen: true }
  20. )
  21. function handleDismiss() {
  22. setShowInstitutionalLeaversSurveyUntil(0)
  23. setHide(true)
  24. sendMetrics('close')
  25. }
  26. function handleLinkClick() {
  27. sendMetrics('click')
  28. }
  29. const shouldDisplay =
  30. !hide && Date.now() <= showInstitutionalLeaversSurveyUntil
  31. useEffect(() => {
  32. if (shouldDisplay) {
  33. sendMetrics('view')
  34. }
  35. }, [shouldDisplay])
  36. if (!shouldDisplay) {
  37. return null
  38. }
  39. return (
  40. <OLNotification
  41. type="info"
  42. content={
  43. <>
  44. <strong>{t('limited_offer')}</strong>
  45. {`: ${t('institutional_leavers_survey_notification')} `}
  46. <a
  47. href="https://docs.google.com/forms/d/e/1FAIpQLSfYdeeoY5p1d31r5iUx1jw0O-Gd66vcsBi_Ntu3lJRMjV2EJA/viewform"
  48. target="_blank"
  49. rel="noopener noreferrer"
  50. onClick={handleLinkClick}
  51. >
  52. {t('take_short_survey')}
  53. </a>
  54. </>
  55. }
  56. isDismissible
  57. onDismiss={handleDismiss}
  58. className="mb-0"
  59. />
  60. )
  61. }