2023-12-06 14:28:47 +00:00
|
|
|
import { FC, Fragment, ReactNode, useEffect } from "react";
|
2023-11-03 14:50:05 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-10-18 14:28:05 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-29 08:55:57 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
// mobx store
|
2023-10-18 14:28:05 +00:00
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-11-03 14:50:05 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
2023-11-29 08:55:57 +00:00
|
|
|
// components
|
|
|
|
import { IssueView } from "./view";
|
2023-11-03 14:50:05 +00:00
|
|
|
// helpers
|
|
|
|
import { copyUrlToClipboard } from "helpers/string.helper";
|
2023-11-29 08:55:57 +00:00
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
2023-12-04 14:33:23 +00:00
|
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
2023-10-18 14:28:05 +00:00
|
|
|
|
|
|
|
interface IIssuePeekOverview {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
issueId: string;
|
|
|
|
handleIssue: (issue: Partial<IIssue>) => void;
|
2023-11-03 14:50:05 +00:00
|
|
|
isArchived?: boolean;
|
2023-11-03 11:50:14 +00:00
|
|
|
children?: ReactNode;
|
2023-10-18 14:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const IssuePeekOverview: FC<IIssuePeekOverview> = observer((props) => {
|
2023-11-03 14:50:05 +00:00
|
|
|
const { workspaceSlug, projectId, issueId, handleIssue, children, isArchived = false } = props;
|
|
|
|
|
|
|
|
const router = useRouter();
|
2023-11-29 08:55:57 +00:00
|
|
|
const { peekIssueId } = router.query;
|
2023-11-03 14:50:05 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
user: userStore,
|
|
|
|
issue: issueStore,
|
|
|
|
issueDetail: issueDetailStore,
|
|
|
|
archivedIssueDetail: archivedIssueDetailStore,
|
|
|
|
archivedIssues: archivedIssuesStore,
|
|
|
|
project: projectStore,
|
2023-11-29 08:55:57 +00:00
|
|
|
} = useMobxStore();
|
2023-11-03 14:50:05 +00:00
|
|
|
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-12-06 14:28:47 +00:00
|
|
|
const fetchIssueDetail = async () => {
|
|
|
|
if (workspaceSlug && projectId && peekIssueId) {
|
|
|
|
if (isArchived)
|
|
|
|
await archivedIssueDetailStore.fetchPeekIssueDetails(workspaceSlug, projectId, peekIssueId as string);
|
|
|
|
else await issueDetailStore.fetchPeekIssueDetails(workspaceSlug, projectId, peekIssueId as string);
|
2023-11-03 14:50:05 +00:00
|
|
|
}
|
2023-12-06 14:28:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchIssueDetail();
|
|
|
|
}, [workspaceSlug, projectId, peekIssueId]);
|
2023-10-18 14:28:05 +00:00
|
|
|
|
2023-11-03 14:50:05 +00:00
|
|
|
const handleCopyText = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
copyUrlToClipboard(
|
|
|
|
`${workspaceSlug}/projects/${projectId}/${isArchived ? "archived-issues" : "issues"}/${peekIssueId}`
|
|
|
|
).then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Link Copied!",
|
|
|
|
message: "Issue link copied to clipboard.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const redirectToIssueDetail = () => {
|
|
|
|
router.push({
|
|
|
|
pathname: `/${workspaceSlug}/projects/${projectId}/${isArchived ? "archived-issues" : "issues"}/${issueId}`,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const issue = isArchived ? archivedIssueDetailStore.getIssue : issueDetailStore.getIssue;
|
|
|
|
const isLoading = isArchived ? archivedIssueDetailStore.loader : issueDetailStore.loader;
|
2023-10-18 14:28:05 +00:00
|
|
|
|
|
|
|
const issueUpdate = (_data: Partial<IIssue>) => {
|
2023-11-29 08:55:57 +00:00
|
|
|
if (handleIssue) handleIssue(_data);
|
2023-10-18 14:28:05 +00:00
|
|
|
};
|
|
|
|
|
2023-10-20 12:25:20 +00:00
|
|
|
const issueReactionCreate = (reaction: string) =>
|
|
|
|
issueDetailStore.createIssueReaction(workspaceSlug, projectId, issueId, reaction);
|
2023-10-20 07:03:39 +00:00
|
|
|
|
2023-10-20 12:25:20 +00:00
|
|
|
const issueReactionRemove = (reaction: string) =>
|
|
|
|
issueDetailStore.removeIssueReaction(workspaceSlug, projectId, issueId, reaction);
|
|
|
|
|
|
|
|
const issueCommentCreate = (comment: any) =>
|
|
|
|
issueDetailStore.createIssueComment(workspaceSlug, projectId, issueId, comment);
|
|
|
|
|
|
|
|
const issueCommentUpdate = (comment: any) =>
|
|
|
|
issueDetailStore.updateIssueComment(workspaceSlug, projectId, issueId, comment?.id, comment);
|
|
|
|
|
|
|
|
const issueCommentRemove = (commentId: string) =>
|
|
|
|
issueDetailStore.removeIssueComment(workspaceSlug, projectId, issueId, commentId);
|
|
|
|
|
|
|
|
const issueCommentReactionCreate = (commentId: string, reaction: string) =>
|
2023-10-25 13:54:14 +00:00
|
|
|
issueDetailStore.creationIssueCommentReaction(workspaceSlug, projectId, issueId, commentId, reaction);
|
2023-10-20 12:25:20 +00:00
|
|
|
|
|
|
|
const issueCommentReactionRemove = (commentId: string, reaction: string) =>
|
2023-10-25 13:54:14 +00:00
|
|
|
issueDetailStore.removeIssueCommentReaction(workspaceSlug, projectId, issueId, commentId, reaction);
|
2023-10-20 07:03:39 +00:00
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
const issueSubscriptionCreate = () => issueDetailStore.createIssueSubscription(workspaceSlug, projectId, issueId);
|
|
|
|
|
|
|
|
const issueSubscriptionRemove = () => issueDetailStore.removeIssueSubscription(workspaceSlug, projectId, issueId);
|
|
|
|
|
2023-11-03 14:50:05 +00:00
|
|
|
const handleDeleteIssue = async () => {
|
|
|
|
if (isArchived) await archivedIssuesStore.deleteArchivedIssue(workspaceSlug, projectId, issue!);
|
2023-11-23 09:17:04 +00:00
|
|
|
else await issueStore.removeIssueFromStructure(workspaceSlug, projectId, issue!);
|
2023-11-03 14:50:05 +00:00
|
|
|
const { query } = router;
|
|
|
|
if (query.peekIssueId) {
|
2023-11-06 08:22:33 +00:00
|
|
|
issueDetailStore.setPeekId(null);
|
2023-11-03 14:50:05 +00:00
|
|
|
delete query.peekIssueId;
|
2023-11-29 08:55:57 +00:00
|
|
|
delete query.peekProjectId;
|
2023-11-03 14:50:05 +00:00
|
|
|
router.push({
|
|
|
|
pathname: router.pathname,
|
|
|
|
query: { ...query },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2023-11-01 08:52:29 +00:00
|
|
|
|
2023-12-04 14:33:23 +00:00
|
|
|
const userRole = userStore.currentProjectRole ?? EUserWorkspaceRoles.GUEST;
|
2023-11-03 13:43:10 +00:00
|
|
|
|
2023-10-18 14:28:05 +00:00
|
|
|
return (
|
2023-11-06 08:22:33 +00:00
|
|
|
<Fragment>
|
|
|
|
<IssueView
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
issueId={issueId}
|
|
|
|
issue={issue}
|
|
|
|
isLoading={isLoading}
|
|
|
|
isArchived={isArchived}
|
|
|
|
handleCopyText={handleCopyText}
|
|
|
|
redirectToIssueDetail={redirectToIssueDetail}
|
|
|
|
issueUpdate={issueUpdate}
|
|
|
|
issueReactionCreate={issueReactionCreate}
|
|
|
|
issueReactionRemove={issueReactionRemove}
|
|
|
|
issueCommentCreate={issueCommentCreate}
|
|
|
|
issueCommentUpdate={issueCommentUpdate}
|
|
|
|
issueCommentRemove={issueCommentRemove}
|
|
|
|
issueCommentReactionCreate={issueCommentReactionCreate}
|
|
|
|
issueCommentReactionRemove={issueCommentReactionRemove}
|
|
|
|
issueSubscriptionCreate={issueSubscriptionCreate}
|
|
|
|
issueSubscriptionRemove={issueSubscriptionRemove}
|
|
|
|
handleDeleteIssue={handleDeleteIssue}
|
|
|
|
disableUserActions={[5, 10].includes(userRole)}
|
|
|
|
showCommentAccessSpecifier={projectStore.currentProjectDetails?.is_deployed}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</IssueView>
|
|
|
|
</Fragment>
|
2023-10-18 14:28:05 +00:00
|
|
|
);
|
|
|
|
});
|