Skip to content

Commit

Permalink
Dismissing renewal popup is permanent
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Jul 5, 2023
1 parent 6a12f2c commit 7865748
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 47 deletions.
109 changes: 63 additions & 46 deletions src/app/components/shell/microsurvey-popup/adoption-content.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, {useRef} from 'react';
import React from 'react';
import useUserContext from '~/contexts/user';
import {useLocation} from 'react-router-dom';
import {useToggle} from '~/helpers/data';
import cookie from '~/helpers/cookie';

const DISMISSED_KEY = 'renewal_dialog_dismissed';
const YESTERDAY = Date.now() - 60 * 60 * 24 * 1000;
// const YESTERDAY = Date.now() - 60 * 60 * 24 * 1000;

function useCookieKey(key) {
return React.useReducer(
Expand All @@ -17,64 +16,82 @@ function useCookieKey(key) {
);
}

export default function useAdoptionMicrosurveyContent() {
const {userModel} = useUserContext();
const {first_name: name} = userModel || {};
function useDismissalCookie() {
const [cookieValue, setCookieValue] = useCookieKey(DISMISSED_KEY);
const recentlyDismissed = React.useMemo(
() => +Number(cookieValue) > YESTERDAY,
const clicked = React.useMemo(
() => +Number(cookieValue) > 0,
[cookieValue]
);
const [clicked, disable] = useToggle(recentlyDismissed);
const ready = React.useMemo(
() => !clicked && userModel?.renewal_eligible,
[clicked, userModel]
);
const ref = useRef();
const {userModel} = useUserContext();
const isFaculty = userModel?.accountsModel?.faculty_status === 'confirmed_faculty';
const {pathname} = useLocation();

// Dismiss upon navigation
React.useEffect(
const ready = React.useMemo(
() => {
if (!clicked && pathname === '/renewal-form') {
disable();
if (pathname === '/renewal-form') {
return false;
}
return !clicked && isFaculty;
},
[pathname, clicked, disable]
[clicked, isFaculty, pathname]
);
const disable = React.useCallback(
() => setCookieValue(Date.now().toString()),
[setCookieValue]
);

// On dismiss, write cookie entry
// Dismiss upon navigation
React.useEffect(
() => {
if (!recentlyDismissed && clicked) {
setCookieValue(Date.now().toString());
}
window.setTimeout(
() => {
if (!clicked && pathname === '/renewal-form') {
disable();
}
},
10
);
},
[clicked, recentlyDismissed, setCookieValue]
[pathname, disable, clicked]
);

function AdoptionContent({children}) {
return (
<div
className="microsurvey-content"
ref={ref}
data-analytics-view
data-analytics-nudge="adoption"
data-nudge-placement="popup"
>
{children}
<h1>
Hi, {name}. Could you update our records
of which books you&apos;re using?
Fill out the <a
return [ready, disable];
}

function AdoptionContentBase({children, disable}) {
const {userModel} = useUserContext();
const {first_name: name} = userModel || {};

return (
<div
className="microsurvey-content"
data-analytics-view
data-analytics-nudge="adoption"
data-nudge-placement="popup"
>
{children}
<h1>
Hi, {name}. Could you update our records
of which books you&apos;re using?
Fill out the <a
href="/renewal-form?from=popup"
onClick={disable}
data-nudge-action="interacted"
>form here</a>.
</h1>
</div>
);
}
onClick={() => disable()}
data-nudge-action="interacted"
>form here</a>.
</h1>
</div>
);
}

export default function useAdoptionMicrosurveyContent() {
const [ready, disable] = useDismissalCookie();
const AdoptionContent = React.useCallback(
({children}) => (
<AdoptionContentBase disable={disable}>
{children}
</AdoptionContentBase>
),
[disable]
);

return [ready, AdoptionContent];
}
1 change: 0 additions & 1 deletion src/app/models/usermodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ function oldUserModel(sfUserModel) {
rejectedFaculty,
is_newflow: sfUserModel.is_newflow,
username: sfUserModel.id,
renewal_eligible: sfUserModel.renewal_eligible,
self_reported_role: sfUserModel.self_reported_role,
self_reported_school: sfUserModel.self_reported_school,
is_not_gdpr_location: sfUserModel.is_not_gdpr_location,
Expand Down

0 comments on commit 7865748

Please sign in to comment.