diff --git a/apps/web/core/services/sticky.service.ts b/apps/web/core/services/sticky.service.ts index ff4491e8ed6..f231130a0b8 100644 --- a/apps/web/core/services/sticky.service.ts +++ b/apps/web/core/services/sticky.service.ts @@ -43,7 +43,7 @@ export class StickyService extends APIService { } async getSticky(workspaceSlug: string, id: string) { - return this.get(`/api/workspaces/${workspaceSlug}/stickies/${id}`) + return this.get(`/api/workspaces/${workspaceSlug}/stickies/${id}/`) .then((res) => res?.data) .catch((err) => { throw err?.response?.data; @@ -59,7 +59,7 @@ export class StickyService extends APIService { } async deleteSticky(workspaceSlug: string, id: string) { - return await this.delete(`/api/workspaces/${workspaceSlug}/stickies/${id}`) + return await this.delete(`/api/workspaces/${workspaceSlug}/stickies/${id}/`) .then((res) => res?.data) .catch((err) => { throw err?.response?.data; diff --git a/apps/web/core/store/sticky/sticky.store.ts b/apps/web/core/store/sticky/sticky.store.ts index 09833214505..0b873053b03 100644 --- a/apps/web/core/store/sticky/sticky.store.ts +++ b/apps/web/core/store/sticky/sticky.store.ts @@ -205,24 +205,29 @@ export class StickyStore implements IStickyStore { } catch (error) { console.error("Error in updating sticky:", error); this.stickies[id] = sticky; - throw new Error(); + throw error; } }; deleteSticky = async (workspaceSlug: string, id: string) => { const sticky = this.stickies[id]; if (!sticky) return; + const currentWorkspaceStickies = this.workspaceStickies[workspaceSlug] || []; + const previousWorkspaceStickies = [...currentWorkspaceStickies]; + const previousActiveStickyId = this.activeStickyId; + const previousRecentStickyId = this.recentStickyId; try { - this.workspaceStickies[workspaceSlug] = this.workspaceStickies[workspaceSlug].filter( - (stickyId) => stickyId !== id - ); + this.workspaceStickies[workspaceSlug] = currentWorkspaceStickies.filter((stickyId) => stickyId !== id); if (this.activeStickyId === id) this.activeStickyId = undefined; delete this.stickies[id]; this.recentStickyId = this.workspaceStickies[workspaceSlug][0]; await this.stickyService.deleteSticky(workspaceSlug, id); - } catch (e) { - console.log(e); + } catch (error) { this.stickies[id] = sticky; + this.workspaceStickies[workspaceSlug] = previousWorkspaceStickies; + this.activeStickyId = previousActiveStickyId; + this.recentStickyId = previousRecentStickyId; + throw error; } };