Skip to content

Commit 833f6e7

Browse files
committed
refactor/frontend: extract isOwnCampCollaboration in collaborator
1 parent ada2cc6 commit 833f6e7

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

frontend/src/components/collaborator/CollaboratorEdit.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import { errorToMultiLineToast } from '@/components/toast/toasts.js'
131131
import CollaboratorListItem from '@/components/collaborator/CollaboratorListItem.vue'
132132
import PromptEntityDelete from '@/components/prompt/PromptEntityDelete.vue'
133133
import campCollaborationDisplayName from '../../../../common/helpers/campCollaborationDisplayName'
134+
import isOwnCampCollaboration from './isOwnCampCollaboration.js'
134135
135136
export default {
136137
name: 'CollaboratorEdit',
@@ -173,10 +174,7 @@ export default {
173174
)
174175
},
175176
isOwnCampCollaboration() {
176-
if (!(typeof this.collaborator.user === 'function')) {
177-
return false
178-
}
179-
return this.$store.state.auth.user?.id === this.collaborator.user().id
177+
return isOwnCampCollaboration(this.collaborator, this.$store.state.auth)
180178
},
181179
name() {
182180
return campCollaborationDisplayName(this.collaborator, this.$tc.bind(this), false)

frontend/src/components/collaborator/CollaboratorList.vue

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,10 @@ import CollaboratorEdit from '@/components/collaborator/CollaboratorEdit.vue'
2323
import CollaboratorListItem from '@/components/collaborator/CollaboratorListItem.vue'
2424
import { sortBy } from 'lodash-es'
2525
import campCollaborationDisplayName from '@/common/helpers/campCollaborationDisplayName.js'
26+
import isOwnCampCollaboration from './isOwnCampCollaboration.js'
2627
2728
const ROLE_ORDER = ['manager', 'member', 'guest']
2829
29-
/**
30-
* @typedef Collaborator {
31-
* user: () => { id: string },
32-
* }
33-
*
34-
* @typedef Auth {
35-
* user: { id: string },
36-
* }
37-
*
38-
* @param {Collaborator} collaborator
39-
* @param {Auth} auth
40-
* @returns {boolean}
41-
*/
42-
function isOwnCampCollaboration(collaborator, auth) {
43-
if (!(typeof collaborator.user === 'function')) {
44-
return false
45-
}
46-
return auth.user?.id === collaborator.user().id
47-
}
48-
4930
export default {
5031
name: 'CollaboratorList',
5132
components: {

frontend/src/components/collaborator/PromptCollaboratorDeactivate.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import DialogBase from '@/components/dialog/DialogBase.vue'
3535
import campCollaborationDisplayName from '@/common/helpers/campCollaborationDisplayName.js'
3636
import { errorToMultiLineToast } from '@/components/toast/toasts'
3737
import PopoverPrompt from '@/components/prompt/PopoverPrompt.vue'
38+
import isOwnCampCollaboration from './isOwnCampCollaboration.js'
3839
3940
export default {
4041
name: 'PromptCollaboratorDeactivate',
@@ -45,10 +46,7 @@ export default {
4546
},
4647
computed: {
4748
isOwnCampCollaboration() {
48-
if (!(typeof this.entity.user === 'function')) {
49-
return false
50-
}
51-
return this.$store.state.auth.user?.id === this.entity.user().id
49+
return isOwnCampCollaboration(this.entity, this.$store.state.auth)
5250
},
5351
displayName() {
5452
return campCollaborationDisplayName(this.entity, this.$tc.bind(this))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @typedef Collaborator {
3+
* user: () => { id: string },
4+
* }
5+
*
6+
* @typedef Auth {
7+
* user: { id: string },
8+
* }
9+
*
10+
* @param {Collaborator} collaborator
11+
* @param {Auth} auth
12+
* @returns {boolean}
13+
*/
14+
export default function isOwnCampCollaboration(collaborator, auth) {
15+
if (!(typeof collaborator.user === 'function')) {
16+
return false
17+
}
18+
return auth.user?.id === collaborator.user().id
19+
}

0 commit comments

Comments
 (0)