import { Bell, BellOff } from "lucide-react"; import { observer } from "mobx-react-lite"; import { FC, useState } from "react"; // UI import { Button, Loader } from "@plane/ui"; // hooks import { useIssueDetail } from "hooks/store"; import useToast from "hooks/use-toast"; import isNil from "lodash/isNil"; export type TIssueSubscription = { workspaceSlug: string; projectId: string; issueId: string; }; export const IssueSubscription: FC = observer((props) => { const { workspaceSlug, projectId, issueId } = props; // hooks const { subscription: { getSubscriptionByIssueId }, createSubscription, removeSubscription, } = useIssueDetail(); const { setToastAlert } = useToast(); // state const [loading, setLoading] = useState(false); const isSubscribed = getSubscriptionByIssueId(issueId); const handleSubscription = async () => { setLoading(true); try { if (isSubscribed) await removeSubscription(workspaceSlug, projectId, issueId); else await createSubscription(workspaceSlug, projectId, issueId); setToastAlert({ type: "success", title: `Issue ${isSubscribed ? `unsubscribed` : `subscribed`} successfully.!`, message: `Issue ${isSubscribed ? `unsubscribed` : `subscribed`} successfully.!`, }); setLoading(false); } catch (error) { setLoading(false); setToastAlert({ type: "error", title: "Error", message: "Something went wrong. Please try again later.", }); } }; if (isNil(isSubscribed)) return ( ); return (
); });