1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 07:10:05 +02:00

refactoring redux action and reducer for member update to use same dispatch function

This commit is contained in:
Alex Windett 2017-01-25 16:15:06 +00:00
parent 8b0e745bea
commit 581d9734fc
6 changed files with 18 additions and 52 deletions

View File

@ -10,9 +10,8 @@ const PeopleTable = (props) => {
const { const {
handleRoleTooltip, handleRoleTooltip,
handleRoleUpdate,
handleStatusTooltip, handleStatusTooltip,
handleStatusUpdate, handleMemberUpdate,
people = [], people = [],
orgUI = {}, orgUI = {},
orgIndex orgIndex
@ -38,8 +37,8 @@ const PeopleTable = (props) => {
const data = people.map( (person, index) => { const data = people.map( (person, index) => {
const status = (person) => ( const status = (person) => (
<PersonStatus <PersonStatus
handleMemberUpdate={handleMemberUpdate}
handleStatusTooltip={handleStatusTooltip} handleStatusTooltip={handleStatusTooltip}
handleStatusUpdate={handleStatusUpdate}
membersStatusOptions={orgUI.members_status} membersStatusOptions={orgUI.members_status}
orgIndex={orgIndex} orgIndex={orgIndex}
person={person} person={person}
@ -50,8 +49,8 @@ const PeopleTable = (props) => {
const role = (person) => ( const role = (person) => (
<PersonRole <PersonRole
handleMemberUpdate={handleMemberUpdate}
handleRoleTooltip={handleRoleTooltip} handleRoleTooltip={handleRoleTooltip}
handleRoleUpdate={handleRoleUpdate}
membersRolesOptions={orgUI.members_roles} membersRolesOptions={orgUI.members_roles}
orgIndex={orgIndex} orgIndex={orgIndex}
person={person} person={person}
@ -78,10 +77,9 @@ const PeopleTable = (props) => {
}; };
PeopleTable.propTypes = { PeopleTable.propTypes = {
handleMemberUpdate: React.PropTypes.func,
handleRoleTooltip: React.PropTypes.func, handleRoleTooltip: React.PropTypes.func,
handleRoleUpdate: React.PropTypes.func,
handleStatusTooltip: React.PropTypes.func, handleStatusTooltip: React.PropTypes.func,
handleStatusUpdate: React.PropTypes.func,
orgIndex: React.PropTypes.number, orgIndex: React.PropTypes.number,
orgUI: React.PropTypes.object, orgUI: React.PropTypes.object,
people: React.PropTypes.array, people: React.PropTypes.array,

View File

@ -54,13 +54,14 @@ const PersonRole = (props) => {
person, person,
personIndex, personIndex,
handleRoleTooltip, handleRoleTooltip,
handleRoleUpdate, handleMemberUpdate,
orgIndex orgIndex
} = props; } = props;
const toggled = toggledID; const toggled = toggledID;
const handleClick = () => handleRoleTooltip(person.uuid); const handleClick = () => handleRoleTooltip(person.uuid);
const handleOptionSelect = (updatedMember) => handleRoleUpdate(updatedMember); const handleOptionSelect = (updatedMember) =>
handleMemberUpdate(updatedMember);
// Only send relevent info as props // Only send relevent info as props
const _person = { const _person = {
@ -90,8 +91,8 @@ const PersonRole = (props) => {
}; };
PersonRole.propTypes = { PersonRole.propTypes = {
handleMemberUpdate: React.PropTypes.func,
handleRoleTooltip: React.PropTypes.func, handleRoleTooltip: React.PropTypes.func,
handleRoleUpdate: React.PropTypes.func,
membersRolesOptions: React.PropTypes.array, membersRolesOptions: React.PropTypes.array,
orgIndex: React.PropTypes.number, orgIndex: React.PropTypes.number,
person: React.PropTypes.object, person: React.PropTypes.object,

View File

@ -54,14 +54,14 @@ const PersonStatus = (props) => {
person, person,
personIndex, personIndex,
handleStatusTooltip, handleStatusTooltip,
handleStatusUpdate, handleMemberUpdate,
orgIndex orgIndex
} = props; } = props;
const toggled = toggledID; const toggled = toggledID;
const handleClick = () => handleStatusTooltip(person.uuid); const handleClick = () => handleStatusTooltip(person.uuid);
const handleOptionSelect = (updatedMember) => const handleOptionSelect = (updatedMember) =>
handleStatusUpdate(updatedMember); handleMemberUpdate(updatedMember);
// Only send relevent info as props // Only send relevent info as props
const _person = { const _person = {
@ -91,8 +91,8 @@ const PersonStatus = (props) => {
}; };
PersonStatus.propTypes = { PersonStatus.propTypes = {
handleMemberUpdate: React.PropTypes.func,
handleStatusTooltip: React.PropTypes.func, handleStatusTooltip: React.PropTypes.func,
handleStatusUpdate: React.PropTypes.func,
membersStatusOptions: React.PropTypes.array, membersStatusOptions: React.PropTypes.array,
orgIndex: React.PropTypes.number, orgIndex: React.PropTypes.number,
person: React.PropTypes.object, person: React.PropTypes.object,

View File

@ -20,8 +20,7 @@ const {
handleInviteToggle, handleInviteToggle,
handlePeopleRoleTooltip, handlePeopleRoleTooltip,
handlePeopleStatusTooltip, handlePeopleStatusTooltip,
handleRoleUpdate, handleMemberUpdate
handleStatusUpdate,
} = actions; } = actions;
const People = (props) => { const People = (props) => {
@ -46,10 +45,9 @@ const mapDispatchToProps = (dispatch) => ({
handleToggle: () => dispatch(handleInviteToggle()), handleToggle: () => dispatch(handleInviteToggle()),
handleStatusTooltip: (id) => dispatch(handlePeopleStatusTooltip(id)), handleStatusTooltip: (id) => dispatch(handlePeopleStatusTooltip(id)),
handleRoleTooltip: (id) => dispatch(handlePeopleRoleTooltip(id)), handleRoleTooltip: (id) => dispatch(handlePeopleRoleTooltip(id)),
handleRoleUpdate: (updatedMember) => handleMemberUpdate: (updatedMember) =>
dispatch(handleRoleUpdate(updatedMember)), dispatch(handleMemberUpdate(updatedMember)),
handleStatusUpdate: (updatedMember) =>
dispatch(handleStatusUpdate(updatedMember)),
}); });
module.exports = connect( module.exports = connect(

View File

@ -22,6 +22,5 @@ module.exports = {
createAction(`${APP}/HANDLE_PERSON_STATUS_TOOLTIP`), createAction(`${APP}/HANDLE_PERSON_STATUS_TOOLTIP`),
handlePeopleRoleTooltip: handlePeopleRoleTooltip:
createAction(`${APP}/HANDLE_PERSON_ROLE_TOOLTIP`), createAction(`${APP}/HANDLE_PERSON_ROLE_TOOLTIP`),
handleMemberUpdate: createAction(`${APP}/HANDLE_PERSON_ROLE_UPDATE`), handleMemberUpdate: createAction(`${APP}/HANDLE_MEMBER_UPDATE`),
handleStatusUpdate: createAction(`${APP}/HANDLE_PERSON_STATUS_UPDATE`),
}; };

View File

@ -10,8 +10,7 @@ const {
handleInviteToggle, handleInviteToggle,
handlePeopleRoleTooltip, handlePeopleRoleTooltip,
handlePeopleStatusTooltip, handlePeopleStatusTooltip,
handleRoleUpdate, handleMemberUpdate,
handleStatusUpdate,
} = actions; } = actions;
module.exports = handleActions({ module.exports = handleActions({
@ -48,36 +47,7 @@ module.exports = handleActions({
} }
}; };
}, },
[handleRoleUpdate.toString()]: (state, action) => { [handleMemberUpdate.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) => {
const { const {
orgIndex, orgIndex,
person, person,