2022-05-24 07:12:21 -04:00
|
|
|
import { useEffect } from 'react'
|
2022-05-16 04:03:42 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
2022-05-24 03:47:08 -04:00
|
|
|
import { useUserEmailsContext } from '../context/user-email-context'
|
2022-05-24 07:12:21 -04:00
|
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
2022-05-24 07:12:21 -04:00
|
|
|
|
|
|
|
function sendMetrics(segmentation: 'view' | 'click' | 'close') {
|
|
|
|
sendMB('institutional-leavers-survey-notification', { type: segmentation })
|
|
|
|
}
|
2022-05-16 04:03:42 -04:00
|
|
|
|
|
|
|
export function LeaversSurveyAlert() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2022-05-24 03:47:08 -04:00
|
|
|
const {
|
|
|
|
showInstitutionalLeaversSurveyUntil,
|
|
|
|
setShowInstitutionalLeaversSurveyUntil,
|
|
|
|
} = useUserEmailsContext()
|
2022-05-18 09:45:31 -04:00
|
|
|
|
|
|
|
const [hide, setHide] = usePersistedState(
|
|
|
|
'hideInstitutionalLeaversSurvey',
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
2022-05-16 04:03:42 -04:00
|
|
|
function handleDismiss() {
|
2022-05-24 03:47:08 -04:00
|
|
|
setShowInstitutionalLeaversSurveyUntil(0)
|
2022-05-18 09:45:31 -04:00
|
|
|
setHide(true)
|
2022-05-24 07:12:21 -04:00
|
|
|
sendMetrics('close')
|
2022-05-16 04:03:42 -04:00
|
|
|
}
|
|
|
|
|
2022-05-24 07:12:21 -04:00
|
|
|
function handleLinkClick() {
|
|
|
|
sendMetrics('click')
|
2022-05-16 04:03:42 -04:00
|
|
|
}
|
|
|
|
|
2022-05-24 07:12:21 -04:00
|
|
|
const shouldDisplay =
|
|
|
|
!hide && Date.now() <= showInstitutionalLeaversSurveyUntil
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (shouldDisplay) {
|
|
|
|
sendMetrics('view')
|
|
|
|
}
|
|
|
|
}, [shouldDisplay])
|
|
|
|
|
|
|
|
if (!shouldDisplay) {
|
2022-05-18 09:45:31 -04:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2022-05-16 04:03:42 -04:00
|
|
|
return (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLNotification
|
2024-04-23 06:25:05 -04:00
|
|
|
type="info"
|
|
|
|
content={
|
|
|
|
<>
|
|
|
|
<strong>{t('limited_offer')}</strong>
|
|
|
|
{`: ${t('institutional_leavers_survey_notification')} `}
|
|
|
|
<a
|
|
|
|
href="https://docs.google.com/forms/d/e/1FAIpQLSfYdeeoY5p1d31r5iUx1jw0O-Gd66vcsBi_Ntu3lJRMjV2EJA/viewform"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
onClick={handleLinkClick}
|
|
|
|
>
|
|
|
|
{t('take_short_survey')}
|
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
isDismissible
|
|
|
|
onDismiss={handleDismiss}
|
|
|
|
className="mb-0"
|
|
|
|
/>
|
2022-05-16 04:03:42 -04:00
|
|
|
)
|
|
|
|
}
|