From bbe772067379f66855d6487e4bcd6383d31c554c Mon Sep 17 00:00:00 2001 From: Herman Snevajs Date: Fri, 20 Dec 2024 11:46:07 +0100 Subject: [PATCH] Separate collaborators method in Project store --- .../components/ProjectMembersTable.vue | 5 +-- .../packages/lib/src/modules/project/store.ts | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/web-app/packages/lib/src/modules/project/components/ProjectMembersTable.vue b/web-app/packages/lib/src/modules/project/components/ProjectMembersTable.vue index 33959ed7..e7e01062 100644 --- a/web-app/packages/lib/src/modules/project/components/ProjectMembersTable.vue +++ b/web-app/packages/lib/src/modules/project/components/ProjectMembersTable.vue @@ -106,7 +106,6 @@ const projectStore = useProjectStore() const userStore = useUserStore() const instanceStore = useInstanceStore() - const itemsPerPage = ref(10) const columns = ref([ { @@ -163,9 +162,9 @@ function removeMember(item: ProjectCollaborator) { } function roleUpdate(item: ProjectCollaborator, value: ProjectRoleName) { - projectStore.updateProjectAccess({ + projectStore.updateProjectCollaborators({ projectId: projectStore.project.id, - access: item, + collaborator: item, data: { role: value } }) } diff --git a/web-app/packages/lib/src/modules/project/store.ts b/web-app/packages/lib/src/modules/project/store.ts index ded681af..e9b1f4e4 100644 --- a/web-app/packages/lib/src/modules/project/store.ts +++ b/web-app/packages/lib/src/modules/project/store.ts @@ -783,6 +783,9 @@ export const useProjectStore = defineStore('projectModule', { Number(item.id) ) this.access = this.access.filter((access) => access.id !== item.id) + this.collaborators = this.collaborators.filter( + (collaborators) => collaborators.id !== item.id + ) } catch { notificationStore.error({ text: `Failed to update project access for user ${item.username}` @@ -831,6 +834,42 @@ export const useProjectStore = defineStore('projectModule', { } }, + async updateProjectCollaborators(payload: { + projectId: string + collaborator: ProjectCollaborator + data: UpdateProjectCollaboratorPayload + }) { + this.accessLoading = true + try { + if (!payload.collaborator.project_role) { + await ProjectApi.addProjectCollaborator(payload.projectId, { + ...payload.data, + username: payload.collaborator.username + }) + } else { + await ProjectApi.updateProjectCollaborator( + payload.projectId, + Number(payload.collaborator.id), + payload.data + ) + } + this.collaborators = this.collaborators.map((collaborator) => { + if (collaborator.id === payload.collaborator.id) { + collaborator.role = payload.data.role + collaborator.project_role = payload.data.role + } + return collaborator + }) + } catch (err) { + this.handleProjectAccessError( + err, + 'Failed to update project collaborator' + ) + } finally { + this.accessLoading = false + } + }, + handleProjectAccessError(err: unknown, defaultMessage: string) { const notificationStore = useNotificationStore() notificationStore.error({