Skip to content

Commit 50edf8a

Browse files
committed
fix: edge case fixes for Join/Decline buttons
ref issue #3310
1 parent de90e5d commit 50edf8a

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src/projects/detail/ProjectDetail.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class ProjectDetail extends Component {
163163
this.onUserInviteAction(queryUrlParams.invitation === 'accept')
164164
}
165165

166-
if (project && project.invites.length > 0 && this.shouldForceCallAcceptRefuseRequest()) {
166+
if (project && project.invites && project.invites.length > 0 && this.shouldForceCallAcceptRefuseRequest()) {
167167
// remove invitation query param
168168
this.props.history.replace(`/projects/${this.props.match.params.projectId}`)
169169
}

src/projects/list/components/Projects/Projects.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,28 @@ class Projects extends Component {
203203
* @param {Bool} isAccept is accept invite
204204
*/
205205
callInviteRequest(project, isAccept) {
206-
const isAcceptingInvite = (isAcception) => {
206+
const setIsAcceptingInvite = (isAccepting) => {
207207
const { isAcceptingInvite } = this.state
208-
isAcceptingInvite[project.id] = isAcception
209-
this.setState({ isAcceptingInvite })
208+
209+
this.setState({ isAcceptingInvite: {
210+
...isAcceptingInvite,
211+
[project.id]: isAccepting
212+
}
213+
})
210214
}
211215

212-
isAcceptingInvite(true)
216+
setIsAcceptingInvite(true)
213217

214218
this.props.acceptOrRefuseInvite(project.id, {
215219
userId: this.props.currentUser.userId,
216220
email: this.props.currentUser.email,
217221
status: isAccept ? PROJECT_MEMBER_INVITE_STATUS_ACCEPTED : PROJECT_MEMBER_INVITE_STATUS_REFUSED
218222
}, this.props.currentUser).then(() => {
219-
isAcceptingInvite(false)
223+
setIsAcceptingInvite(false)
220224
}) .catch((err) => {
221225
// if we fail to accept invite
222226
console.log(err)
223-
isAcceptingInvite(false)
227+
setIsAcceptingInvite(false)
224228
})
225229
}
226230

src/projects/reducers/projectSearch.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)