plane/apps/app/services/notifications.service.ts
Dakshesh Jain 16a7bd3bda
feat: user issue notifications (#1523)
* feat: added new issue subscriber table

* dev: notification model

* feat: added CRUD operation for issue subscriber

* Revert "feat: added CRUD operation for issue subscriber"

This reverts commit b22e062576.

* feat: added CRUD operation for issue subscriber

* dev: notification models and operations

* dev: remove delete endpoint response data

* dev: notification endpoints and fix bg worker for saving notifications

* feat: added list and unsubscribe function in issue subscriber

* dev: filter by snoozed and response update for list and permissions

* dev: update issue notifications

* dev: notification  segregation

* dev: update notifications

* dev: notification filtering

* dev: add issue name in notifications

* dev: notification new endpoints

* fix: pushing local settings

* feat: notification workflow setup and made basic UI

* style: improved UX with toast alerts and other interactions

refactor: changed classnames according to new theme structure, changed all icons to material icons

* feat: showing un-read notification count

* feat: not showing 'subscribe' button on issue created by user & assigned to user

not showing 'Create by you' for view & guest of the workspace

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
2023-07-18 12:07:55 +05:30

175 lines
4.7 KiB
TypeScript

// services
import APIService from "services/api.service";
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
// types
import { IUserNotification, INotificationParams } from "types";
class UserNotificationsServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
}
async getUserNotifications(
workspaceSlug: string,
params: INotificationParams
): Promise<IUserNotification[]> {
return this.get(`/api/workspaces/${workspaceSlug}/users/notifications`, {
params,
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getUserNotificationDetailById(
workspaceSlug: string,
notificationId: string
): Promise<IUserNotification> {
return this.get(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async markUserNotificationAsRead(
workspaceSlug: string,
notificationId: string
): Promise<IUserNotification> {
return this.post(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async markUserNotificationAsUnread(
workspaceSlug: string,
notificationId: string
): Promise<IUserNotification> {
return this.delete(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/read/`
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async markUserNotificationAsArchived(
workspaceSlug: string,
notificationId: string
): Promise<IUserNotification> {
return this.post(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async markUserNotificationAsUnarchived(
workspaceSlug: string,
notificationId: string
): Promise<IUserNotification> {
return this.delete(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/archive/`
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async patchUserNotification(
workspaceSlug: string,
notificationId: string,
data: Partial<IUserNotification>
): Promise<IUserNotification> {
return this.patch(
`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`,
data
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async deleteUserNotification(workspaceSlug: string, notificationId: string): Promise<any> {
return this.delete(`/api/workspaces/${workspaceSlug}/users/notifications/${notificationId}/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async subscribeToIssueNotifications(
workspaceSlug: string,
projectId: string,
issueId: string,
data: {
subscriber: string;
}
): Promise<any> {
return this.post(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/issue-subscribers/`,
data
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getIssueNotificationSubscriptionStatus(
workspaceSlug: string,
projectId: string,
issueId: string
): Promise<{
subscribed: boolean;
}> {
return this.get(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/subscribe/`
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async unsubscribeFromIssueNotifications(
workspaceSlug: string,
projectId: string,
issueId: string
): Promise<any> {
return this.delete(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/subscribe/`
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async getUnreadNotificationsCount(workspaceSlug: string): Promise<{
created_issues: number;
my_issues: number;
watching_notifications: number;
}> {
return this.get(`/api/workspaces/${workspaceSlug}/users/notifications/unread/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}
const userNotificationServices = new UserNotificationsServices();
export default userNotificationServices;