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 { bindActionCreators } from 'redux';
|
||||||
|
|
||||||
import { FullWidthRow, ButtonSpacer, Spacer } from '../helpers';
|
import { FullWidthRow, ButtonSpacer, Spacer } from '../helpers';
|
||||||
|
import { deleteAccount, resetProgress } from '../../redux/settings';
|
||||||
import DeleteModal from './DeleteModal';
|
import DeleteModal from './DeleteModal';
|
||||||
|
import ResetModal from './ResetModal';
|
||||||
import {deleteAccount, resetProgress } from '../../redux/settings';
|
|
||||||
|
|
||||||
import './danger-zone.css';
|
import './danger-zone.css';
|
||||||
import ResetModal from './ResetModal';
|
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
deleteAccount: PropTypes.func.isRequired,
|
deleteAccount: PropTypes.func.isRequired,
|
||||||
@ -48,6 +47,7 @@ class DangerZone extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { deleteAccount, resetProgress } = this.props;
|
||||||
return (
|
return (
|
||||||
<div className='danger-zone'>
|
<div className='danger-zone'>
|
||||||
<FullWidthRow>
|
<FullWidthRow>
|
||||||
@ -79,9 +79,11 @@ class DangerZone extends Component {
|
|||||||
</FullWidthRow>
|
</FullWidthRow>
|
||||||
</Panel>
|
</Panel>
|
||||||
<ResetModal
|
<ResetModal
|
||||||
|
reset={resetProgress}
|
||||||
onHide={() => this.toggleResetModal()}
|
onHide={() => this.toggleResetModal()}
|
||||||
show={this.state.reset} />
|
show={this.state.reset} />
|
||||||
<DeleteModal
|
<DeleteModal
|
||||||
|
delete={deleteAccount}
|
||||||
onHide={() => this.toggleDeleteModal()}
|
onHide={() => this.toggleDeleteModal()}
|
||||||
show={this.state.delete} />
|
show={this.state.delete} />
|
||||||
</FullWidthRow>
|
</FullWidthRow>
|
||||||
|
@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
|||||||
import { ButtonSpacer } from '../helpers';
|
import { ButtonSpacer } from '../helpers';
|
||||||
import { Button, Modal } from '@freecodecamp/react-bootstrap'
|
import { Button, Modal } from '@freecodecamp/react-bootstrap'
|
||||||
|
|
||||||
import './DangerZone'
|
import './danger-zone.css';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
delete: PropTypes.func.isRequired,
|
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 { createAction, handleActions } from 'redux-actions';
|
||||||
|
|
||||||
import { createTypes, createAsyncTypes } from '../../utils/createTypes';
|
import { createTypes, createAsyncTypes } from '../../utils/createTypes';
|
||||||
|
import { createDangerZoneSaga } from './danger-zone-saga';
|
||||||
import { createSettingsSagas } from './settings-sagas';
|
import { createSettingsSagas } from './settings-sagas';
|
||||||
import { createUpdateMyEmailSaga } from './update-email-saga';
|
import { createUpdateMyEmailSaga } from './update-email-saga';
|
||||||
|
|
||||||
@ -37,7 +38,8 @@ export const types = createTypes(
|
|||||||
|
|
||||||
export const sagas = [
|
export const sagas = [
|
||||||
...createSettingsSagas(types),
|
...createSettingsSagas(types),
|
||||||
...createUpdateMyEmailSaga(types)
|
...createUpdateMyEmailSaga(types),
|
||||||
|
...createDangerZoneSaga(types)
|
||||||
];
|
];
|
||||||
|
|
||||||
const checkForSuccessPayload = ({ type, payload }) =>
|
const checkForSuccessPayload = ({ type, payload }) =>
|
||||||
|
@ -50,6 +50,14 @@ export function postReportUser(body) {
|
|||||||
return post('/user/report-user', 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 **/
|
/** PUT **/
|
||||||
|
|
||||||
export function putUpdateMyAbout(values) {
|
export function putUpdateMyAbout(values) {
|
||||||
|
Reference in New Issue
Block a user