diff --git a/client/src/redux/index.js b/client/src/redux/index.js index 7ba654068e..1e5f316120 100644 --- a/client/src/redux/index.js +++ b/client/src/redux/index.js @@ -51,6 +51,7 @@ export const types = createTypes( 'hardGoTo', 'openDonationModal', 'onlineStatusChange', + 'resetUserData', 'submitComplete', 'updateComplete', 'updateFailed', @@ -110,6 +111,8 @@ export const reportUser = createAction(types.reportUser); export const reportUserComplete = createAction(types.reportUserComplete); export const reportUserError = createAction(types.reportUserError); +export const resetUserData = createAction(types.resetUserData); + export const showCert = createAction(types.showCert); export const showCertComplete = createAction(types.showCertComplete); export const showCertError = createAction(types.showCertError); @@ -259,6 +262,11 @@ export const reducer = handleActions( ...state, showDonationModal: true }), + [types.resetUserData]: state => ({ + ...state, + appUsername: '', + user: {} + }), [types.showCert]: state => ({ ...state, showCert: {}, diff --git a/client/src/redux/settings/danger-zone-saga.js b/client/src/redux/settings/danger-zone-saga.js index 56c41ea8fd..52a0f941dc 100644 --- a/client/src/redux/settings/danger-zone-saga.js +++ b/client/src/redux/settings/danger-zone-saga.js @@ -1,3 +1,4 @@ +import { navigate } from 'gatsby'; import { call, put, takeEvery } from 'redux-saga/effects'; import { @@ -6,27 +7,30 @@ import { resetProgressComplete, resetProgressError } from './'; - -import { - postResetProgress, - postDeleteAccount -} from '../../utils/ajax'; +import { resetUserData, fetchUser } from '../'; +import { postResetProgress, postDeleteAccount } from '../../utils/ajax'; import { createFlashMessage } from '../../components/Flash/redux'; -function* deleteAccountSaga({ payload }) { +function* deleteAccountSaga() { try { - const { data: response } = yield call(postDeleteAccount, payload); + const { data: response } = yield call(postDeleteAccount); yield put(deleteAccountComplete(response)); + // remove current user information from application state + yield put(resetUserData()); + yield call(navigate, '/'); yield put(createFlashMessage(response)); } catch (e) { yield put(deleteAccountError(e)); } } -function* resetProgressSaga({ payload }) { +function* resetProgressSaga() { try { - const { data: response } = yield call(postResetProgress, payload); + const { data: response } = yield call(postResetProgress); yield put(resetProgressComplete(response)); + // refresh current user data in application state + yield put(fetchUser()); + yield call(navigate, '/welcome'); yield put(createFlashMessage(response)); } catch (e) { yield put(resetProgressError(e));