plane/apps/app/hooks/use-issue-notification-subscription.tsx
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

77 lines
1.9 KiB
TypeScript

import { useCallback } from "react";
import useSWR from "swr";
// hooks
import useUserAuth from "hooks/use-user-auth";
// services
import userNotificationServices from "services/notifications.service";
const useUserIssueNotificationSubscription = (
workspaceSlug?: string | string[] | null,
projectId?: string | string[] | null,
issueId?: string | string[] | null
) => {
const { user } = useUserAuth();
const { data, error, mutate } = useSWR(
workspaceSlug && projectId && issueId
? `SUBSCRIPTION_STATUE_${workspaceSlug}_${projectId}_${issueId}`
: null,
workspaceSlug && projectId && issueId
? () =>
userNotificationServices.getIssueNotificationSubscriptionStatus(
workspaceSlug.toString(),
projectId.toString(),
issueId.toString()
)
: null
);
const handleUnsubscribe = useCallback(() => {
if (!workspaceSlug || !projectId || !issueId) return;
userNotificationServices
.unsubscribeFromIssueNotifications(
workspaceSlug as string,
projectId as string,
issueId as string
)
.then(() => {
mutate({
subscribed: false,
});
});
}, [workspaceSlug, projectId, issueId, mutate]);
const handleSubscribe = useCallback(() => {
console.log(workspaceSlug, projectId, issueId, user);
if (!workspaceSlug || !projectId || !issueId || !user) return;
userNotificationServices
.subscribeToIssueNotifications(
workspaceSlug as string,
projectId as string,
issueId as string,
{
subscriber: user.id,
}
)
.then(() => {
mutate({
subscribed: true,
});
});
}, [workspaceSlug, projectId, issueId, mutate, user]);
return {
loading: !data && !error,
subscribed: data?.subscribed,
handleSubscribe,
handleUnsubscribe,
} as const;
};
export default useUserIssueNotificationSubscription;