mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
import {
|
|
PostStatusesRequestActionTypes,
|
|
POST_STATUSES_REQUEST_START,
|
|
POST_STATUSES_REQUEST_SUCCESS,
|
|
POST_STATUSES_REQUEST_FAILURE,
|
|
} from '../actions/requestPostStatuses';
|
|
|
|
import IPostStatus from '../interfaces/IPostStatus';
|
|
|
|
export interface PostStatusesState {
|
|
items: Array<IPostStatus>;
|
|
areLoading: boolean;
|
|
error: string;
|
|
}
|
|
|
|
const initialState: PostStatusesState = {
|
|
items: [],
|
|
areLoading: false,
|
|
error: '',
|
|
}
|
|
|
|
const postStatusesReducer = (
|
|
state = initialState,
|
|
action: PostStatusesRequestActionTypes,
|
|
) => {
|
|
switch (action.type) {
|
|
case POST_STATUSES_REQUEST_START:
|
|
return {
|
|
...state,
|
|
areLoading: true,
|
|
};
|
|
|
|
case POST_STATUSES_REQUEST_SUCCESS:
|
|
return {
|
|
...state,
|
|
items: action.postStatuses.map(postStatus => ({
|
|
id: postStatus.id,
|
|
name: postStatus.name,
|
|
color: postStatus.color,
|
|
})),
|
|
areLoading: false,
|
|
error: '',
|
|
};
|
|
|
|
case POST_STATUSES_REQUEST_FAILURE:
|
|
return {
|
|
...state,
|
|
areLoading: false,
|
|
error: action.error,
|
|
};
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default postStatusesReducer; |