diff --git a/web/store/cycle.store.ts b/web/store/cycle.store.ts index ea10c58af..695789998 100644 --- a/web/store/cycle.store.ts +++ b/web/store/cycle.store.ts @@ -179,12 +179,9 @@ export class CycleStore implements ICycleStore { const cyclesResponse = await this.cycleService.getCyclesWithParams(workspaceSlug, projectId, params); - const _cycleMap = set(this.cycleMap, [projectId], cyclesResponse); - const _cycles = set(this.cycles, [projectId, params], Object.keys(cyclesResponse)); - runInAction(() => { - this.cycleMap = _cycleMap; - this.cycles = _cycles; + set(this.cycleMap, [projectId], cyclesResponse); + set(this.cycles, [projectId, params], Object.keys(cyclesResponse)); this.loader = false; this.error = null; }); @@ -199,9 +196,8 @@ export class CycleStore implements ICycleStore { try { const response = await this.cycleService.getCycleDetails(workspaceSlug, projectId, cycleId); - const _cycleMap = set(this.cycleMap, [projectId, response?.id], response); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, response?.id], response); }); return response; @@ -215,9 +211,8 @@ export class CycleStore implements ICycleStore { try { const response = await this.cycleService.createCycle(workspaceSlug, projectId, data); - const _cycleMap = set(this.cycleMap, [projectId, response?.id], response); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, response?.id], response); }); const _currentView = this.cycleView === "active" ? "current" : this.cycleView; @@ -236,9 +231,8 @@ export class CycleStore implements ICycleStore { const currentCycle = this.cycleMap[projectId][cycleId]; - const _cycleMap = set(this.cycleMap, [projectId, cycleId], { ...currentCycle, ...data }); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, cycleId], { ...currentCycle, ...data }); }); const _currentView = this.cycleView === "active" ? "current" : this.cycleView; @@ -253,12 +247,10 @@ export class CycleStore implements ICycleStore { deleteCycle = async (workspaceSlug: string, projectId: string, cycleId: string) => { try { - const currentProjectCycles = this.cycleMap[projectId]; - delete currentProjectCycles[cycleId]; + if (!this.cycleMap?.[projectId]?.[cycleId]) return; - const _cycleMap = set(this.cycleMap, [projectId], currentProjectCycles); runInAction(() => { - this.cycleMap = _cycleMap; + delete this.cycleMap[projectId][cycleId]; }); const _response = await this.cycleService.deleteCycle(workspaceSlug, projectId, cycleId); @@ -278,9 +270,8 @@ export class CycleStore implements ICycleStore { const currentCycle = this.cycleMap[projectId][cycleId]; if (currentCycle.is_favorite) return; - const _cycleMap = set(this.cycleMap, [projectId, cycleId, "is_favorite"], true); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, cycleId, "is_favorite"], true); }); // updating through api. @@ -290,10 +281,8 @@ export class CycleStore implements ICycleStore { } catch (error) { console.log("Failed to add cycle to favorites in the cycles store", error); - // reset on error - const _cycleMap = set(this.cycleMap, [projectId, cycleId, "is_favorite"], false); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, cycleId, "is_favorite"], false); }); throw error; @@ -306,9 +295,8 @@ export class CycleStore implements ICycleStore { if (!currentCycle.is_favorite) return; - const _cycleMap = set(this.cycleMap, [projectId, cycleId, "is_favorite"], false); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, cycleId, "is_favorite"], false); }); const response = await this.cycleService.removeCycleFromFavorites(workspaceSlug, projectId, cycleId); @@ -317,10 +305,8 @@ export class CycleStore implements ICycleStore { } catch (error) { console.log("Failed to remove cycle from favorites - Cycle Store", error); - // reset on error - const _cycleMap = set(this.cycleMap, [projectId, cycleId, "is_favorite"], true); runInAction(() => { - this.cycleMap = _cycleMap; + set(this.cycleMap, [projectId, cycleId, "is_favorite"], true); }); throw error; diff --git a/web/store/label.store.ts b/web/store/label.store.ts index 59c6cae81..bb7a9320d 100644 --- a/web/store/label.store.ts +++ b/web/store/label.store.ts @@ -100,9 +100,8 @@ export class LabelStore { createLabel = async (workspaceSlug: string, projectId: string, data: Partial) => { const response = await this.issueLabelService.createIssueLabel(workspaceSlug, projectId, data); - const _labelMap = set(this.labelMap, [response.id], response); runInAction(() => { - this.labelMap = _labelMap; + set(this.labelMap, [response.id], response); }); return response; }; @@ -118,21 +117,16 @@ export class LabelStore { updateLabel = async (workspaceSlug: string, projectId: string, labelId: string, data: Partial) => { const originalLabel = this.labelMap[labelId]; try { - const _labelMap = set(this.labelMap, [labelId], { ...this.labelMap[labelId], ...data }); runInAction(() => { - this.labelMap = _labelMap; + set(this.labelMap, [labelId], { ...this.labelMap[labelId], ...data }); }); const response = await this.issueLabelService.patchIssueLabel(workspaceSlug, projectId, labelId, data); return response; } catch (error) { console.log("Failed to update label from project store"); - const _labelMap = set(this.labelMap, [labelId], { ...this.labelMap[labelId], ...data }); runInAction(() => { - this.labelMap = { - ...this.labelMap, - [labelId]: { ...this.labelMap[labelId], ...originalLabel }, - }; + set(this.labelMap, [labelId], originalLabel); }); throw error; } @@ -214,10 +208,10 @@ export class LabelStore { const originalLabel = this.labelMap[labelId]; try { - const _labelMap = this.labelMap; - delete _labelMap[labelId]; + if (!this.labelMap[labelId]) return; + runInAction(() => { - this.labelMap = _labelMap; + delete this.labelMap[labelId]; }); // deleting using api @@ -225,9 +219,8 @@ export class LabelStore { } catch (error) { console.log("Failed to delete label from project store"); // reverting back to original label list - const labelMap = set(this.labelMap, [labelId], originalLabel); runInAction(() => { - this.labelMap = labelMap; + set(this.labelMap, [labelId], originalLabel); }); } }; diff --git a/web/store/module.store.ts b/web/store/module.store.ts index cfd858d92..0c2f36133 100644 --- a/web/store/module.store.ts +++ b/web/store/module.store.ts @@ -139,9 +139,8 @@ export class ModulesStore implements IModuleStore { const modulesResponse = await this.moduleService.getModules(workspaceSlug, projectId); - const _moduleMap = set(this.moduleMap, [projectId], modulesResponse); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId], modulesResponse); this.loader = false; this.error = null; }); @@ -164,9 +163,8 @@ export class ModulesStore implements IModuleStore { const response = await this.moduleService.getModuleDetails(workspaceSlug, projectId, moduleId); - const _moduleMap = set(this.moduleMap, [projectId, moduleId], response); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId], response); this.loader = false; this.error = null; }); @@ -188,9 +186,8 @@ export class ModulesStore implements IModuleStore { try { const response = await this.moduleService.createModule(workspaceSlug, projectId, data); - const _moduleMap = set(this.moduleMap, [projectId, response?.id], response); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, response?.id], response); this.loader = false; this.error = null; }); @@ -212,9 +209,8 @@ export class ModulesStore implements IModuleStore { try { const currentModule = this.moduleMap[projectId][moduleId]; - const _moduleMap = set(this.moduleMap, [projectId, moduleId], { ...currentModule, ...data }); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId], { ...currentModule, ...data }); }); const response = await this.moduleService.patchModule(workspaceSlug, projectId, moduleId, data); @@ -236,12 +232,10 @@ export class ModulesStore implements IModuleStore { deleteModule = async (workspaceSlug: string, projectId: string, moduleId: string) => { try { - const currentProjectModules = this.moduleMap[projectId]; - delete currentProjectModules[moduleId]; + if (!this.moduleMap?.[projectId]?.[moduleId]) return; - const _moduleMap = set(this.moduleMap, [projectId], currentProjectModules); runInAction(() => { - this.moduleMap = _moduleMap; + delete this.moduleMap[projectId][moduleId]; }); await this.moduleService.deleteModule(workspaceSlug, projectId, moduleId); @@ -267,13 +261,8 @@ export class ModulesStore implements IModuleStore { const currentModule = this.moduleMap[projectId][moduleId]; - const _moduleMap = set( - this.moduleMap, - [projectId, moduleId, "link_module"], - [response, ...currentModule.link_module] - ); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "link_module"], [response, ...currentModule.link_module]); }); return response; @@ -304,9 +293,8 @@ export class ModulesStore implements IModuleStore { const currentModule = this.moduleMap[projectId][moduleId]; const linkModules = currentModule.link_module.map((link) => (link.id === linkId ? response : link)); - const _moduleMap = set(this.moduleMap, [projectId, moduleId, "link_module"], linkModules); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "link_module"], linkModules); }); return response; @@ -329,9 +317,8 @@ export class ModulesStore implements IModuleStore { const currentModule = this.moduleMap[projectId][moduleId]; const linkModules = currentModule.link_module.filter((link) => link.id !== linkId); - const _moduleMap = set(this.moduleMap, [projectId, moduleId, "link_module"], linkModules); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "link_module"], linkModules); }); await this.moduleService.deleteModuleLink(workspaceSlug, projectId, moduleId, linkId); @@ -355,9 +342,8 @@ export class ModulesStore implements IModuleStore { if (currentModule.is_favorite) return; - const _moduleMap = set(this.moduleMap, [projectId, moduleId, "is_favorite"], true); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "is_favorite"], true); }); await this.moduleService.addModuleToFavorites(workspaceSlug, projectId, { @@ -366,9 +352,8 @@ export class ModulesStore implements IModuleStore { } catch (error) { console.error("Failed to add module to favorites in module store", error); - const _moduleMap = set(this.moduleMap, [projectId, moduleId, "is_favorite"], false); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "is_favorite"], false); }); } }; @@ -379,18 +364,16 @@ export class ModulesStore implements IModuleStore { if (!currentModule.is_favorite) return; - const _moduleMap = set(this.moduleMap, [projectId, moduleId, "is_favorite"], false); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "is_favorite"], false); }); await this.moduleService.removeModuleFromFavorites(workspaceSlug, projectId, moduleId); } catch (error) { console.error("Failed to remove module from favorites in module store", error); - const _moduleMap = set(this.moduleMap, [projectId, moduleId, "is_favorite"], true); runInAction(() => { - this.moduleMap = _moduleMap; + set(this.moduleMap, [projectId, moduleId, "is_favorite"], true); }); } }; diff --git a/web/store/page.store.ts b/web/store/page.store.ts index 8d61e2033..04261f14f 100644 --- a/web/store/page.store.ts +++ b/web/store/page.store.ts @@ -238,7 +238,7 @@ export class PageStore { createPage = async (workspaceSlug: string, projectId: string, data: Partial) => { const response = await this.pageService.createPage(workspaceSlug, projectId, data); runInAction(() => { - this.pages = set(this.pages, [response.id], response); + set(this.pages, [response.id], response); }); }; @@ -277,7 +277,7 @@ export class PageStore { try { const response = await this.pageService.deletePage(workspaceSlug, projectId, pageId); runInAction(() => { - this.archivedPages = set(this.archivedPages, [pageId], this.pages[pageId]); + set(this.archivedPages, [pageId], this.pages[pageId]); delete this.pages[pageId]; }); return response; diff --git a/web/store/project-view.store.ts b/web/store/project-view.store.ts index b9a1cd199..796e20ffd 100644 --- a/web/store/project-view.store.ts +++ b/web/store/project-view.store.ts @@ -90,10 +90,9 @@ export class ProjectViewsStore implements IProjectViewsStore { const response = await this.viewService.getViews(workspaceSlug, projectId); - const _viewMap = set(this.viewMap, [projectId], response); runInAction(() => { this.loader = false; - this.viewMap = _viewMap; + set(this.viewMap, [projectId], response); }); return response; @@ -115,10 +114,9 @@ export class ProjectViewsStore implements IProjectViewsStore { const response = await this.viewService.getViewDetails(workspaceSlug, projectId, viewId); - const _viewMap = set(this.viewMap, [projectId, viewId], response); runInAction(() => { this.loader = false; - this.viewMap = _viewMap; + set(this.viewMap, [projectId, viewId], response); }); return response; @@ -136,10 +134,9 @@ export class ProjectViewsStore implements IProjectViewsStore { try { const response = await this.viewService.createView(workspaceSlug, projectId, data); - const _viewMap = set(this.viewMap, [projectId, response.id], response); runInAction(() => { this.loader = false; - this.viewMap = _viewMap; + set(this.viewMap, [projectId, response.id], response); }); return response; @@ -161,9 +158,8 @@ export class ProjectViewsStore implements IProjectViewsStore { try { const currentView = this.viewMap[projectId][viewId]; - const _viewMap = set(this.viewMap, [projectId, viewId], { ...currentView, ...data }); runInAction(() => { - this.viewMap = _viewMap; + set(this.viewMap, [projectId, viewId], { ...currentView, ...data }); }); const response = await this.viewService.patchView(workspaceSlug, projectId, viewId, data); @@ -182,12 +178,10 @@ export class ProjectViewsStore implements IProjectViewsStore { deleteView = async (workspaceSlug: string, projectId: string, viewId: string): Promise => { try { - const currentProjectViews = this.viewMap[projectId]; - delete currentProjectViews[viewId]; + if (!this.viewMap?.[projectId]?.[viewId]) return; - const _viewMap = set(this.viewMap, [projectId], currentProjectViews); runInAction(() => { - this.viewMap = _viewMap; + delete this.viewMap[projectId][viewId]; }); await this.viewService.deleteView(workspaceSlug, projectId, viewId); @@ -208,9 +202,8 @@ export class ProjectViewsStore implements IProjectViewsStore { if (currentView.is_favorite) return; - const _viewMap = set(this.viewMap, [projectId, viewId, "is_favorite"], true); runInAction(() => { - this.viewMap = _viewMap; + set(this.viewMap, [projectId, viewId, "is_favorite"], true); }); await this.viewService.addViewToFavorites(workspaceSlug, projectId, { @@ -219,9 +212,8 @@ export class ProjectViewsStore implements IProjectViewsStore { } catch (error) { console.error("Failed to add view to favorites in view store", error); - const _viewMap = set(this.viewMap, [projectId, viewId, "is_favorite"], false); runInAction(() => { - this.viewMap = _viewMap; + set(this.viewMap, [projectId, viewId, "is_favorite"], false); }); } }; @@ -232,18 +224,16 @@ export class ProjectViewsStore implements IProjectViewsStore { if (!currentView.is_favorite) return; - const _viewMap = set(this.viewMap, [projectId, viewId, "is_favorite"], false); runInAction(() => { - this.viewMap = _viewMap; + set(this.viewMap, [projectId, viewId, "is_favorite"], false); }); await this.viewService.removeViewFromFavorites(workspaceSlug, projectId, viewId); } catch (error) { console.error("Failed to remove view from favorites in view store", error); - const _viewMap = set(this.viewMap, [projectId, viewId, "is_favorite"], true); runInAction(() => { - this.viewMap = _viewMap; + set(this.viewMap, [projectId, viewId, "is_favorite"], true); }); } }; diff --git a/web/store/project/project-publish.store.ts b/web/store/project/project-publish.store.ts index 4cc420482..7f39a697b 100644 --- a/web/store/project/project-publish.store.ts +++ b/web/store/project/project-publish.store.ts @@ -148,14 +148,9 @@ export class ProjectPublishStore implements IProjectPublishStore { project: response?.project || null, }; - const _projectMap = set( - this.projectRootStore.projects.projectMap, - [workspaceSlug, projectId, "is_deployed"], - true - ); runInAction(() => { this.projectPublishSettings = _projectPublishSettings; - this.projectRootStore.projects.projectMap = _projectMap; + set(this.projectRootStore.projects.projectMap, [workspaceSlug, projectId, "is_deployed"], true); this.generalLoader = false; this.error = null; }); @@ -233,14 +228,9 @@ export class ProjectPublishStore implements IProjectPublishStore { projectPublishId ); - const _projectMap = set( - this.projectRootStore.projects.projectMap, - [workspaceSlug, projectId, "is_deployed"], - false - ); runInAction(() => { this.projectPublishSettings = "not-initialized"; - this.projectRootStore.projects.projectMap = _projectMap; + set(this.projectRootStore.projects.projectMap, [workspaceSlug, projectId, "is_deployed"], false); this.generalLoader = false; this.error = null; }); diff --git a/web/store/project/projects.store.ts b/web/store/project/projects.store.ts index 7710e5d22..04802a048 100644 --- a/web/store/project/projects.store.ts +++ b/web/store/project/projects.store.ts @@ -164,9 +164,8 @@ export class ProjectsStore implements IProjectsStore { try { const currentProjectMap = await this.projectService.getProjects(workspaceSlug); - const _projectMap = set(this.projectMap, [workspaceSlug], currentProjectMap); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug], currentProjectMap); }); } catch (error) { console.log("Failed to fetch project from workspace store"); @@ -178,9 +177,8 @@ export class ProjectsStore implements IProjectsStore { try { const response = await this.projectService.getProject(workspaceSlug, projectId); - const _projectMap = set(this.projectMap, [workspaceSlug, projectId], response); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId], response); }); return response; } catch (error) { @@ -203,9 +201,8 @@ export class ProjectsStore implements IProjectsStore { if (currentProject.is_favorite) return; - const _projectMap = set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], true); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], true); }); const response = await this.projectService.addProjectToFavorites(workspaceSlug, projectId); @@ -213,9 +210,8 @@ export class ProjectsStore implements IProjectsStore { } catch (error) { console.log("Failed to add project to favorite"); - const _projectMap = set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], false); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], false); }); throw error; @@ -228,9 +224,8 @@ export class ProjectsStore implements IProjectsStore { if (!currentProject.is_favorite) return; - const _projectMap = set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], false); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], false); }); const response = await this.projectService.removeProjectFromFavorites(workspaceSlug, projectId); @@ -239,9 +234,8 @@ export class ProjectsStore implements IProjectsStore { } catch (error) { console.log("Failed to add project to favorite"); - const _projectMap = set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], true); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId, "is_favorite"], true); }); throw error; } @@ -268,9 +262,8 @@ export class ProjectsStore implements IProjectsStore { updatedSortOrder = (destinationSortingOrder + relativeDestinationSortingOrder) / 2; } - const _projectMap = set(this.projectMap, [workspaceSlug, projectId, "sort_order"], updatedSortOrder); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId, "sort_order"], updatedSortOrder); }); return updatedSortOrder; @@ -296,9 +289,8 @@ export class ProjectsStore implements IProjectsStore { try { const response = await this.projectService.createProject(workspaceSlug, data); - const _projectMap = set(this.projectMap, [workspaceSlug, response.id], response); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, response.id], response); }); return response; @@ -312,9 +304,8 @@ export class ProjectsStore implements IProjectsStore { try { const currentProject = this.projectMap?.[workspaceSlug]?.[projectId]; - const _projectMap = set(this.projectMap, [workspaceSlug, projectId], { ...currentProject, ...data }); runInAction(() => { - this.projectMap = _projectMap; + set(this.projectMap, [workspaceSlug, projectId], { ...currentProject, ...data }); }); const response = await this.projectService.updateProject(workspaceSlug, projectId, data); @@ -330,13 +321,10 @@ export class ProjectsStore implements IProjectsStore { deleteProject = async (workspaceSlug: string, projectId: string) => { try { - const workspaceProjects = { ...this.projectMap[workspaceSlug] }; + if (!this.projectMap?.[workspaceSlug]?.[projectId]) return; - delete workspaceProjects[projectId]; - - const _projectMap = set(this.projectMap, [workspaceSlug], workspaceProjects); runInAction(() => { - this.projectMap = _projectMap; + delete this.projectMap[workspaceSlug][projectId]; }); await this.projectService.deleteProject(workspaceSlug, projectId); diff --git a/web/store/state.store.ts b/web/store/state.store.ts index ea6320a01..f2b22ba10 100644 --- a/web/store/state.store.ts +++ b/web/store/state.store.ts @@ -91,9 +91,8 @@ export class StateStore implements IStateStore { createState = async (workspaceSlug: string, projectId: string, data: Partial) => { const response = await this.stateService.createState(workspaceSlug, projectId, data); - const _stateMap = set(this.stateMap, [response?.id], response); runInAction(() => { - this.stateMap = _stateMap; + set(this.stateMap, [response?.id], response); }); return response; }; @@ -109,9 +108,8 @@ export class StateStore implements IStateStore { updateState = async (workspaceSlug: string, projectId: string, stateId: string, data: Partial) => { const originalState = this.stateMap[stateId]; try { - const _stateMap = set(this.stateMap, [stateId], { ...this.stateMap?.[stateId], ...data }); runInAction(() => { - this.stateMap = _stateMap; + set(this.stateMap, [stateId], { ...this.stateMap?.[stateId], ...data }); }); const response = await this.stateService.patchState(workspaceSlug, projectId, stateId, data); return response; @@ -135,12 +133,12 @@ export class StateStore implements IStateStore { deleteState = async (workspaceSlug: string, projectId: string, stateId: string) => { const originalStates = this.stateMap; try { - const _stateMap = this.stateMap; - delete this.stateMap[stateId]; + if (!this.stateMap?.[stateId]) return; runInAction(() => { - this.stateMap = _stateMap; + delete this.stateMap[stateId]; }); + await this.stateService.deleteState(workspaceSlug, projectId, stateId); } catch (error) { runInAction(() => { @@ -159,9 +157,8 @@ export class StateStore implements IStateStore { markStateAsDefault = async (workspaceSlug: string, projectId: string, stateId: string) => { const originalStates = this.stateMap; try { - const _stateMap = set(this.stateMap, [stateId, "default"], true); runInAction(() => { - this.stateMap = _stateMap; + set(this.stateMap, [stateId, "default"], true); }); await this.stateService.markDefault(workspaceSlug, projectId, stateId); @@ -204,9 +201,8 @@ export class StateStore implements IStateStore { else newSequence = (groupStates[groupIndex + 2].sequence + groupStates[groupIndex + 1].sequence) / 2; } - const _stateMap = set(this.stateMap, [stateId, "sequence"], newSequence); runInAction(() => { - this.stateMap = _stateMap; + set(this.stateMap, [stateId, "sequence"], newSequence); }); // updating using api diff --git a/web/store/workspace/index.ts b/web/store/workspace/index.ts index d8ee12546..fd70de19c 100644 --- a/web/store/workspace/index.ts +++ b/web/store/workspace/index.ts @@ -158,12 +158,10 @@ export class WorkspaceRootStore implements IWorkspaceRootStore { const response = await this.workspaceService.createWorkspace(data); - const updatedWorkspacesList = set(this.workspaces, response.id, response); - runInAction(() => { this.loader = false; this.error = null; - this.workspaces = updatedWorkspacesList; + set(this.workspaces, response.id, response); }); return response; @@ -191,12 +189,10 @@ export class WorkspaceRootStore implements IWorkspaceRootStore { const response = await this.workspaceService.updateWorkspace(workspaceSlug, data); - const updatedWorkspacesList = set(this.workspaces, response.id, data); - runInAction(() => { this.loader = false; this.error = null; - this.workspaces = updatedWorkspacesList; + set(this.workspaces, response.id, data); }); return response; @@ -216,22 +212,16 @@ export class WorkspaceRootStore implements IWorkspaceRootStore { */ deleteWorkspace = async (workspaceSlug: string) => { try { - runInAction(() => { - this.loader = true; - this.error = null; - }); - await this.workspaceService.deleteWorkspace(workspaceSlug); const updatedWorkspacesList = this.workspaces; const workspaceId = this.getWorkspaceBySlug(workspaceSlug)?.id; - delete updatedWorkspacesList[`${workspaceId}`]; - + if (!this.workspaces?.[workspaceId]) return; runInAction(() => { this.loader = false; this.error = null; - this.workspaces = updatedWorkspacesList; + delete updatedWorkspacesList[workspaceId]; }); } catch (error) { runInAction(() => {