mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-23 22:00:38 -04:00
feat(donation): set donor cookie (#45808)
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
shouldRequestDonationSelector,
|
||||
preventProgressDonationRequests,
|
||||
recentlyClaimedBlockSelector,
|
||||
isDonatingSelector,
|
||||
addDonationComplete,
|
||||
addDonationError,
|
||||
postChargeStripeComplete,
|
||||
@@ -51,6 +52,7 @@ function* addDonationSaga({ payload }) {
|
||||
try {
|
||||
yield call(addDonation, payload);
|
||||
yield put(addDonationComplete());
|
||||
yield call(setDonationCookie);
|
||||
} catch (error) {
|
||||
const data =
|
||||
error.response && error.response.data
|
||||
@@ -66,6 +68,7 @@ function* postChargeStripeSaga({ payload }) {
|
||||
try {
|
||||
yield call(postChargeStripe, payload);
|
||||
yield put(postChargeStripeComplete());
|
||||
yield call(setDonationCookie);
|
||||
} catch (error) {
|
||||
const err =
|
||||
error.response && error.response.data
|
||||
@@ -112,17 +115,31 @@ function* postChargeStripeCardSaga({
|
||||
}
|
||||
yield call(addDonation, optimizedPayload);
|
||||
yield put(postChargeStripeCardComplete());
|
||||
yield call(setDonationCookie);
|
||||
} catch (error) {
|
||||
const errorMessage = error.message || defaultDonationErrorMessage;
|
||||
yield put(postChargeStripeCardError(errorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
function* setDonationCookie() {
|
||||
const isDonating = yield select(isDonatingSelector);
|
||||
const isDonorCookieSet = document.cookie
|
||||
.split(';')
|
||||
.some(item => item.trim().startsWith('isDonor=true'));
|
||||
if (isDonating) {
|
||||
if (!isDonorCookieSet) {
|
||||
document.cookie = 'isDonor=true';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createDonationSaga(types) {
|
||||
return [
|
||||
takeEvery(types.tryToShowDonationModal, showDonateModalSaga),
|
||||
takeEvery(types.addDonation, addDonationSaga),
|
||||
takeLeading(types.postChargeStripe, postChargeStripeSaga),
|
||||
takeLeading(types.postChargeStripeCard, postChargeStripeCardSaga)
|
||||
takeLeading(types.postChargeStripeCard, postChargeStripeCardSaga),
|
||||
takeEvery(types.fetchUserComplete, setDonationCookie)
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user