mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
const FETCH_USERS = 'scm/users/FETCH';
|
|
const FETCH_USERS_SUCCESS= 'scm/users/FETCH_SUCCESS';
|
|
const FETCH_USERS_FAILURE = 'scm/users/FETCH_FAILURE';
|
|
|
|
function requestUsers() {
|
|
return {
|
|
type: FETCH_USERS
|
|
};
|
|
}
|
|
|
|
|
|
function fetchUsers() {
|
|
return function(dispatch) {
|
|
dispatch(requestUsers());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function shouldFetchUsers(state: any): boolean {
|
|
const users = state.users;
|
|
return null;
|
|
}
|
|
|
|
export function fetchUsersIfNeeded() {
|
|
return (dispatch, getState) => {
|
|
if (shouldFetchUsers(getState())) {
|
|
dispatch(fetchUsers());
|
|
}
|
|
}
|
|
}
|
|
|
|
export default function reducer(state = {}, action = {}) {
|
|
switch (action.type) {
|
|
case FETCH_USERS:
|
|
return {
|
|
...state,
|
|
login: true,
|
|
error: null
|
|
};
|
|
case FETCH_USERS_SUCCESS:
|
|
return {
|
|
...state,
|
|
login: false,
|
|
timestamp: action.timestamp,
|
|
error: null,
|
|
users: action.payload
|
|
};
|
|
case FETCH_USERS_FAILURE:
|
|
return {
|
|
...state,
|
|
login: false,
|
|
error: action.payload
|
|
};
|
|
|
|
default:
|
|
return state
|
|
}
|
|
}
|