mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
f27efb80e1
* dev: create email notification preference model * dev: intiate models * dev: user notification preferences * dev: create notification logs for the user. * dev: email notification stacking and sending logic * feat: email notification preference settings page. * dev: delete subscribers * dev: issue update ui implementation in email notification * chore: integrate email notification endpoint. * chore: remove toggle switch. * chore: added labels part * fix: refactored base design with tables * dev: email notification templates * dev: template updates * dev: update models * dev: update template for labels and new migrations * fix: profile settings preference sidebar. * dev: update preference endpoints * dev: update the schedule to 5 minutes * dev: update template with priority data * dev: update templates * chore: enable `issue subscribe` button for all users. * chore: notification handling for external api * dev: update origin request --------- Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com> Co-authored-by: LAKHAN BAHETI <lakhanbaheti9@gmail.com> Co-authored-by: Ramesh Kumar Chandra <rameshkumar2299@gmail.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { FC, useState } from "react";
|
|
import { Bell } from "lucide-react";
|
|
import { observer } from "mobx-react-lite";
|
|
// UI
|
|
import { Button } from "@plane/ui";
|
|
// hooks
|
|
import { useIssueDetail } from "hooks/store";
|
|
import useToast from "hooks/use-toast";
|
|
|
|
export type TIssueSubscription = {
|
|
workspaceSlug: string;
|
|
projectId: string;
|
|
issueId: string;
|
|
};
|
|
|
|
export const IssueSubscription: FC<TIssueSubscription> = observer((props) => {
|
|
const { workspaceSlug, projectId, issueId } = props;
|
|
// hooks
|
|
const {
|
|
subscription: { getSubscriptionByIssueId },
|
|
createSubscription,
|
|
removeSubscription,
|
|
} = useIssueDetail();
|
|
const { setToastAlert } = useToast();
|
|
// state
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const subscription = getSubscriptionByIssueId(issueId);
|
|
|
|
const handleSubscription = async () => {
|
|
setLoading(true);
|
|
try {
|
|
if (subscription?.subscribed) await removeSubscription(workspaceSlug, projectId, issueId);
|
|
else await createSubscription(workspaceSlug, projectId, issueId);
|
|
setToastAlert({
|
|
type: "success",
|
|
title: `Issue ${subscription?.subscribed ? `unsubscribed` : `subscribed`} successfully.!`,
|
|
message: `Issue ${subscription?.subscribed ? `unsubscribed` : `subscribed`} successfully.!`,
|
|
});
|
|
setLoading(false);
|
|
} catch (error) {
|
|
setLoading(false);
|
|
setToastAlert({
|
|
type: "error",
|
|
title: "Error",
|
|
message: "Something went wrong. Please try again later.",
|
|
});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<Button
|
|
size="sm"
|
|
prependIcon={<Bell className="h-3 w-3" />}
|
|
variant="outline-primary"
|
|
className="hover:!bg-custom-primary-100/20"
|
|
onClick={handleSubscription}
|
|
>
|
|
{loading ? "Loading..." : subscription?.subscribed ? "Unsubscribe" : "Subscribe"}
|
|
</Button>
|
|
</div>
|
|
);
|
|
});
|