mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
86 lines
2.0 KiB
TypeScript
86 lines
2.0 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;
|
|
|
|
mutate(
|
|
{
|
|
subscribed: false,
|
|
},
|
|
false
|
|
);
|
|
|
|
userNotificationServices
|
|
.unsubscribeFromIssueNotifications(
|
|
workspaceSlug.toString(),
|
|
projectId.toString(),
|
|
issueId.toString()
|
|
)
|
|
.then(() => {
|
|
mutate({
|
|
subscribed: false,
|
|
});
|
|
});
|
|
}, [workspaceSlug, projectId, issueId, mutate]);
|
|
|
|
const handleSubscribe = useCallback(() => {
|
|
if (!workspaceSlug || !projectId || !issueId || !user) return;
|
|
|
|
mutate(
|
|
{
|
|
subscribed: true,
|
|
},
|
|
false
|
|
);
|
|
|
|
userNotificationServices
|
|
.subscribeToIssueNotifications(
|
|
workspaceSlug.toString(),
|
|
projectId.toString(),
|
|
issueId.toString()
|
|
)
|
|
.then(() => {
|
|
mutate({
|
|
subscribed: true,
|
|
});
|
|
});
|
|
}, [workspaceSlug, projectId, issueId, mutate, user]);
|
|
|
|
return {
|
|
loading: !data && !error,
|
|
subscribed: data?.subscribed,
|
|
handleSubscribe,
|
|
handleUnsubscribe,
|
|
} as const;
|
|
};
|
|
|
|
export default useUserIssueNotificationSubscription;
|