@@ -73,7 +73,7 @@ export default function(state = initialState, action) {
7373 const bigRoles = _ . intersectionWith ( roles , ADMIN_ROLES . concat ( MANAGER_ROLES ) , _ . isEqual )
7474
7575 const projectIndex = _ . findIndex ( projects , { id : action . meta . projectId } )
76- if ( ! _ . isNil ( projectIndex ) ) {
76+ if ( projectIndex > - 1 ) {
7777 if ( bigRoles . length === 0 ) {
7878 // remove project from the search list if normal user refuse invite
7979 return update ( state , {
@@ -82,7 +82,7 @@ export default function(state = initialState, action) {
8282 } else {
8383 // remove user from invites list
8484 const userIndex = _ . findIndex ( projects [ projectIndex ] . invites , { userId : action . meta . currentUser . userId } )
85- if ( ! _ . isNil ( userIndex ) ) {
85+ if ( userIndex > - 1 ) {
8686 const updatedProject = update ( projects [ projectIndex ] , {
8787 invites : { $splice : [ [ userIndex , 1 ] ] } ,
8888 } )
@@ -96,15 +96,29 @@ export default function(state = initialState, action) {
9696 // user accept invite
9797 const { projects } = state
9898 const projectIndex = _ . findIndex ( projects , { id : action . meta . projectId } )
99- if ( ! _ . isNil ( projectIndex ) ) {
100- const user = _ . cloneDeep ( _ . pick ( action . meta . currentUser , [
101- 'userId' , 'projectId' , 'photoURL' , 'handle' ,
102- ] ) )
103- user . role = action . payload . role
104- user . deletedAt = null
105- const updatedProject = update ( projects [ projectIndex ] , {
106- members : { $push : [ user ] } ,
99+
100+ if ( projectIndex > - 1 ) {
101+ // construct member for the project member list
102+ const member = _ . pick ( action . meta . currentUser , [
103+ 'userId' , 'photoURL' , 'handle' ,
104+ ] )
105+ member . role = action . payload . role
106+ member . projectId = action . meta . projectId
107+
108+ // add new member to member list
109+ let updatedProject = update ( projects [ projectIndex ] , {
110+ members : { $push : [ member ] } ,
107111 } )
112+
113+ // remove user from invites list
114+ const userIndex = _ . findIndex ( projects [ projectIndex ] . invites , { userId : action . meta . currentUser . userId } )
115+ if ( userIndex > - 1 ) {
116+ updatedProject = update ( updatedProject , {
117+ invites : { $splice : [ [ userIndex , 1 ] ] } ,
118+ } )
119+ }
120+
121+ // update project
108122 return update ( state , {
109123 projects : { $splice : [ [ projectIndex , 1 , updatedProject ] ] }
110124 } )
0 commit comments