diff --git a/web/store/dataMaps/workspace.data.store.ts b/web/store/dataMaps/workspace.data.store.ts index 7db350729..801ce458e 100644 --- a/web/store/dataMaps/workspace.data.store.ts +++ b/web/store/dataMaps/workspace.data.store.ts @@ -7,7 +7,7 @@ import { set } from "lodash"; export interface IWorkspaceData { workspaceMap: Record; - addWorkspaces: (workspaces: IWorkspace[]) => void; + addWorkspace: (workspaces: IWorkspace) => void; deleteWorkspace: (workspaceId: string) => void; getWorkspacebyId: (workspaceId: string) => WorkspaceModel | undefined; } @@ -25,10 +25,8 @@ export class WorkspaceData implements IWorkspaceData { this.dataStore = _dataStore; } - addWorkspaces = (workspaces: IWorkspace[]) => { - workspaces.forEach((workspace) => { - set(this.workspaceMap, [workspace.id], new WorkspaceModel(workspace, this.dataStore)); - }); + addWorkspace = (workspace: IWorkspace) => { + set(this.workspaceMap, [workspace.id], new WorkspaceModel(workspace, this.dataStore)); }; deleteWorkspace = (workspaceId: string) => { diff --git a/web/store/user.store.ts b/web/store/user.store.ts index 13a06c769..19a593f9e 100644 --- a/web/store/user.store.ts +++ b/web/store/user.store.ts @@ -38,9 +38,9 @@ export class UserModel implements IUserModel { fetchWorkspaces = async () => { const workspaceResponse = await this.workspaceService.userWorkspaces(); - this.data.workspace.addWorkspaces(workspaceResponse); runInAction(() => { workspaceResponse.forEach((workspace) => { + this.data.workspace.addWorkspace(workspace); set(this.workspaces, [workspace.id], this.data.workspace.workspaceMap[workspace.id]); }); }); @@ -53,8 +53,8 @@ export class UserModel implements IUserModel { */ createWorkspace = async (data: Partial) => await this.workspaceService.createWorkspace(data).then((response) => { - this.data.workspace.addWorkspaces([response]); runInAction(() => { + this.data.workspace.addWorkspace(response); set(this.workspaces, [response.id], this.data.workspace.workspaceMap[response.id]); }); return response; diff --git a/web/store/workspace.store.ts b/web/store/workspace.store.ts index f9517fcc6..ea3c261bc 100644 --- a/web/store/workspace.store.ts +++ b/web/store/workspace.store.ts @@ -58,4 +58,22 @@ export class WorkspaceModel implements IWorkspaceModel { this.organization_size = workspace.organization_size; this.total_issues = workspace.total_issues; } + + get toJSON() { + return { + id: this.id, + owner: this.owner, + created_at: this.created_at, + updated_at: this.updated_at, + name: this.name, + url: this.url, + logo: this.logo, + total_members: this.total_members, + slug: this.slug, + created_by: this.created_by, + updated_by: this.updated_by, + organization_size: this.organization_size, + total_issues: this.total_issues, + }; + } }