diff --git a/web/components/profile/profile-issues.tsx b/web/components/profile/profile-issues.tsx index 35d9cf7b3..0b4af3da5 100644 --- a/web/components/profile/profile-issues.tsx +++ b/web/components/profile/profile-issues.tsx @@ -27,8 +27,11 @@ export const ProfileIssuesPage = observer((props: IProfileIssuesPage) => { const { workspaceProfileIssues: { loader, getIssues, fetchIssues }, workspaceProfileIssuesFilter: { issueFilters, fetchFilters }, + workspaceMember: { currentWorkspaceUserProjectsRole }, }: RootStore = useMobxStore(); + console.log("currentWorkspaceUserProjectsRole", currentWorkspaceUserProjectsRole); + useSWR( workspaceSlug && userId ? `CURRENT_WORKSPACE_PROFILE_ISSUES_${workspaceSlug}_${userId}_${type}` : null, async () => { diff --git a/web/layouts/auth-layout/workspace-wrapper.tsx b/web/layouts/auth-layout/workspace-wrapper.tsx index 622e9c23e..9a3bc09f0 100644 --- a/web/layouts/auth-layout/workspace-wrapper.tsx +++ b/web/layouts/auth-layout/workspace-wrapper.tsx @@ -19,7 +19,7 @@ export const WorkspaceAuthWrapper: FC = observer((props) user: { currentWorkspaceMemberInfo, hasPermissionToCurrentWorkspace, fetchUserWorkspaceInfo }, project: { fetchProjects }, workspace: { fetchWorkspaceLabels }, - workspaceMember: { fetchWorkspaceMembers }, + workspaceMember: { fetchWorkspaceMembers, fetchWorkspaceUserProjectsRole }, } = useMobxStore(); // router @@ -45,6 +45,11 @@ export const WorkspaceAuthWrapper: FC = observer((props) workspaceSlug ? `WORKSPACE_LABELS_${workspaceSlug}` : null, workspaceSlug ? () => fetchWorkspaceLabels(workspaceSlug.toString()) : null ); + // fetch workspace user projects role + useSWR( + workspaceSlug ? `WORKSPACE_PROJECTS_ROLE_${workspaceSlug}` : null, + workspaceSlug ? () => fetchWorkspaceUserProjectsRole(workspaceSlug.toString()) : null + ); // while data is being loaded if (!currentWorkspaceMemberInfo && hasPermissionToCurrentWorkspace === undefined) { diff --git a/web/services/workspace.service.ts b/web/services/workspace.service.ts index 42cfef450..52d47f8b5 100644 --- a/web/services/workspace.service.ts +++ b/web/services/workspace.service.ts @@ -13,6 +13,7 @@ import { IProductUpdateResponse, IWorkspaceBulkInviteFormData, IWorkspaceViewProps, + IUserProjectsRole, } from "types"; import { IWorkspaceView } from "types/workspace-views"; // store @@ -267,4 +268,12 @@ export class WorkspaceService extends APIService { throw error?.response?.data; }); } + + async getWorkspaceUserProjectsRole(workspaceSlug: string): Promise { + return this.get(`/api/users/me/workspaces/${workspaceSlug}/project-roles/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } } diff --git a/web/store/workspace/workspace-member.store.ts b/web/store/workspace/workspace-member.store.ts index def30ea59..7a97c059b 100644 --- a/web/store/workspace/workspace-member.store.ts +++ b/web/store/workspace/workspace-member.store.ts @@ -1,7 +1,7 @@ import { action, computed, observable, makeObservable, runInAction } from "mobx"; import { RootStore } from "../root"; // types -import { IWorkspaceMember, IWorkspaceMemberInvitation, IWorkspaceBulkInviteFormData } from "types"; +import { IWorkspaceMember, IWorkspaceMemberInvitation, IWorkspaceBulkInviteFormData, IUserProjectsRole } from "types"; // services import { WorkspaceService } from "services/workspace.service"; @@ -13,7 +13,9 @@ export interface IWorkspaceMemberStore { // observables members: { [workspaceSlug: string]: IWorkspaceMember[] }; // workspaceSlug: members[] memberInvitations: { [workspaceSlug: string]: IWorkspaceMemberInvitation[] }; + workspaceUserProjectsRole: { [workspaceSlug: string]: IUserProjectsRole } | undefined; // actions + fetchWorkspaceUserProjectsRole: (workspaceSlug: string) => Promise; fetchWorkspaceMembers: (workspaceSlug: string) => Promise; fetchWorkspaceMemberInvitations: (workspaceSlug: string) => Promise; updateMember: (workspaceSlug: string, memberId: string, data: Partial) => Promise; @@ -29,6 +31,7 @@ export interface IWorkspaceMemberStore { workspaceMembers: IWorkspaceMember[] | null; workspaceMemberInvitations: IWorkspaceMemberInvitation[] | null; workspaceMembersWithInvitations: any[] | null; + currentWorkspaceUserProjectsRole: IUserProjectsRole | undefined; } export class WorkspaceMemberStore implements IWorkspaceMemberStore { @@ -38,6 +41,7 @@ export class WorkspaceMemberStore implements IWorkspaceMemberStore { // observables members: { [workspaceSlug: string]: IWorkspaceMember[] } = {}; memberInvitations: { [workspaceSlug: string]: IWorkspaceMemberInvitation[] } = {}; + workspaceUserProjectsRole: { [workspaceSlug: string]: IUserProjectsRole } | undefined = undefined; // services workspaceService; // root store @@ -53,6 +57,7 @@ export class WorkspaceMemberStore implements IWorkspaceMemberStore { members: observable.ref, memberInvitations: observable.ref, // actions + fetchWorkspaceUserProjectsRole: action, fetchWorkspaceMembers: action, fetchWorkspaceMemberInvitations: action, updateMember: action, @@ -64,6 +69,7 @@ export class WorkspaceMemberStore implements IWorkspaceMemberStore { workspaceMembers: computed, workspaceMemberInvitations: computed, workspaceMembersWithInvitations: computed, + currentWorkspaceUserProjectsRole: computed, }); this.rootStore = _rootStore; @@ -126,6 +132,36 @@ export class WorkspaceMemberStore implements IWorkspaceMemberStore { ]; } + /** + * computed value provides the workspace user projects role + */ + get currentWorkspaceUserProjectsRole() { + if (!this.rootStore.workspace.workspaceSlug) return undefined; + + return this.workspaceUserProjectsRole?.[this.rootStore.workspace.workspaceSlug]; + } + + /** + * fetch workspace user projects role using workspace slug + * @param workspaceSlug + */ + fetchWorkspaceUserProjectsRole = async (workspaceSlug: string) => { + try { + const _workspaceUserProjectsRole = { ...this.workspaceUserProjectsRole }; + if (!_workspaceUserProjectsRole[workspaceSlug]) _workspaceUserProjectsRole[workspaceSlug] = {}; + + const response = await this.workspaceService.getWorkspaceUserProjectsRole(workspaceSlug); + _workspaceUserProjectsRole[workspaceSlug] = response; + + runInAction(() => { + this.workspaceUserProjectsRole = _workspaceUserProjectsRole; + }); + return response; + } catch (error) { + throw error; + } + }; + /** * fetch workspace members using workspace slug * @param workspaceSlug diff --git a/web/types/users.d.ts b/web/types/users.d.ts index 0d81ba2a7..7f1d452f7 100644 --- a/web/types/users.d.ts +++ b/web/types/users.d.ts @@ -162,6 +162,10 @@ export interface IUserProfileProjectSegregation { }; } +export interface IUserProjectsRole { + [project_id: string]: boolean; +} + // export interface ICurrentUser { // id: readonly string; // avatar: string; diff --git a/yarn.lock b/yarn.lock index 803857bfc..d6353dc89 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2797,7 +2797,7 @@ dependencies: "@types/react" "*" -"@types/react@*", "@types/react@^18.2.39", "@types/react@^18.2.42": +"@types/react@*", "@types/react@18.2.42", "@types/react@^18.2.39", "@types/react@^18.2.42": version "18.2.42" resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.42.tgz#6f6b11a904f6d96dda3c2920328a97011a00aba7" integrity sha512-c1zEr96MjakLYus/wPnuWDo1/zErfdU9rNsIGmE+NV71nx88FG9Ttgo5dqorXTu/LImX2f63WBP986gJkMPNbA==