refactor: migrate services (dashboard) from apps/web to @plane/services

This commit is contained in:
Rahulcheryala
2026-06-04 17:38:01 +05:30
parent f266e80556
commit bffa52c974
3 changed files with 4 additions and 65 deletions

View File

@@ -1,59 +0,0 @@
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
import { API_BASE_URL } from "@plane/constants";
import type { THomeDashboardResponse, TWidget, TWidgetStatsResponse, TWidgetStatsRequestParams } from "@plane/types";
import { APIService } from "@/services/api.service";
// helpers
// types
export class DashboardService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getHomeDashboardWidgets(workspaceSlug: string): Promise<THomeDashboardResponse> {
return this.get(`/api/workspaces/${workspaceSlug}/dashboard/`, {
params: {
dashboard_type: "home",
},
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getWidgetStats(
workspaceSlug: string,
dashboardId: string,
params: TWidgetStatsRequestParams
): Promise<TWidgetStatsResponse> {
return this.get(`/api/workspaces/${workspaceSlug}/dashboard/${dashboardId}/`, {
params,
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getDashboardDetails(dashboardId: string): Promise<TWidgetStatsResponse> {
return this.get(`/api/dashboard/${dashboardId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async updateDashboardWidget(dashboardId: string, widgetId: string, data: Partial<TWidget>): Promise<TWidget> {
return this.patch(`/api/dashboard/${dashboardId}/widgets/${widgetId}/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View File

@@ -17,7 +17,7 @@ import type {
TWidgetStatsRequestParams,
} from "@plane/types";
// services
import { DashboardService } from "@/services/dashboard.service";
import { DashboardService } from "@plane/services";
// plane web store
import type { CoreRootStore } from "./root.store";
@@ -156,7 +156,7 @@ export class DashboardStore implements IDashboardStore {
*/
fetchHomeDashboardWidgets = async (workspaceSlug: string): Promise<THomeDashboardResponse> => {
try {
const response = await this.dashboardService.getHomeDashboardWidgets(workspaceSlug);
const response = await this.dashboardService.getHomeWidgets(workspaceSlug);
runInAction(() => {
this.homeDashboardId = response.dashboard.id;
@@ -228,7 +228,7 @@ export class DashboardStore implements IDashboardStore {
...data,
};
});
const response = await this.dashboardService.updateDashboardWidget(dashboardId, widgetId, data);
const response = await this.dashboardService.updateWidget(dashboardId, widgetId, data);
return response;
} catch (error) {
// revert changes

View File

@@ -8,7 +8,7 @@ import { API_BASE_URL } from "@plane/constants";
import type { THomeDashboardResponse, TWidget, TWidgetStatsResponse, TWidgetStatsRequestParams } from "@plane/types";
import { APIService } from "../api.service";
export default class DashboardService extends APIService {
export class DashboardService extends APIService {
constructor(BASE_URL?: string) {
super(BASE_URL || API_BASE_URL);
}
@@ -83,5 +83,3 @@ export default class DashboardService extends APIService {
});
}
}
export { DashboardService };