Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import { select, put, take } from 'redux-saga/effects';
  2.  
  3. function* emptySaga() {}
  4.  
  5. export function* withConfirmation(text, onConfirm, onCancel = emptySaga) {
  6. yield put({ type: 'ShowConfirmationDialog', payload: text });
  7.  
  8. const { type } = yield take([
  9. 'ConfirmationDialogConfirmed',
  10. 'ConfirmationDialogCanceled'
  11. ]);
  12.  
  13. switch (type) {
  14. case 'ConfirmationDialogConfirmed':
  15. yield* onConfirm();
  16. break;
  17.  
  18. case 'ConfirmationDialogCanceled':
  19. yield* onCancel();
  20. break;
  21.  
  22. default:
  23. throw `${type} - Missing impl`;
  24. }
  25.  
  26. yield put({ type: 'HideConfirmationDialog' });
  27. }
  28.  
  29. export function* requestDelete({ payload }) {
  30. const {
  31. id,
  32. firstName,
  33. lastName
  34. } = yield select(appState => appState.list.users.find(({ id }) => id === payload));
  35.  
  36. yield* withConfirmation(`Are you sure that you want to delete ${firstName} ${lastName}?`, function*() {
  37. yield put({
  38. type: 'DeleteUser',
  39. payload: id
  40. });
  41. });
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement