Use team update route to update a team member's admin status
This commit is contained in:
parent
b779500240
commit
903cdcc93a
2 changed files with 16 additions and 9 deletions
|
@ -7,7 +7,8 @@ export default class TeamMemberService extends AbstractService {
|
||||||
super({
|
super({
|
||||||
create: '/teams/{teamId}/members',
|
create: '/teams/{teamId}/members',
|
||||||
delete: '/teams/{teamId}/members/{username}',
|
delete: '/teams/{teamId}/members/{username}',
|
||||||
});
|
update: '/teams/{teamId}/members/{username}/admin',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
processModel(model) {
|
processModel(model) {
|
||||||
|
@ -19,7 +20,7 @@ export default class TeamMemberService extends AbstractService {
|
||||||
modelFactory(data) {
|
modelFactory(data) {
|
||||||
return new TeamMemberModel(data)
|
return new TeamMemberModel(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeCreate(model) {
|
beforeCreate(model) {
|
||||||
model.userId = model.id // The api wants to get the user id as user_Id
|
model.userId = model.id // The api wants to get the user id as user_Id
|
||||||
model.admin = model.admin === null ? false : model.admin
|
model.admin = model.admin === null ? false : model.admin
|
||||||
|
|
|
@ -129,6 +129,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="actions" v-if="userIsAdmin">
|
<td class="actions" v-if="userIsAdmin">
|
||||||
<button @click="toggleUserType(m)" class="button buttonright is-primary"
|
<button @click="toggleUserType(m)" class="button buttonright is-primary"
|
||||||
|
:class="{'is-loading': teamMemberService.loading}"
|
||||||
v-if="m.id !== userInfo.id">
|
v-if="m.id !== userInfo.id">
|
||||||
Make
|
Make
|
||||||
<template v-if="!m.admin">
|
<template v-if="!m.admin">
|
||||||
|
@ -139,6 +140,7 @@
|
||||||
</template>
|
</template>
|
||||||
</button>
|
</button>
|
||||||
<button @click="() => {member = m; showUserDeleteModal = true}" class="button is-danger"
|
<button @click="() => {member = m; showUserDeleteModal = true}" class="button is-danger"
|
||||||
|
:class="{'is-loading': teamMemberService.loading}"
|
||||||
v-if="m.id !== userInfo.id">
|
v-if="m.id !== userInfo.id">
|
||||||
<span class="icon is-small">
|
<span class="icon is-small">
|
||||||
<icon icon="trash-alt"/>
|
<icon icon="trash-alt"/>
|
||||||
|
@ -230,7 +232,7 @@
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// call again the method if the route changes
|
// call again the method if the route changes
|
||||||
'$route': 'loadTeam'
|
'$route': 'loadTeam',
|
||||||
},
|
},
|
||||||
computed: mapState({
|
computed: mapState({
|
||||||
userInfo: state => state.auth.info,
|
userInfo: state => state.auth.info,
|
||||||
|
@ -309,11 +311,15 @@
|
||||||
},
|
},
|
||||||
toggleUserType(member) {
|
toggleUserType(member) {
|
||||||
member.admin = !member.admin
|
member.admin = !member.admin
|
||||||
this.teamMemberService.delete(member)
|
this.teamMemberService.update(member)
|
||||||
.then(() => this.teamMemberService.create(member))
|
.then(r => {
|
||||||
.then(() => {
|
for(const tm in this.team.members) {
|
||||||
this.loadTeam()
|
if (this.team.members[tm].id === member.id) {
|
||||||
this.success({message: 'The team member was successfully made ' + (member.admin ? 'admin': 'member') + '.'}, this)
|
this.$set(this.team.members[tm], 'admin', r.admin)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.success({message: 'The team member was successfully made ' + (member.admin ? 'admin' : 'member') + '.'}, this)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
this.error(e, this)
|
this.error(e, this)
|
||||||
|
@ -336,7 +342,7 @@
|
||||||
clearAll() {
|
clearAll() {
|
||||||
this.$set(this, 'foundUsers', [])
|
this.$set(this, 'foundUsers', [])
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue