Migration du client sur Typescript
This commit is contained in:
42
client/src/store/reducers/issues.ts
Normal file
42
client/src/store/reducers/issues.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { FETCH_ISSUES_SUCCESS, CREATE_ISSUE_SUCCESS } from "../actions/issues";
|
||||
|
||||
const defaultState = {
|
||||
byProject: {}
|
||||
};
|
||||
|
||||
export function issuesReducer(state = defaultState, action: any) {
|
||||
switch(action.type) {
|
||||
case FETCH_ISSUES_SUCCESS:
|
||||
return handleFetchIssuesSuccess(state, action);
|
||||
case CREATE_ISSUE_SUCCESS:
|
||||
return handleCreateIssueSuccess(state, action);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function handleFetchIssuesSuccess(state: any, action: any) {
|
||||
return {
|
||||
...state,
|
||||
byProject: {
|
||||
...state.byProject,
|
||||
[action.project]: [
|
||||
...action.issues,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleCreateIssueSuccess(state: any, action: any) {
|
||||
return {
|
||||
...state,
|
||||
byProject: {
|
||||
...state.byProject,
|
||||
[action.project]: [
|
||||
...state.byProject[action.project],
|
||||
action.issue
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user