fix: project wrapper (#2589)

* fix: project wrapper

* fix: project wrapper for unjoined project

* chore: update store structure
This commit is contained in:
Aaryan Khandelwal 2023-11-01 17:10:10 +05:30 committed by GitHub
parent 4fcc4b4a01
commit 13ead7c314
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 204 additions and 181 deletions

View file

@ -522,6 +522,11 @@ export class ProjectStore implements IProjectStore {
};
joinProject = async (workspaceSlug: string, projectIds: string[]) => {
const newPermissions: { [projectId: string]: boolean } = {};
projectIds.forEach((projectId) => {
newPermissions[projectId] = true;
});
try {
this.loader = true;
this.error = null;
@ -530,6 +535,10 @@ export class ProjectStore implements IProjectStore {
await this.fetchProjects(workspaceSlug);
runInAction(() => {
this.rootStore.user.hasPermissionToProject = {
...this.rootStore.user.hasPermissionToProject,
...newPermissions,
};
this.loader = false;
this.error = null;
});

View file

@ -18,11 +18,14 @@ export interface IUserStore {
dashboardInfo: any;
workspaceMemberInfo: IWorkspaceMemberMe | null;
hasPermissionToWorkspace: boolean | null;
hasPermissionToWorkspace: {
[workspaceSlug: string]: boolean | null;
};
projectMemberInfo: IProjectMember | null;
projectNotFound: boolean;
hasPermissionToProject: boolean | null;
hasPermissionToProject: {
[projectId: string]: boolean | null;
};
fetchCurrentUser: () => Promise<IUser>;
fetchCurrentUserSettings: () => Promise<IUserSettings>;
@ -46,11 +49,14 @@ class UserStore implements IUserStore {
dashboardInfo: any = null;
workspaceMemberInfo: IWorkspaceMemberMe | null = null;
hasPermissionToWorkspace: boolean | null = null;
hasPermissionToWorkspace: {
[workspaceSlug: string]: boolean | null;
} = {};
projectMemberInfo: IProjectMember | null = null;
projectNotFound: boolean = false;
hasPermissionToProject: boolean | null = null;
hasPermissionToProject: {
[projectId: string]: boolean | null;
} = {};
// root store
rootStore;
// services
@ -68,7 +74,6 @@ class UserStore implements IUserStore {
workspaceMemberInfo: observable.ref,
hasPermissionToWorkspace: observable.ref,
projectMemberInfo: observable.ref,
projectNotFound: observable.ref,
hasPermissionToProject: observable.ref,
// action
fetchCurrentUser: action,
@ -128,14 +133,21 @@ class UserStore implements IUserStore {
fetchUserWorkspaceInfo = async (workspaceSlug: string) => {
try {
const response = await this.workspaceService.workspaceMemberMe(workspaceSlug.toString());
runInAction(() => {
this.workspaceMemberInfo = response;
this.hasPermissionToWorkspace = true;
this.hasPermissionToWorkspace = {
...this.hasPermissionToWorkspace,
[workspaceSlug]: true,
};
});
return response;
} catch (error) {
runInAction(() => {
this.hasPermissionToWorkspace = false;
this.hasPermissionToWorkspace = {
...this.hasPermissionToWorkspace,
[workspaceSlug]: false,
};
});
throw error;
}
@ -147,18 +159,20 @@ class UserStore implements IUserStore {
runInAction(() => {
this.projectMemberInfo = response;
this.hasPermissionToWorkspace = true;
this.hasPermissionToProject = {
...this.hasPermissionToProject,
[projectId]: true,
};
});
return response;
} catch (error: any) {
runInAction(() => {
this.hasPermissionToWorkspace = false;
this.hasPermissionToProject = {
...this.hasPermissionToProject,
[projectId]: false,
};
});
if (error?.status === 404) {
runInAction(() => {
this.projectNotFound = true;
});
}
throw error;
}
};