feat: allow users to leave a team they're in

This commit is contained in:
kolaente 2022-10-09 16:49:26 +02:00
parent 4784e3a22f
commit feeaca2c02
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 39 additions and 1 deletions

View file

@ -857,6 +857,12 @@
"text1": "Are you sure you want to remove this user from the team?", "text1": "Are you sure you want to remove this user from the team?",
"text2": "They will lose access to all lists and namespaces this team has access to. This CANNOT BE UNDONE!", "text2": "They will lose access to all lists and namespaces this team has access to. This CANNOT BE UNDONE!",
"success": "The user was successfully deleted from the team." "success": "The user was successfully deleted from the team."
},
"leave": {
"title": "Leave team",
"text1": "Are you sure you want to leave this team?",
"text2": "You will loose access to all lists and namespaces this team has access to. If you change your mind you'll need a team admin to add you again.",
"success": "You have successfully left the team."
} }
}, },
"attributes": { "attributes": {

View file

@ -127,6 +127,24 @@
</table> </table>
</card> </card>
<x-button class="is-fullwidth is-danger" @click="showLeaveModal = true">
{{ $t('team.edit.leave.title') }}
</x-button>
<!-- Leave team modal -->
<modal
v-if="showLeaveModal"
@close="showLeaveModal = false"
@submit="leave()"
>
<template #header><span>{{ $t('team.edit.leave.title') }}</span></template>
<template #text>
<p>{{ $t('team.edit.leave.text1') }}<br/>
{{ $t('team.edit.leave.text2') }}</p>
</template>
</modal>
<!-- Team delete modal --> <!-- Team delete modal -->
<transition name="modal"> <transition name="modal">
<modal <modal
@ -202,13 +220,14 @@ const teamMemberService = ref<TeamMemberService>(new TeamMemberService())
const userService = ref<UserService>(new UserService()) const userService = ref<UserService>(new UserService())
const team = ref<ITeam>() const team = ref<ITeam>()
const teamId = computed(() => route.params.id) const teamId = computed(() => Number(route.params.id))
const memberToDelete = ref<ITeamMember>() const memberToDelete = ref<ITeamMember>()
const newMember = ref<IUser>() const newMember = ref<IUser>()
const foundUsers = ref<IUser[]>() const foundUsers = ref<IUser[]>()
const showDeleteModal = ref(false) const showDeleteModal = ref(false)
const showUserDeleteModal = ref(false) const showUserDeleteModal = ref(false)
const showLeaveModal = ref(false)
const showError = ref(false) const showError = ref(false)
const title = ref('') const title = ref('')
@ -287,6 +306,19 @@ async function findUser(query: string) {
const users = await userService.value.getAll({}, {s: query}) const users = await userService.value.getAll({}, {s: query})
foundUsers.value = users.filter((u: IUser) => u.id !== userInfo.value.id) foundUsers.value = users.filter((u: IUser) => u.id !== userInfo.value.id)
} }
async function leave() {
try {
await teamMemberService.value.delete({
teamId: teamId.value,
username: userInfo.value.username,
})
success({message: t('team.edit.leave.success')})
await router.push({name: 'home'})
} finally {
showUserDeleteModal.value = false
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>