Skip to content

Commit 2422565

Browse files
authored
Merge pull request #1636 from topcoder-platform/PM-973_invite-by-mail
PM-973 - fix checkIsUserInvitedToProject
2 parents de8f892 + 21d0574 commit 2422565

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/containers/Challenges/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
setActiveProject,
2121
resetSidebarActiveParams
2222
} from '../../actions/sidebar'
23-
import { checkAdmin, checkIsUserInvited } from '../../util/tc'
23+
import { checkAdmin, checkIsUserInvitedToProject } from '../../util/tc'
2424
import { withRouter } from 'react-router-dom'
2525

2626
class Challenges extends Component {
@@ -60,7 +60,7 @@ class Challenges extends Component {
6060
componentDidUpdate () {
6161
const { auth } = this.props
6262

63-
if (checkIsUserInvited(auth.token, this.props.projectDetail)) {
63+
if (checkIsUserInvitedToProject(auth.token, this.props.projectDetail)) {
6464
this.props.history.push(`/projects/${this.props.projectId}/invitation`)
6565
}
6666
}

src/containers/ProjectEditor/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
updateProject
1616
} from '../../actions/projects'
1717
import { setActiveProject } from '../../actions/sidebar'
18-
import { checkAdminOrCopilot, checkAdmin, checkIsUserInvited } from '../../util/tc'
18+
import { checkAdminOrCopilot, checkAdmin, checkIsUserInvitedToProject } from '../../util/tc'
1919
import { PROJECT_ROLES } from '../../config/constants'
2020
import Loader from '../../components/Loader'
2121

@@ -38,7 +38,7 @@ class ProjectEditor extends Component {
3838
componentDidUpdate () {
3939
const { auth } = this.props
4040

41-
if (checkIsUserInvited(auth.token, this.props.projectDetail)) {
41+
if (checkIsUserInvitedToProject(auth.token, this.props.projectDetail)) {
4242
this.props.history.push(`/projects/${this.props.projectDetail.id}/invitation`)
4343
}
4444

src/containers/ProjectInvitations/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
33
import { connect } from 'react-redux'
44
import { withRouter } from 'react-router-dom'
55
import { toastr } from 'react-redux-toastr'
6-
import { checkIsUserInvited } from '../../util/tc'
6+
import { checkIsUserInvitedToProject } from '../../util/tc'
77
import { isEmpty } from 'lodash'
88
import { loadProjectInvites } from '../../actions/projects'
99
import ConfirmationModal from '../../components/Modal/ConfirmationModal'
@@ -20,7 +20,7 @@ const theme = {
2020
const ProjectInvitations = ({ match, auth, isProjectLoading, history, projectDetail, loadProjectInvites }) => {
2121
const automaticAction = useMemo(() => [PROJECT_MEMBER_INVITE_STATUS_ACCEPTED, PROJECT_MEMBER_INVITE_STATUS_REFUSED].includes(match.params.action) ? match.params.action : undefined, [match.params])
2222
const projectId = useMemo(() => parseInt(match.params.projectId), [match.params])
23-
const invitation = useMemo(() => checkIsUserInvited(auth.token, projectDetail), [auth.token, projectDetail])
23+
const invitation = useMemo(() => checkIsUserInvitedToProject(auth.token, projectDetail), [auth.token, projectDetail])
2424
const [isUpdating, setIsUpdating] = useState(automaticAction || false)
2525
const isAccepting = isUpdating === PROJECT_MEMBER_INVITE_STATUS_ACCEPTED
2626
const isDeclining = isUpdating === PROJECT_MEMBER_INVITE_STATUS_REFUSED

src/containers/Projects/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { withRouter, Link } from 'react-router-dom'
55
import { connect } from 'react-redux'
66
import PropTypes from 'prop-types'
77
import Loader from '../../components/Loader'
8-
import { checkAdminOrCopilot, checkIsUserInvited, checkManager } from '../../util/tc'
8+
import { checkAdminOrCopilot, checkIsUserInvitedToProject, checkManager } from '../../util/tc'
99
import { PrimaryButton } from '../../components/Buttons'
1010
import Select from '../../components/Select'
1111
import ProjectCard from '../../components/ProjectCard'
@@ -112,7 +112,7 @@ const Projects = ({ projects, auth, isLoading, projectsCount, loadProjects, load
112112
{projects.map(p => (
113113
<li key={p.id}>
114114
<ProjectCard
115-
isInvited={!!checkIsUserInvited(auth.token, p)}
115+
isInvited={!!checkIsUserInvitedToProject(auth.token, p)}
116116
projectStatus={p.status}
117117
projectName={p.name}
118118
projectId={p.id}

src/util/tc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ export const checkAdminOrCopilot = (token, project) => {
233233
return isAdmin || (isCopilot && canManageProject)
234234
}
235235

236-
export const checkIsUserInvited = (token, project) => {
236+
export const checkIsUserInvitedToProject = (token, project) => {
237237
if (!token) {
238238
return
239239
}
240240

241241
const tokenData = decodeToken(token)
242-
return project && !_.isEmpty(project) && _.find(project.invites, { userId: tokenData.userId })
242+
return project && !_.isEmpty(project) && (_.find(project.invites, d => d.userId === tokenData.userId || d.email === tokenData.email))
243243
}
244244

245245
/**

0 commit comments

Comments
 (0)