mirror of
https://github.com/yldio/copilot.git
synced 2024-11-10 21:30:06 +02:00
refactoring redux action and reducer for member update to use same dispatch function
This commit is contained in:
parent
8b0e745bea
commit
581d9734fc
@ -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) => (
|
||||
<PersonStatus
|
||||
handleMemberUpdate={handleMemberUpdate}
|
||||
handleStatusTooltip={handleStatusTooltip}
|
||||
handleStatusUpdate={handleStatusUpdate}
|
||||
membersStatusOptions={orgUI.members_status}
|
||||
orgIndex={orgIndex}
|
||||
person={person}
|
||||
@ -50,8 +49,8 @@ const PeopleTable = (props) => {
|
||||
|
||||
const role = (person) => (
|
||||
<PersonRole
|
||||
handleMemberUpdate={handleMemberUpdate}
|
||||
handleRoleTooltip={handleRoleTooltip}
|
||||
handleRoleUpdate={handleRoleUpdate}
|
||||
membersRolesOptions={orgUI.members_roles}
|
||||
orgIndex={orgIndex}
|
||||
person={person}
|
||||
@ -78,10 +77,9 @@ const PeopleTable = (props) => {
|
||||
};
|
||||
|
||||
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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
@ -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`),
|
||||
};
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user