2020-06-03 12:44:03 +03:00
|
|
|
import { Map, fromJS } from 'immutable';
|
|
|
|
import { AnyAction } from 'redux';
|
|
|
|
import { STATUS_REQUEST, STATUS_SUCCESS, STATUS_FAILURE } from '../actions/status';
|
|
|
|
import { Status } from '../types/redux';
|
|
|
|
|
2020-06-15 10:59:28 -04:00
|
|
|
interface StatusAction extends AnyAction {
|
|
|
|
payload: {
|
|
|
|
status: { auth: { status: boolean }; api: { status: boolean; statusPage: string } };
|
|
|
|
error?: Error;
|
|
|
|
};
|
2020-06-03 12:44:03 +03:00
|
|
|
}
|
|
|
|
|
2020-06-15 10:59:28 -04:00
|
|
|
const status = (state = Map(), action: StatusAction) => {
|
2020-06-03 12:44:03 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case STATUS_REQUEST:
|
|
|
|
return state.set('isFetching', true);
|
|
|
|
case STATUS_SUCCESS:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('isFetching', false);
|
|
|
|
map.set('status', fromJS(action.payload.status));
|
|
|
|
});
|
|
|
|
case STATUS_FAILURE:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.set('isFetching', false);
|
|
|
|
map.set('error', action.payload.error);
|
|
|
|
});
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const selectStatus = (status: Status) => {
|
|
|
|
return status.get('status')?.toJS() || {};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default status;
|