Files
SCM-Manager/scm-ui/src/users/modules/users.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-07-04 09:55:02 +02:00
const FETCH_USERS = 'scm/users/FETCH';
const FETCH_USERS_SUCCESS= 'scm/users/FETCH_SUCCESS';
const FETCH_USERS_FAILURE = 'scm/users/FETCH_FAILURE';
2018-07-02 16:05:58 +02:00
2018-07-04 09:55:02 +02:00
function requestUsers() {
2018-07-02 16:05:58 +02:00
return {
2018-07-04 09:55:02 +02:00
type: FETCH_USERS
2018-07-02 16:05:58 +02:00
};
}
2018-07-04 09:55:02 +02:00
function fetchUsers() {
2018-07-02 16:05:58 +02:00
return function(dispatch) {
2018-07-04 09:55:02 +02:00
dispatch(requestUsers());
2018-07-02 16:05:58 +02:00
return null;
}
}
2018-07-04 09:55:02 +02:00
export function shouldFetchUsers(state: any): boolean {
const users = state.users;
2018-07-02 16:05:58 +02:00
return null;
}
2018-07-04 09:55:02 +02:00
export function fetchUsersIfNeeded() {
2018-07-02 16:05:58 +02:00
return (dispatch, getState) => {
2018-07-04 09:55:02 +02:00
if (shouldFetchUsers(getState())) {
dispatch(fetchUsers());
2018-07-02 16:05:58 +02:00
}
}
}
export default function reducer(state = {}, action = {}) {
switch (action.type) {
2018-07-04 09:55:02 +02:00
case FETCH_USERS:
2018-07-02 16:05:58 +02:00
return {
...state,
2018-07-02 16:22:24 +02:00
login: true,
2018-07-02 16:05:58 +02:00
error: null
};
2018-07-04 09:55:02 +02:00
case FETCH_USERS_SUCCESS:
2018-07-02 16:05:58 +02:00
return {
...state,
2018-07-02 16:22:24 +02:00
login: false,
2018-07-02 16:05:58 +02:00
timestamp: action.timestamp,
error: null,
2018-07-04 09:55:02 +02:00
users: action.payload
2018-07-02 16:05:58 +02:00
};
2018-07-04 09:55:02 +02:00
case FETCH_USERS_FAILURE:
2018-07-02 16:05:58 +02:00
return {
...state,
2018-07-02 16:22:24 +02:00
login: false,
2018-07-02 16:05:58 +02:00
error: action.payload
};
default:
return state
}
}