Created
November 6, 2018 03:56
-
-
Save hewrin/254b2812743c88edab4df6c9403d74c0 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 { call, put, select } from 'redux-saga/effects'; | |
| import Config from 'react-native-config'; | |
| import { SHOW_SUCCESS_SCREEN, SHOW_ERROR_SCREEN } from '../../actions/statusScreen'; | |
| const bulkParcelUpdate = params => fetch(`${Config.SERVER_URL}/api/v2/agents/parcels`, { | |
| method: 'PATCH', | |
| headers: { | |
| Accept: 'application/json', | |
| 'Content-Type': 'application/json', | |
| Authorization: `Bearer ${params.authToken}`, | |
| }, | |
| body: JSON.stringify({ | |
| agentId: params.agentId, | |
| parcelReturns: params.parcelReturns, | |
| parcelCollections: params.parcelCollections, | |
| agentCode: params.agentCode, | |
| }), | |
| }); | |
| function* fetchBulkParcelUpdate() { | |
| let response; | |
| const authToken = yield select(state => state.session.authToken); | |
| const agentId = yield select(state => state.scanner.agent.id); | |
| const parcelReturns = yield select(state => state.returns.selectedReturns); | |
| const parcelCollections = yield select(state => state.collections.selectedCollections); | |
| const agentCode = yield select(state => state.bulkParcelUpdate.agentCode); | |
| try { | |
| response = yield call(bulkParcelUpdate, { | |
| authToken, agentId, parcelReturns, parcelCollections, agentCode, | |
| }); | |
| if (response.status === 200) { | |
| yield put({ type: SHOW_SUCCESS_SCREEN }); | |
| } else { | |
| yield put({ type: SHOW_ERROR_SCREEN }); | |
| } | |
| } catch (error) { | |
| alert(`catch fetchBulkParcelUpdate error ${error}`); | |
| } | |
| } | |
| export default fetchBulkParcelUpdate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment