Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pgangwani/a36a6c33990f8547cc0ea759549a8cde to your computer and use it in GitHub Desktop.

Select an option

Save pgangwani/a36a6c33990f8547cc0ea759549a8cde to your computer and use it in GitHub Desktop.

Revisions

  1. @tomkis tomkis revised this gist Aug 26, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions redux-saga-confirmation-dialog.js
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,8 @@ export function* withConfirmation(text, onConfirm, onCancel = emptySaga) {
    default:
    throw `${type} - Missing impl`;
    }

    yield put({ type: 'HideConfirmationDialog' });
    }

    export function* requestDelete({ payload }) {
  2. @tomkis tomkis created this gist Aug 26, 2016.
    40 changes: 40 additions & 0 deletions redux-saga-confirmation-dialog.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    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`;
    }
    }

    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
    });
    });
    }