Skip to content

Commit

Permalink
add update data to redux state when start update todo
Browse files Browse the repository at this point in the history
  • Loading branch information
charleyw committed Apr 20, 2017
1 parent 43c9d03 commit a2b132d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {crudCreate, crudGetList, crudUpdate} from './dataActions'

export const addTodo = (projectId, name) => (crudCreate('todos', {name}, `projects/${projectId}/todos`, {projectId: projectId}));
export const fetchTodos = (projectId) => (crudGetList('todos', null, null, null, `projects/${projectId}/todos`, {projectId}));
export const updateTodo = (id, data) => (crudUpdate('todos', id, data));
export const updateTodo = (id, data) => (crudUpdate('todos', id, {...data, id}));

export const addProject = (name) => (crudCreate('projects', {name}));
export const fetchProjects = () => (crudGetList('projects'));
2 changes: 1 addition & 1 deletion src/reducers/resource/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default (resource) => (previousState = initialState, {type, payload, meta
case CRUD_GET_LIST_SUCCESS:
return addRecords(payload.data, previousState);
case CRUD_UPDATE: // replace record in edit form with edited one to avoid displaying previous record version
return addRecords([payload.data], previousState);
return addRecords([{...previousState[payload.data.id], ...payload.data}], previousState);
case CRUD_GET_ONE_SUCCESS:
case CRUD_UPDATE_SUCCESS:
case CRUD_CREATE_SUCCESS:
Expand Down

0 comments on commit a2b132d

Please sign in to comment.