Skip to content

Commit bbe7720

Browse files
committed
Separate collaborators method in Project store
1 parent 8389be3 commit bbe7720

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

web-app/packages/lib/src/modules/project/components/ProjectMembersTable.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ const projectStore = useProjectStore()
106106
const userStore = useUserStore()
107107
const instanceStore = useInstanceStore()
108108
109-
110109
const itemsPerPage = ref(10)
111110
const columns = ref<DataViewWrapperColumnItem[]>([
112111
{
@@ -163,9 +162,9 @@ function removeMember(item: ProjectCollaborator) {
163162
}
164163
165164
function roleUpdate(item: ProjectCollaborator, value: ProjectRoleName) {
166-
projectStore.updateProjectAccess({
165+
projectStore.updateProjectCollaborators({
167166
projectId: projectStore.project.id,
168-
access: item,
167+
collaborator: item,
169168
data: { role: value }
170169
})
171170
}

web-app/packages/lib/src/modules/project/store.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ export const useProjectStore = defineStore('projectModule', {
783783
Number(item.id)
784784
)
785785
this.access = this.access.filter((access) => access.id !== item.id)
786+
this.collaborators = this.collaborators.filter(
787+
(collaborators) => collaborators.id !== item.id
788+
)
786789
} catch {
787790
notificationStore.error({
788791
text: `Failed to update project access for user ${item.username}`
@@ -831,6 +834,42 @@ export const useProjectStore = defineStore('projectModule', {
831834
}
832835
},
833836

837+
async updateProjectCollaborators(payload: {
838+
projectId: string
839+
collaborator: ProjectCollaborator
840+
data: UpdateProjectCollaboratorPayload
841+
}) {
842+
this.accessLoading = true
843+
try {
844+
if (!payload.collaborator.project_role) {
845+
await ProjectApi.addProjectCollaborator(payload.projectId, {
846+
...payload.data,
847+
username: payload.collaborator.username
848+
})
849+
} else {
850+
await ProjectApi.updateProjectCollaborator(
851+
payload.projectId,
852+
Number(payload.collaborator.id),
853+
payload.data
854+
)
855+
}
856+
this.collaborators = this.collaborators.map((collaborator) => {
857+
if (collaborator.id === payload.collaborator.id) {
858+
collaborator.role = payload.data.role
859+
collaborator.project_role = payload.data.role
860+
}
861+
return collaborator
862+
})
863+
} catch (err) {
864+
this.handleProjectAccessError(
865+
err,
866+
'Failed to update project collaborator'
867+
)
868+
} finally {
869+
this.accessLoading = false
870+
}
871+
},
872+
834873
handleProjectAccessError(err: unknown, defaultMessage: string) {
835874
const notificationStore = useNotificationStore()
836875
notificationStore.error({

0 commit comments

Comments
 (0)