import { SagaIterator , delay } from 'redux-saga' ; import { Action } from 'typescript-fsa' ; import { takeEvery , put , take , race , select , call } from 'redux-saga/effects' ; import { MODAL_ANIMATION_TIME } from '../../constants' ; import * as account from 'modules/account' ; import * as application from 'modules/application' ; import * as auth from 'modules/auth' ; export function * removeAccountWorker ( action ) { yield put ( application . actions . receiveAlert ( { title : "alert.title.warning" , type : 'warning' , message : "account.want.to.remove" , } ) ) ; const result = yield race ( { confirm : take ( application . actions . confirmAlert ) , cancel : take ( application . actions . cancelAlert ) } ) ; if ( result . confirm ) { const currentAccount = yield select ( auth . selectors . getCurrentAccount ) ; if ( action . payload . uniqKey === currentAccount ) { yield put ( application . actions . toggleDrawer ( false ) ) ; yield call ( delay , MODAL_ANIMATION_TIME ) ; yield put ( auth . actions . logout ( ) ) ; } yield put ( account . actions . removeAccount . done ( { params : action . payload , result : null } ) ) ; } if ( result . cancel ) { yield put ( account . actions . removeAccount . failed ( { params : action . payload , error : 'User has reject the action!' } , { ignore : true } ) ) ; } } export default function * AccountSaga ( ) { yield takeEvery ( account . actions . removeAccount . started , removeAccountWorker ) ; }