Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions frontend/src/components/collaborator/CollaboratorEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<CollaboratorForm
:collaboration="entityData"
:status="collaborator.status"
:readonly-role="isLastManager"
:readonly-role="isLastManager || !isManager"
:initial-collaboration="collaborator"
>
<template #statusChange>
Expand Down Expand Up @@ -131,6 +131,7 @@ import { errorToMultiLineToast } from '@/components/toast/toasts.js'
import CollaboratorListItem from '@/components/collaborator/CollaboratorListItem.vue'
import PromptEntityDelete from '@/components/prompt/PromptEntityDelete.vue'
import campCollaborationDisplayName from '../../../../common/helpers/campCollaborationDisplayName'
import isOwnCampCollaboration from './isOwnCampCollaboration.js'

export default {
name: 'CollaboratorEdit',
Expand Down Expand Up @@ -173,10 +174,7 @@ export default {
)
},
isOwnCampCollaboration() {
if (!(typeof this.collaborator.user === 'function')) {
return false
}
return this.$store.state.auth.user?.id === this.collaborator.user().id
return isOwnCampCollaboration(this.collaborator, this.$store.state.auth)
},
name() {
return campCollaborationDisplayName(this.collaborator, this.$tc.bind(this), false)
Expand Down
34 changes: 24 additions & 10 deletions frontend/src/components/collaborator/CollaboratorList.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<template>
<v-list class="mx-n2">
<transition-group v-if="isManager" name="list">
<transition-group name="list">
<div v-for="collaborator in sortedCollaborators" :key="collaborator._meta.self">
<CollaboratorEdit :collaborator="collaborator" :inactive="inactive" />
<CollaboratorEdit
v-if="isManager || isOwnCollaborationMap[collaborator._meta.self]"
:collaborator="collaborator"
:inactive="inactive"
/>
<CollaboratorListItem
v-else
:key="collaborator._meta.self"
:collaborator="collaborator"
:inactive="inactive"
/>
</div>
</transition-group>
<template v-else>
<CollaboratorListItem
v-for="collaborator in sortedCollaborators"
:key="collaborator._meta.self"
:collaborator="collaborator"
:inactive="inactive"
/>
</template>
</v-list>
</template>

Expand All @@ -21,6 +23,7 @@ import CollaboratorEdit from '@/components/collaborator/CollaboratorEdit.vue'
import CollaboratorListItem from '@/components/collaborator/CollaboratorListItem.vue'
import { sortBy } from 'lodash-es'
import campCollaborationDisplayName from '@/common/helpers/campCollaborationDisplayName.js'
import isOwnCampCollaboration from './isOwnCampCollaboration.js'

const ROLE_ORDER = ['manager', 'member', 'guest']

Expand All @@ -44,6 +47,17 @@ export default {
campCollaborationDisplayName(c, this.$tc.bind(this)).toLowerCase()
)
},

isOwnCollaborationMap() {
const result = {}
this.collaborators.forEach((collaborator) => {
result[collaborator._meta.self] = isOwnCampCollaboration(
collaborator,
this.$store.state.auth
)
})
return result
},
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import DialogBase from '@/components/dialog/DialogBase.vue'
import campCollaborationDisplayName from '@/common/helpers/campCollaborationDisplayName.js'
import { errorToMultiLineToast } from '@/components/toast/toasts'
import PopoverPrompt from '@/components/prompt/PopoverPrompt.vue'
import isOwnCampCollaboration from './isOwnCampCollaboration.js'

export default {
name: 'PromptCollaboratorDeactivate',
Expand All @@ -45,10 +46,7 @@ export default {
},
computed: {
isOwnCampCollaboration() {
if (!(typeof this.entity.user === 'function')) {
return false
}
return this.$store.state.auth.user?.id === this.entity.user().id
return isOwnCampCollaboration(this.entity, this.$store.state.auth)
},
displayName() {
return campCollaborationDisplayName(this.entity, this.$tc.bind(this))
Expand All @@ -65,9 +63,13 @@ export default {
.catch((e) => this.$toast.error(errorToMultiLineToast(e)))

// User left camp -> navigate to camp-overview
promise.then(
() => this.isOwnCampCollaboration && this.$router.push({ name: 'camps' })
)
promise.then(() => {
if (!this.isOwnCampCollaboration) {
return
}
this.api.get().camps().$reload()
this.$router.push({ name: 'camps' })
})

return promise
},
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/components/collaborator/isOwnCampCollaboration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @typedef Collaborator {
* user: () => { id: string },
* }
*
* @typedef Auth {
* user: { id: string },
* }
*
* @param {Collaborator} collaborator
* @param {Auth} auth
* @returns {boolean}
*/
export default function isOwnCampCollaboration(collaborator, auth) {
if (!(typeof collaborator.user === 'function')) {
return false
}
return auth.user?.id === collaborator.user().id
}
Loading