+
+ {t('limited_offer')}
+ {`: ${t('institutional_leavers_survey_notification')} `}
+
+ {t('take_short_survey')}
+
+
+
+ )
+}
diff --git a/services/web/frontend/js/features/settings/context/user-email-context.tsx b/services/web/frontend/js/features/settings/context/user-email-context.tsx
index e42fe91f2a..c8d017a6b6 100644
--- a/services/web/frontend/js/features/settings/context/user-email-context.tsx
+++ b/services/web/frontend/js/features/settings/context/user-email-context.tsx
@@ -13,6 +13,9 @@ import { Affiliation } from '../../../../../types/affiliation'
import { normalize, NormalizedObject } from '../../../utils/normalize'
import { getJSON } from '../../../infrastructure/fetch-json'
import useAsync from '../../../shared/hooks/use-async'
+import usePersistedState from '../../../shared/hooks/use-persisted-state'
+
+const ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000
// eslint-disable-next-line no-unused-vars
export enum Actions {
@@ -194,6 +197,10 @@ const reducer = (state: State, action: Action) => {
}
function useUserEmails() {
+ const [, setExpirationDate] = usePersistedState(
+ 'showInstitutionalLeaversSurveyUntil',
+ 0
+ )
const [state, unsafeDispatch] = useReducer(reducer, initialState)
const dispatch = useSafeDispatch(unsafeDispatch)
const { data, isLoading, isError, isSuccess, runAsync } = useAsync()
@@ -211,12 +218,34 @@ function useUserEmails() {
getEmails()
}, [getEmails])
+ const resetLeaversSurveyExpiration = useCallback(
+ (deletedEmail: UserEmailData) => {
+ if (!data) {
+ return
+ }
+ const emailData = data as UserEmailData[]
+ if (
+ deletedEmail.emailHasInstitutionLicence ||
+ deletedEmail.affiliation?.pastReconfirmDate
+ ) {
+ const stillHasLicenseAccess = emailData.some(
+ userEmail => userEmail.emailHasInstitutionLicence
+ )
+ if (stillHasLicenseAccess) {
+ setExpirationDate(Date.now() + ONE_WEEK_IN_MS)
+ }
+ }
+ },
+ [data, setExpirationDate]
+ )
+
return {
state,
isInitializing: isLoading && !data,
isInitializingSuccess: isSuccess,
isInitializingError: isError,
getEmails,
+ resetLeaversSurveyExpiration,
setLoading: useCallback(
(flag: boolean) => dispatch(ActionCreators.setLoading(flag)),
[dispatch]
diff --git a/services/web/frontend/stories/settings/leavers-survey-alert.stories.tsx b/services/web/frontend/stories/settings/leavers-survey-alert.stories.tsx
new file mode 100644
index 0000000000..b793913f9d
--- /dev/null
+++ b/services/web/frontend/stories/settings/leavers-survey-alert.stories.tsx
@@ -0,0 +1,15 @@
+import EmailsSection from '../../js/features/settings/components/emails-section'
+import { LeaversSurveyAlert } from '../../js/features/settings/components/leavers-survey-alert'
+
+export const SurveyAlert = () => {
+ localStorage.setItem(
+ 'showInstitutionalLeaversSurveyUntil',
+ (Date.now() + 1000 * 60 * 60).toString()
+ )
+ return