diff --git a/client/src/templates/Challenges/redux/completion-epic.js b/client/src/templates/Challenges/redux/completion-epic.js index 3a14266643d..0c9ee9dada7 100644 --- a/client/src/templates/Challenges/redux/completion-epic.js +++ b/client/src/templates/Challenges/redux/completion-epic.js @@ -23,8 +23,6 @@ import { import { userSelector, isSignedInSelector, - openDonationModal, - showDonationSelector, submitComplete, updateComplete, updateFailed @@ -126,19 +124,13 @@ const submitters = { 'project.backEnd': submitProject }; -function shouldShowDonate(state) { - return showDonationSelector(state) ? of(openDonationModal()) : empty(); -} - export default function completionEpic(action$, state$) { return action$.pipe( ofType(types.submitChallenge), switchMap(({ type }) => { const state = state$.value; const meta = challengeMetaSelector(state); - const { isDonating } = userSelector(state); const { nextChallengePath, introPath, challengeType } = meta; - const showDonate = isDonating ? empty() : shouldShowDonate(state); const closeChallengeModal = of(closeModal('completion')); let submitter = () => of({ type: 'no-user-signed-in' }); if ( @@ -157,7 +149,6 @@ export default function completionEpic(action$, state$) { return submitter(type, state).pipe( tap(() => navigate(introPath ? introPath : nextChallengePath)), concat(closeChallengeModal), - concat(showDonate), filter(Boolean) ); }) diff --git a/client/src/templates/Challenges/redux/current-challenge-saga.js b/client/src/templates/Challenges/redux/current-challenge-saga.js index f048d228620..702b656e845 100644 --- a/client/src/templates/Challenges/redux/current-challenge-saga.js +++ b/client/src/templates/Challenges/redux/current-challenge-saga.js @@ -3,8 +3,11 @@ import { put, select, call, takeEvery } from 'redux-saga/effects'; import { isSignedInSelector, currentChallengeIdSelector, + openDonationModal, + showDonationSelector, updateComplete, - updateFailed + updateFailed, + userSelector } from '../../../redux'; import { post } from '../../../utils/ajax'; @@ -35,9 +38,18 @@ function* updateSuccessMessageSaga() { yield put(updateSuccessMessage(randomCompliment())); } +function* showDonateModalSaga() { + let { isDonating } = yield select(userSelector); + let shouldShowDonate = yield select(showDonationSelector); + if (!isDonating && shouldShowDonate) { + yield put(openDonationModal()); + } +} + export function createCurrentChallengeSaga(types) { return [ takeEvery(types.challengeMounted, currentChallengeSaga), - takeEvery(types.challengeMounted, updateSuccessMessageSaga) + takeEvery(types.challengeMounted, updateSuccessMessageSaga), + takeEvery(types.challengeMounted, showDonateModalSaga) ]; }