fix(donate): modal opens at most once per session (#36632)
* Track if donation modal has opened in a session * Fix prettier problem * Create separate action that switches donationRequested
This commit is contained in:
@ -28,6 +28,7 @@ export const defaultFetchState = {
|
|||||||
const initialState = {
|
const initialState = {
|
||||||
appUsername: '',
|
appUsername: '',
|
||||||
completionCount: 0,
|
completionCount: 0,
|
||||||
|
donationRequested: false,
|
||||||
showCert: {},
|
showCert: {},
|
||||||
showCertFetchState: {
|
showCertFetchState: {
|
||||||
...defaultFetchState
|
...defaultFetchState
|
||||||
@ -48,6 +49,7 @@ export const types = createTypes(
|
|||||||
[
|
[
|
||||||
'appMount',
|
'appMount',
|
||||||
'closeDonationModal',
|
'closeDonationModal',
|
||||||
|
'donationRequested',
|
||||||
'hardGoTo',
|
'hardGoTo',
|
||||||
'openDonationModal',
|
'openDonationModal',
|
||||||
'onlineStatusChange',
|
'onlineStatusChange',
|
||||||
@ -79,6 +81,7 @@ export const appMount = createAction(types.appMount);
|
|||||||
|
|
||||||
export const closeDonationModal = createAction(types.closeDonationModal);
|
export const closeDonationModal = createAction(types.closeDonationModal);
|
||||||
export const openDonationModal = createAction(types.openDonationModal);
|
export const openDonationModal = createAction(types.openDonationModal);
|
||||||
|
export const donationRequested = createAction(types.donationRequested);
|
||||||
|
|
||||||
export const onlineStatusChange = createAction(types.onlineStatusChange);
|
export const onlineStatusChange = createAction(types.onlineStatusChange);
|
||||||
|
|
||||||
@ -122,6 +125,7 @@ export const completedChallengesSelector = state =>
|
|||||||
export const completionCountSelector = state => state[ns].completionCount;
|
export const completionCountSelector = state => state[ns].completionCount;
|
||||||
export const currentChallengeIdSelector = state =>
|
export const currentChallengeIdSelector = state =>
|
||||||
userSelector(state).currentChallengeId || '';
|
userSelector(state).currentChallengeId || '';
|
||||||
|
export const donationRequestedSelector = state => state[ns].donationRequested;
|
||||||
|
|
||||||
export const isOnlineSelector = state => state[ns].isOnline;
|
export const isOnlineSelector = state => state[ns].isOnline;
|
||||||
export const isSignedInSelector = state => !!state[ns].appUsername;
|
export const isSignedInSelector = state => !!state[ns].appUsername;
|
||||||
@ -136,16 +140,17 @@ export const showDonationSelector = state => {
|
|||||||
const completedChallenges = completedChallengesSelector(state);
|
const completedChallenges = completedChallengesSelector(state);
|
||||||
const completionCount = completionCountSelector(state);
|
const completionCount = completionCountSelector(state);
|
||||||
const currentCompletedLength = completedChallenges.length;
|
const currentCompletedLength = completedChallenges.length;
|
||||||
|
const donationRequested = donationRequestedSelector(state);
|
||||||
// the user has not completed 9 challenges in total yet
|
// the user has not completed 9 challenges in total yet
|
||||||
if (currentCompletedLength < 9) {
|
if (currentCompletedLength < 9) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// this will mean we are on the 10th submission in total for the user
|
// this will mean we are on the 10th submission in total for the user
|
||||||
if (completedChallenges.length === 9) {
|
if (completedChallenges.length === 9 && donationRequested === false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// this will mean we are on the 3rd submission for this browser session
|
// this will mean we are on the 3rd submission for this browser session
|
||||||
if (completionCount === 2) {
|
if (completionCount === 2 && donationRequested === false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -262,6 +267,10 @@ export const reducer = handleActions(
|
|||||||
...state,
|
...state,
|
||||||
showDonationModal: true
|
showDonationModal: true
|
||||||
}),
|
}),
|
||||||
|
[types.donationRequested]: state => ({
|
||||||
|
...state,
|
||||||
|
donationRequested: true
|
||||||
|
}),
|
||||||
[types.resetUserData]: state => ({
|
[types.resetUserData]: state => ({
|
||||||
...state,
|
...state,
|
||||||
appUsername: '',
|
appUsername: '',
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
currentChallengeIdSelector,
|
currentChallengeIdSelector,
|
||||||
openDonationModal,
|
openDonationModal,
|
||||||
showDonationSelector,
|
showDonationSelector,
|
||||||
|
donationRequested,
|
||||||
updateComplete,
|
updateComplete,
|
||||||
updateFailed,
|
updateFailed,
|
||||||
userSelector
|
userSelector
|
||||||
@ -43,6 +44,7 @@ function* showDonateModalSaga() {
|
|||||||
let shouldShowDonate = yield select(showDonationSelector);
|
let shouldShowDonate = yield select(showDonationSelector);
|
||||||
if (!isDonating && shouldShowDonate) {
|
if (!isDonating && shouldShowDonate) {
|
||||||
yield put(openDonationModal());
|
yield put(openDonationModal());
|
||||||
|
yield put(donationRequested());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user