From 581d9734fc45904d372399d44de3e5000b710da9 Mon Sep 17 00:00:00 2001 From: Alex Windett Date: Wed, 25 Jan 2017 16:15:06 +0000 Subject: [PATCH] refactoring redux action and reducer for member update to use same dispatch function --- .../src/components/people-list/table/index.js | 10 +++--- .../people-list/table/person-role.js | 7 ++-- .../people-list/table/person-status.js | 6 ++-- frontend/src/containers/org/people.js | 10 +++--- frontend/src/state/actions.js | 3 +- frontend/src/state/reducers/orgs.js | 34 ++----------------- 6 files changed, 18 insertions(+), 52 deletions(-) diff --git a/frontend/src/components/people-list/table/index.js b/frontend/src/components/people-list/table/index.js index 44c6f692..88b4d970 100644 --- a/frontend/src/components/people-list/table/index.js +++ b/frontend/src/components/people-list/table/index.js @@ -10,9 +10,8 @@ const PeopleTable = (props) => { const { handleRoleTooltip, - handleRoleUpdate, handleStatusTooltip, - handleStatusUpdate, + handleMemberUpdate, people = [], orgUI = {}, orgIndex @@ -38,8 +37,8 @@ const PeopleTable = (props) => { const data = people.map( (person, index) => { const status = (person) => ( { const role = (person) => ( { }; PeopleTable.propTypes = { + handleMemberUpdate: React.PropTypes.func, handleRoleTooltip: React.PropTypes.func, - handleRoleUpdate: React.PropTypes.func, handleStatusTooltip: React.PropTypes.func, - handleStatusUpdate: React.PropTypes.func, orgIndex: React.PropTypes.number, orgUI: React.PropTypes.object, people: React.PropTypes.array, diff --git a/frontend/src/components/people-list/table/person-role.js b/frontend/src/components/people-list/table/person-role.js index 7d3913e7..902f7af5 100644 --- a/frontend/src/components/people-list/table/person-role.js +++ b/frontend/src/components/people-list/table/person-role.js @@ -54,13 +54,14 @@ const PersonRole = (props) => { person, personIndex, handleRoleTooltip, - handleRoleUpdate, + handleMemberUpdate, orgIndex } = props; const toggled = toggledID; const handleClick = () => handleRoleTooltip(person.uuid); - const handleOptionSelect = (updatedMember) => handleRoleUpdate(updatedMember); + const handleOptionSelect = (updatedMember) => + handleMemberUpdate(updatedMember); // Only send relevent info as props const _person = { @@ -90,8 +91,8 @@ const PersonRole = (props) => { }; PersonRole.propTypes = { + handleMemberUpdate: React.PropTypes.func, handleRoleTooltip: React.PropTypes.func, - handleRoleUpdate: React.PropTypes.func, membersRolesOptions: React.PropTypes.array, orgIndex: React.PropTypes.number, person: React.PropTypes.object, diff --git a/frontend/src/components/people-list/table/person-status.js b/frontend/src/components/people-list/table/person-status.js index d73a4b01..8c0f5164 100644 --- a/frontend/src/components/people-list/table/person-status.js +++ b/frontend/src/components/people-list/table/person-status.js @@ -54,14 +54,14 @@ const PersonStatus = (props) => { person, personIndex, handleStatusTooltip, - handleStatusUpdate, + handleMemberUpdate, orgIndex } = props; const toggled = toggledID; const handleClick = () => handleStatusTooltip(person.uuid); const handleOptionSelect = (updatedMember) => - handleStatusUpdate(updatedMember); + handleMemberUpdate(updatedMember); // Only send relevent info as props const _person = { @@ -91,8 +91,8 @@ const PersonStatus = (props) => { }; PersonStatus.propTypes = { + handleMemberUpdate: React.PropTypes.func, handleStatusTooltip: React.PropTypes.func, - handleStatusUpdate: React.PropTypes.func, membersStatusOptions: React.PropTypes.array, orgIndex: React.PropTypes.number, person: React.PropTypes.object, diff --git a/frontend/src/containers/org/people.js b/frontend/src/containers/org/people.js index 074470ec..38444c66 100644 --- a/frontend/src/containers/org/people.js +++ b/frontend/src/containers/org/people.js @@ -20,8 +20,7 @@ const { handleInviteToggle, handlePeopleRoleTooltip, handlePeopleStatusTooltip, - handleRoleUpdate, - handleStatusUpdate, + handleMemberUpdate } = actions; const People = (props) => { @@ -46,10 +45,9 @@ const mapDispatchToProps = (dispatch) => ({ handleToggle: () => dispatch(handleInviteToggle()), handleStatusTooltip: (id) => dispatch(handlePeopleStatusTooltip(id)), handleRoleTooltip: (id) => dispatch(handlePeopleRoleTooltip(id)), - handleRoleUpdate: (updatedMember) => - dispatch(handleRoleUpdate(updatedMember)), - handleStatusUpdate: (updatedMember) => - dispatch(handleStatusUpdate(updatedMember)), + handleMemberUpdate: (updatedMember) => + dispatch(handleMemberUpdate(updatedMember)), + }); module.exports = connect( diff --git a/frontend/src/state/actions.js b/frontend/src/state/actions.js index e67159e7..8edb6883 100644 --- a/frontend/src/state/actions.js +++ b/frontend/src/state/actions.js @@ -22,6 +22,5 @@ module.exports = { createAction(`${APP}/HANDLE_PERSON_STATUS_TOOLTIP`), handlePeopleRoleTooltip: createAction(`${APP}/HANDLE_PERSON_ROLE_TOOLTIP`), - handleMemberUpdate: createAction(`${APP}/HANDLE_PERSON_ROLE_UPDATE`), - handleStatusUpdate: createAction(`${APP}/HANDLE_PERSON_STATUS_UPDATE`), + handleMemberUpdate: createAction(`${APP}/HANDLE_MEMBER_UPDATE`), }; diff --git a/frontend/src/state/reducers/orgs.js b/frontend/src/state/reducers/orgs.js index f98e7fd3..e8cea8aa 100644 --- a/frontend/src/state/reducers/orgs.js +++ b/frontend/src/state/reducers/orgs.js @@ -10,8 +10,7 @@ const { handleInviteToggle, handlePeopleRoleTooltip, handlePeopleStatusTooltip, - handleRoleUpdate, - handleStatusUpdate, + handleMemberUpdate, } = actions; module.exports = handleActions({ @@ -48,36 +47,7 @@ module.exports = handleActions({ } }; }, - [handleRoleUpdate.toString()]: (state, action) => { - const { - orgIndex, - person, - personIndex, - } = action.payload; - - return { - ...state, - ui: { - ...state.ui, - member_role_tooltip: false - }, - data: [ - ...state.data.slice(0, orgIndex), - { - ...state.data[orgIndex], - members: [ - ...state.data[orgIndex].members.slice(0, personIndex), - { - ...person, - }, - ...state.data[orgIndex].members.slice(personIndex + 1) - ] - }, - ...state.data.slice(orgIndex + 1), - ] - }; - }, - [handleStatusUpdate.toString()]: (state, action) => { + [handleMemberUpdate.toString()]: (state, action) => { const { orgIndex, person,