Files
plane/web/core/services/workspace-notification.service.ts
guru_sainath 209dc57307 [WEB-1764] chore: revamp workspace notifications (#4947)
* chore: Initialised store and updated the components

* chore: updated store and types

* chore: updated notifications in the side and updated store

* chore: handled notification center

* chore: updates store request

* chore: notifications filter changed

* chore: updated filter logic and handled bulk read

* chore: handled filter dropdown

* chore: handled ui

* chore: resolved build error

* chore: implemented applied filters

* chore: removed old notifications

* chore: added redirection from sidebar

* chore: updated notification as read when we see the notification preview

* chore: updated read and unread validation

* chore: handled custom snooze dropdown

* chore: resolved git comments

* chore: updated structure and typos

* chore: import and prop changes

* chore: updated avatar props

* chore: updated avatar

* chore: notification unread count on the app sidebar

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
2024-06-28 19:00:48 +05:30

119 lines
3.3 KiB
TypeScript

/* eslint-disable no-useless-catch */
import type {
TNotificationPaginatedInfo,
TNotificationPaginatedInfoQueryParams,
TNotification,
TUnreadNotificationsCount,
} from "@plane/types";
// helpers
import { API_BASE_URL } from "@/helpers/common.helper";
// services
import { APIService } from "@/services/api.service";
export class WorkspaceNotificationService extends APIService {
constructor() {
super(API_BASE_URL);
}
async fetchUnreadNotificationsCount(workspaceSlug: string): Promise<TUnreadNotificationsCount | undefined> {
try {
const { data } = await this.get(`/api/workspaces/${workspaceSlug}/users/notifications/unread/`);
return data || undefined;
} catch (error) {
throw error;
}
}
async fetchNotifications(
workspaceSlug: string,
params: TNotificationPaginatedInfoQueryParams
): Promise<TNotificationPaginatedInfo | undefined> {
try {
const { data } = await this.get(`/api/workspaces/${workspaceSlug}/users/notifications`, {
params,
});
return data || undefined;
} catch (error) {
throw error;
}
}
async updateNotificationById(
workspaceSlug: string,
notificationId: string,
payload: Partial<TNotification>
): Promise<TNotification | undefined> {
try {
const { data } = await this.patch(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`,
payload
);
return data || undefined;
} catch (error) {
throw error;
}
}
async markNotificationAsRead(workspaceSlug: string, notificationId: string): Promise<TNotification | undefined> {
try {
const { data } = await this.post(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`);
return data || undefined;
} catch (error) {
throw error;
}
}
async markNotificationAsUnread(workspaceSlug: string, notificationId: string): Promise<TNotification | undefined> {
try {
const { data } = await this.delete(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`
);
return data || undefined;
} catch (error) {
throw error;
}
}
async markNotificationAsArchived(workspaceSlug: string, notificationId: string): Promise<TNotification | undefined> {
try {
const { data } = await this.post(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
);
return data || undefined;
} catch (error) {
throw error;
}
}
async markNotificationAsUnArchived(
workspaceSlug: string,
notificationId: string
): Promise<TNotification | undefined> {
try {
const { data } = await this.delete(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
);
return data || undefined;
} catch (error) {
throw error;
}
}
async markAllNotificationsAsRead(
workspaceSlug: string,
payload: TNotificationPaginatedInfoQueryParams
): Promise<TNotification | undefined> {
try {
const { data } = await this.post(`/api/workspaces/${workspaceSlug}/users/notifications/mark-all-read/`, payload);
return data || undefined;
} catch (error) {
throw error;
}
}
}
const workspaceNotificationService = new WorkspaceNotificationService();
export default workspaceNotificationService;