Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { select, put, take } from 'redux-saga/effects';
- function* emptySaga() {}
- export function* withConfirmation(text, onConfirm, onCancel = emptySaga) {
- yield put({ type: 'ShowConfirmationDialog', payload: text });
- const { type } = yield take([
- 'ConfirmationDialogConfirmed',
- 'ConfirmationDialogCanceled'
- ]);
- switch (type) {
- case 'ConfirmationDialogConfirmed':
- yield* onConfirm();
- break;
- case 'ConfirmationDialogCanceled':
- yield* onCancel();
- break;
- default:
- throw `${type} - Missing impl`;
- }
- yield put({ type: 'HideConfirmationDialog' });
- }
- export function* requestDelete({ payload }) {
- const {
- id,
- firstName,
- lastName
- } = yield select(appState => appState.list.users.find(({ id }) => id === payload));
- yield* withConfirmation(`Are you sure that you want to delete ${firstName} ${lastName}?`, function*() {
- yield put({
- type: 'DeleteUser',
- payload: id
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement