41 lines
946 B
TypeScript
Raw Normal View History

import { produce } from 'immer';
import { STATUS_REQUEST, STATUS_SUCCESS, STATUS_FAILURE } from '../constants';
2020-06-03 12:44:03 +03:00
import type { StatusAction } from '../actions/status';
2022-10-20 11:57:30 -04:00
export interface StatusState {
isFetching: boolean;
status: {
auth: { status: boolean };
api: { status: boolean; statusPage: string };
};
error: Error | undefined;
2022-10-20 11:57:30 -04:00
}
2020-06-03 12:44:03 +03:00
2022-10-20 11:57:30 -04:00
const defaultState: StatusState = {
isFetching: false,
status: {
auth: { status: true },
api: { status: true, statusPage: '' },
},
error: undefined,
};
2022-10-20 11:57:30 -04:00
const status = produce((state: StatusState, 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;