Skip to content

Commit 94767d4

Browse files
authored
Merge pull request #1139 from appirio-tech/syncUsers
sync users
2 parents f5e65ed + a76276f commit 94767d4

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/api/projectMembers.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash'
22
import { axiosInstance as axios } from './requestInterceptor'
3-
import { TC_API_URL } from '../config/constants'
3+
import { TC_API_URL, CONNECT_MESSAGE_API_URL } from '../config/constants'
44

55
export function getMembersById (userIds) {
66
const _userIdArr = _.map(userIds, _id => `userId:${_id}`)
@@ -29,7 +29,9 @@ export function addProjectMember(projectId, newMember) {
2929
const url = `${TC_API_URL}/v4/projects/${projectId}/members/`
3030
return axios.post(url, { param: newMember})
3131
.then(resp => {
32-
return resp.data.result.content
32+
return axios.put(`${CONNECT_MESSAGE_API_URL}/v4/topics/syncUsers`,
33+
{ reference: 'project', referenceId: projectId })
34+
.then(() => resp.data.result.content)
3335
})
3436
}
3537

@@ -42,11 +44,23 @@ export function updateProjectMember(projectId, memberId, updatedProps) {
4244
})
4345
}
4446

45-
export function removeProjectMember(projectId, memberId) {
47+
export function removeProjectMember(projectId, memberId, isUserLeaving) {
4648
const url = `${TC_API_URL}/v4/projects/${projectId}/members/${memberId}/`
47-
return axios.delete(url)
48-
.then(resp => { // eslint-disable-line no-unused-vars
49-
// return the member id just removed
50-
return memberId
49+
let promise = { then: fn => fn() }
50+
if (isUserLeaving) {
51+
promise = axios.put(`${CONNECT_MESSAGE_API_URL}/v4/topics/syncUsers`,
52+
{ reference: 'project', referenceId: projectId, isUserLeaving })
53+
}
54+
return promise.then(() => {
55+
return axios.delete(url)
56+
.then(() => {
57+
if (!isUserLeaving) {
58+
return axios.put(`${CONNECT_MESSAGE_API_URL}/v4/topics/syncUsers`,
59+
{ reference: 'project', referenceId: projectId })
60+
.then(() => memberId)
61+
}
62+
// return the member id just removed
63+
return memberId
64+
})
5165
})
5266
}

src/projects/actions/projectMember.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function removeProjectMember(projectId, memberId, isUserLeaving) {
5454
return (dispatch) => {
5555
return dispatch({
5656
type: REMOVE_PROJECT_MEMBER,
57-
payload: removeMember(projectId, memberId),
57+
payload: removeMember(projectId, memberId, isUserLeaving),
5858
meta: { isUserLeaving }
5959
})
6060
}

0 commit comments

Comments
 (0)