forked from github/plane
chore: store implementation for workspace user projects role
This commit is contained in:
parent
69b716ab5c
commit
b0b25de07a
@ -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 () => {
|
||||
|
@ -19,7 +19,7 @@ export const WorkspaceAuthWrapper: FC<IWorkspaceAuthWrapper> = 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<IWorkspaceAuthWrapper> = 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) {
|
||||
|
@ -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<IUserProjectsRole> {
|
||||
return this.get(`/api/users/me/workspaces/${workspaceSlug}/project-roles/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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<IUserProjectsRole>;
|
||||
fetchWorkspaceMembers: (workspaceSlug: string) => Promise<void>;
|
||||
fetchWorkspaceMemberInvitations: (workspaceSlug: string) => Promise<IWorkspaceMemberInvitation[]>;
|
||||
updateMember: (workspaceSlug: string, memberId: string, data: Partial<IWorkspaceMember>) => Promise<void>;
|
||||
@ -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
|
||||
|
4
web/types/users.d.ts
vendored
4
web/types/users.d.ts
vendored
@ -162,6 +162,10 @@ export interface IUserProfileProjectSegregation {
|
||||
};
|
||||
}
|
||||
|
||||
export interface IUserProjectsRole {
|
||||
[project_id: string]: boolean;
|
||||
}
|
||||
|
||||
// export interface ICurrentUser {
|
||||
// id: readonly string;
|
||||
// avatar: string;
|
||||
|
@ -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==
|
||||
|
Loading…
Reference in New Issue
Block a user