Skip to content

Commit

Permalink
Separate collaborators method in Project store
Browse files Browse the repository at this point in the history
  • Loading branch information
harminius committed Dec 20, 2024
1 parent 8389be3 commit bbe7720
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const projectStore = useProjectStore()
const userStore = useUserStore()
const instanceStore = useInstanceStore()


const itemsPerPage = ref(10)
const columns = ref<DataViewWrapperColumnItem[]>([
{
Expand Down Expand Up @@ -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 }
})
}
Expand Down
39 changes: 39 additions & 0 deletions web-app/packages/lib/src/modules/project/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit bbe7720

Please sign in to comment.