39 lines
932 B
TypeScript
Raw Normal View History

import { produce } from 'immer';
import type { StatusAction } from '../actions/status';
import { STATUS_REQUEST, STATUS_SUCCESS, STATUS_FAILURE } from '../actions/status';
2020-06-03 12:44:03 +03:00
export type Status = {
isFetching: boolean;
status: {
auth: { status: boolean };
api: { status: boolean; statusPage: string };
};
error: Error | undefined;
};
2020-06-03 12:44:03 +03:00
const defaultState: Status = {
isFetching: false,
status: {
auth: { status: true },
api: { status: true, statusPage: '' },
},
error: undefined,
};
const status = produce((state: Status, action: StatusAction) => {
2020-06-03 12:44:03 +03:00
switch (action.type) {
case STATUS_REQUEST:
state.isFetching = true;
break;
2020-06-03 12:44:03 +03:00
case STATUS_SUCCESS:
state.isFetching = false;
state.status = action.payload.status;
break;
2020-06-03 12:44:03 +03:00
case STATUS_FAILURE:
state.isFetching = false;
state.error = action.payload.error;
2020-06-03 12:44:03 +03:00
}
}, defaultState);
2020-06-03 12:44:03 +03:00
export default status;