From 2c61693c21d834cc082426333b31c567fa05c749 Mon Sep 17 00:00:00 2001 From: Alex Windett Date: Tue, 31 Jan 2017 11:34:15 +0000 Subject: [PATCH] implimenting adding member to org and project --- frontend/src/components/people-list/invite.js | 49 +++++++++++++------ frontend/src/containers/org/people.js | 2 + frontend/src/containers/project/people.js | 2 + frontend/src/state/actions.js | 4 ++ frontend/src/state/reducers/orgs.js | 23 +++++++++ frontend/src/state/reducers/projects.js | 23 +++++++++ 6 files changed, 88 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/people-list/invite.js b/frontend/src/components/people-list/invite.js index 4a49bf62..e68a5bbe 100644 --- a/frontend/src/components/people-list/invite.js +++ b/frontend/src/components/people-list/invite.js @@ -11,9 +11,11 @@ require('react-select/dist/react-select.css'); const Invite = React.createClass({ propTypes: { + addMemember: React.PropTypes.func, // UI: React.PropTypes.object, handleToggle: React.PropTypes.func, // people: React.PropTypes.array, + parentIndex: React.PropTypes.number, platformMembers: React.PropTypes.array, }, @@ -31,6 +33,22 @@ const Invite = React.createClass({ })); }, + handleSubmit(e) { + e.preventDefault(); + + const data = { + member: { + name: this.state.selectValue.label, + email: this.state.selectValue.value, + role: 'Unassigned', + status: 'Sent invitation', + }, + parentIndex: this.props.parentIndex, + }; + + this.props.addMemember(data); + }, + render() { const { @@ -69,21 +87,22 @@ const Invite = React.createClass({ - {/*TODO: Fix why there are issues with webpack and nodemodules*/} - + + diff --git a/frontend/src/containers/org/people.js b/frontend/src/containers/org/people.js index 3e486bbb..60f2931c 100644 --- a/frontend/src/containers/org/people.js +++ b/frontend/src/containers/org/people.js @@ -17,6 +17,7 @@ const { } = selectors; const { + addMemberToOrg, orgHandleInviteToggle, orgHandlePeopleRoleTooltip, orgHandlePeopleStatusTooltip, @@ -43,6 +44,7 @@ const mapStateToProps = (state, { }); const mapDispatchToProps = (dispatch) => ({ + addMemember: (member) => dispatch(addMemberToOrg(member)), handleToggle: () => dispatch(orgHandleInviteToggle()), handleStatusTooltip: (id) => dispatch(orgHandlePeopleStatusTooltip(id)), handleRoleTooltip: (id) => dispatch(orgHandlePeopleRoleTooltip(id)), diff --git a/frontend/src/containers/project/people.js b/frontend/src/containers/project/people.js index 2107f5fb..427f0f1e 100644 --- a/frontend/src/containers/project/people.js +++ b/frontend/src/containers/project/people.js @@ -17,6 +17,7 @@ const { } = selectors; const { + addMemberToProject, projectHandleInviteToggle, projectHandlePeopleRoleTooltip, projectHandlePeopleStatusTooltip, @@ -43,6 +44,7 @@ const mapStateToProps = (state, { }); const mapDispatchToProps = (dispatch) => ({ + addMemember: (member) => dispatch(addMemberToProject(member)), handleToggle: () => dispatch(projectHandleInviteToggle()), handleStatusTooltip: (id) => dispatch(projectHandlePeopleStatusTooltip(id)), handleRoleTooltip: (id) => dispatch(projectHandlePeopleRoleTooltip(id)), diff --git a/frontend/src/state/actions.js b/frontend/src/state/actions.js index b58ac68f..3bd3c157 100644 --- a/frontend/src/state/actions.js +++ b/frontend/src/state/actions.js @@ -8,6 +8,8 @@ const { const APP = constantCase(process.env['APP_NAME']); const projectMemberActions = { + addMemberToProject: + createAction(`${APP}/PROJECT_ADD_MEMBER`), projectHandleInviteToggle: createAction(`${APP}/PROJECT_HANDLE_INVITE_MEMBER_TOGGLE`), projectHandlePeopleStatusTooltip: @@ -21,6 +23,8 @@ const projectMemberActions = { }; const orgMemberActions = { + addMemberToOrg: + createAction(`${APP}/ORG_ADD_MEMBER`), orgHandleInviteToggle: createAction(`${APP}/ORG_HANDLE_INVITE_MEMBER_TOGGLE`), orgHandlePeopleStatusTooltip: diff --git a/frontend/src/state/reducers/orgs.js b/frontend/src/state/reducers/orgs.js index 02339525..ef8486c5 100644 --- a/frontend/src/state/reducers/orgs.js +++ b/frontend/src/state/reducers/orgs.js @@ -7,6 +7,7 @@ const { } = ReduxActions; const { + addMemberToOrg, orgHandleInviteToggle, orgHandlePeopleRoleTooltip, orgHandlePeopleStatusTooltip, @@ -15,6 +16,28 @@ const { } = actions; module.exports = handleActions({ + [addMemberToOrg.toString()]: (state, action) => { + + const { + parentIndex, + member, + } = action.payload; + + return { + ...state, + data: [ + ...state.data.slice(0, parentIndex), + { + ...state.data[parentIndex], + members: [ + ...state.data[parentIndex].members, + member + ] + }, + ...state.data.slice(parentIndex + 1), + ] + }; + }, [orgHandleInviteToggle.toString()]: (state, action) => { return { ...state, diff --git a/frontend/src/state/reducers/projects.js b/frontend/src/state/reducers/projects.js index 8eaac127..3126850a 100644 --- a/frontend/src/state/reducers/projects.js +++ b/frontend/src/state/reducers/projects.js @@ -7,6 +7,7 @@ const { } = ReduxActions; const { + addMemberToProject, projectHandleInviteToggle, projectHandlePeopleRoleTooltip, projectHandlePeopleStatusTooltip, @@ -15,6 +16,28 @@ const { } = actions; module.exports = handleActions({ + [addMemberToProject.toString()]: (state, action) => { + + const { + parentIndex, + member, + } = action.payload; + + return { + ...state, + data: [ + ...state.data.slice(0, parentIndex), + { + ...state.data[parentIndex], + members: [ + ...state.data[parentIndex].members, + member + ] + }, + ...state.data.slice(parentIndex + 1), + ] + }; + }, [projectHandleInviteToggle.toString()]: (state, action) => { return { ...state,