feat: added danger-zone-saga.js
This commit is contained in:
committed by
mrugesh mohapatra
parent
e51b8bfaca
commit
05f8c2bd5c
@ -5,12 +5,11 @@ import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
|
||||
import { FullWidthRow, ButtonSpacer, Spacer } from '../helpers';
|
||||
import { deleteAccount, resetProgress } from '../../redux/settings';
|
||||
import DeleteModal from './DeleteModal';
|
||||
|
||||
import {deleteAccount, resetProgress } from '../../redux/settings';
|
||||
import ResetModal from './ResetModal';
|
||||
|
||||
import './danger-zone.css';
|
||||
import ResetModal from './ResetModal';
|
||||
|
||||
const propTypes = {
|
||||
deleteAccount: PropTypes.func.isRequired,
|
||||
@ -48,6 +47,7 @@ class DangerZone extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { deleteAccount, resetProgress } = this.props;
|
||||
return (
|
||||
<div className='danger-zone'>
|
||||
<FullWidthRow>
|
||||
@ -79,9 +79,11 @@ class DangerZone extends Component {
|
||||
</FullWidthRow>
|
||||
</Panel>
|
||||
<ResetModal
|
||||
reset={resetProgress}
|
||||
onHide={() => this.toggleResetModal()}
|
||||
show={this.state.reset} />
|
||||
<DeleteModal
|
||||
delete={deleteAccount}
|
||||
onHide={() => this.toggleDeleteModal()}
|
||||
show={this.state.delete} />
|
||||
</FullWidthRow>
|
||||
|
@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
||||
import { ButtonSpacer } from '../helpers';
|
||||
import { Button, Modal } from '@freecodecamp/react-bootstrap'
|
||||
|
||||
import './DangerZone'
|
||||
import './danger-zone.css';
|
||||
|
||||
const propTypes = {
|
||||
delete: PropTypes.func.isRequired,
|
||||
|
41
client/src/redux/settings/danger-zone-saga.js
Normal file
41
client/src/redux/settings/danger-zone-saga.js
Normal file
@ -0,0 +1,41 @@
|
||||
import { call, put, takeEvery } from 'redux-saga/effects';
|
||||
|
||||
import {
|
||||
deleteAccountComplete,
|
||||
deleteAccountError,
|
||||
resetProgressComplete,
|
||||
resetProgressError
|
||||
} from './';
|
||||
|
||||
import {
|
||||
postResetProgress,
|
||||
postDeleteAccount
|
||||
} from '../../utils/ajax';
|
||||
import { createFlashMessage } from '../../components/Flash/redux';
|
||||
|
||||
function* deleteAccountSaga({ payload }) {
|
||||
try {
|
||||
const { data: response } = yield call(postDeleteAccount, payload);
|
||||
yield put(deleteAccountComplete(response));
|
||||
yield put(createFlashMessage(response));
|
||||
} catch (e) {
|
||||
yield put(deleteAccountError(e));
|
||||
}
|
||||
}
|
||||
|
||||
function* resetProgressSaga({ payload }) {
|
||||
try {
|
||||
const { data: response } = yield call(postResetProgress, payload);
|
||||
yield put(resetProgressComplete(response));
|
||||
yield put(createFlashMessage(response));
|
||||
} catch (e) {
|
||||
yield put(resetProgressError(e));
|
||||
}
|
||||
}
|
||||
|
||||
export function createDangerZoneSaga(types) {
|
||||
return [
|
||||
takeEvery(types.deleteAccount, deleteAccountSaga),
|
||||
takeEvery(types.resetProgress, resetProgressSaga)
|
||||
];
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { createAction, handleActions } from 'redux-actions';
|
||||
|
||||
import { createTypes, createAsyncTypes } from '../../utils/createTypes';
|
||||
import { createDangerZoneSaga } from './danger-zone-saga';
|
||||
import { createSettingsSagas } from './settings-sagas';
|
||||
import { createUpdateMyEmailSaga } from './update-email-saga';
|
||||
|
||||
@ -37,7 +38,8 @@ export const types = createTypes(
|
||||
|
||||
export const sagas = [
|
||||
...createSettingsSagas(types),
|
||||
...createUpdateMyEmailSaga(types)
|
||||
...createUpdateMyEmailSaga(types),
|
||||
...createDangerZoneSaga(types)
|
||||
];
|
||||
|
||||
const checkForSuccessPayload = ({ type, payload }) =>
|
||||
|
@ -50,6 +50,14 @@ export function postReportUser(body) {
|
||||
return post('/user/report-user', body);
|
||||
}
|
||||
|
||||
export function postDeleteAccount(body) {
|
||||
return post('/account/delete', body);
|
||||
}
|
||||
|
||||
export function postResetProgress(body) {
|
||||
return post('/account/reset-progress', body);
|
||||
}
|
||||
|
||||
/** PUT **/
|
||||
|
||||
export function putUpdateMyAbout(values) {
|
||||
|
Reference in New Issue
Block a user