Created
February 20, 2019 09:15
-
-
Save charisschomba/635de8340b62cc43c78db9984d095a2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { takeLatest, put, call } from 'redux-saga/effects'; | |
import { REGISTERING_USER, EDITING_USER } from '../../../constants/users'; | |
import { | |
registerUserSuccess, | |
registrationStarted, | |
registerUserFailure, | |
} from '.'; | |
import { api } from '../../../utils/api'; | |
export function* registerUser({ payload }) { | |
try { | |
yield put(registrationStarted()); | |
const user = yield call(api.users.create, payload); | |
const { data } = user; | |
yield put(registerUserSuccess(data)); | |
} catch (error) { | |
yield put( | |
registerUserFailure( | |
error.response | |
? error.response.data | |
: { | |
message: 'Something went wrong.', | |
}, | |
), | |
); | |
} | |
} | |
export function* watchRegistration() { | |
yield takeLatest(REGISTERING_USER, registerUser); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment