Skip to content

Commit

Permalink
OCLOMRS-55: Fix the loader right before the dictionaries are retrieved
Browse files Browse the repository at this point in the history
OCLOMRS-55: Fix the loader right before the dictionaries are retrieved
  • Loading branch information
EleisonC committed Jun 24, 2018
1 parent 00f6ff5 commit 4dda255
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
34 changes: 15 additions & 19 deletions src/redux/actions/dictionaries/dictionaryActionCreators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { notify } from 'react-notify-toast';
import { addDictionary, fetchOrganizations, isSuccess, isFetching } from './dictionaryActions';
import { addDictionary, fetchOrganizations, isSuccess, isFetching, isErrored } from './dictionaryActions';
import api from './../../api';

export const createDictionary = data => dispatch =>
Expand Down Expand Up @@ -28,21 +28,17 @@ export const fetchingOrganizations = () => dispatch =>
.then(payload =>
dispatch(fetchOrganizations(payload)));

export const fetchDictionaries = () => dispatch =>
api.dictionaries
.fetchingDictionaries()
.then(dispatch(isFetching(true)))
.then(payload =>
dispatch(isSuccess(payload)),
dispatch(isFetching(false))
)
.catch((error) => () => {
if (error.payload){
dispatch(isSuccess(error.payload));
dispatch(isFetching(false));
} else {
dispatch(isErrored(error.payload.data));
dispatch(isFetching(false));
}
}
);
export const fetchDictionaries = () => dispatch =>{
dispatch(isFetching(true));
return api.dictionaries
.fetchingDictionaries()
.then(payload => {
dispatch(isSuccess(payload));
dispatch(isFetching(false));
})
.catch(error => {
let verror = "Can not make this request";
dispatch(isErrored(error.response.data));
dispatch(isFetching(false));
});
}
2 changes: 1 addition & 1 deletion src/redux/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
fetchingDictionaries: () =>
instance
.get(`collections/?q=${''}&limit=${1000}&page=${1}&verbose=true`)
.then(payload => payload.data)
.then(payload => payload.data)
},
organizations: {
fetchOrganizations: () =>
Expand Down
3 changes: 2 additions & 1 deletion src/tests/Dashboard/action/dictionaryAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('Test suite for dictionary actions', () => {

const expectedActions = [
{ type: IS_FETCHING, payload: true },
{ type: IS_FETCHING, payload: false },
{ type: FETCHING_DICTIONARIES, payload: [dictionaries] },
{ type: IS_FETCHING, payload: false },
];

const store = mockStore({ payload: {} });
Expand All @@ -73,6 +73,7 @@ describe('Test suite for dictionary actions', () => {

const expectedActions = [
{ type: IS_FETCHING, payload: true },
{ type: FETCHING_DICTIONARIES, payload: 'could not complete this request' },
{ type: IS_FETCHING, payload: false },
];

Expand Down

0 comments on commit 4dda255

Please sign in to comment.