2023-12-07 12:43:27 +00:00
|
|
|
import { FC, Fragment, ReactNode, useCallback, 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
|
|
|
// 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
|
2023-12-07 12:43:27 +00:00
|
|
|
import { IssueView } from "components/issues";
|
2023-11-03 14:50:05 +00:00
|
|
|
// helpers
|
|
|
|
import { copyUrlToClipboard } from "helpers/string.helper";
|
2023-11-29 08:55:57 +00:00
|
|
|
// types
|
2023-12-11 16:56:29 +00:00
|
|
|
import { IIssue, IIssueLink } from "types";
|
2023-12-18 06:44:57 +00:00
|
|
|
import { EIssueActions } from "../issue-layouts/types";
|
2023-12-07 12:43:27 +00:00
|
|
|
// constants
|
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;
|
2023-12-18 06:44:57 +00:00
|
|
|
handleIssue: (issue: Partial<IIssue>, action: EIssueActions) => Promise<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 {
|
2023-12-07 12:43:27 +00:00
|
|
|
issueDetail: {
|
|
|
|
createIssueComment,
|
|
|
|
updateIssueComment,
|
|
|
|
removeIssueComment,
|
|
|
|
creationIssueCommentReaction,
|
|
|
|
removeIssueCommentReaction,
|
|
|
|
createIssueReaction,
|
|
|
|
removeIssueReaction,
|
|
|
|
createIssueSubscription,
|
|
|
|
removeIssueSubscription,
|
2023-12-11 16:56:29 +00:00
|
|
|
createIssueLink,
|
|
|
|
updateIssueLink,
|
|
|
|
deleteIssueLink,
|
2023-12-07 12:43:27 +00:00
|
|
|
getIssue,
|
|
|
|
loader,
|
|
|
|
fetchPeekIssueDetails,
|
|
|
|
setPeekId,
|
|
|
|
fetchIssueActivity,
|
|
|
|
},
|
|
|
|
archivedIssueDetail: {
|
|
|
|
getIssue: getArchivedIssue,
|
|
|
|
loader: archivedIssueLoader,
|
|
|
|
fetchPeekIssueDetails: fetchArchivedPeekIssueDetails,
|
|
|
|
},
|
|
|
|
archivedIssues: { deleteArchivedIssue },
|
|
|
|
project: { currentProjectDetails },
|
2023-12-18 09:17:40 +00:00
|
|
|
workspaceMember: { currentWorkspaceUserProjectsRole },
|
2023-11-29 08:55:57 +00:00
|
|
|
} = useMobxStore();
|
2023-11-03 14:50:05 +00:00
|
|
|
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const fetchIssueDetail = useCallback(async () => {
|
2023-12-06 14:28:47 +00:00
|
|
|
if (workspaceSlug && projectId && peekIssueId) {
|
2023-12-07 12:43:27 +00:00
|
|
|
if (isArchived) await fetchArchivedPeekIssueDetails(workspaceSlug, projectId, peekIssueId as string);
|
|
|
|
else await fetchPeekIssueDetails(workspaceSlug, projectId, peekIssueId as string);
|
2023-11-03 14:50:05 +00:00
|
|
|
}
|
2023-12-07 12:43:27 +00:00
|
|
|
}, [fetchArchivedPeekIssueDetails, fetchPeekIssueDetails, workspaceSlug, projectId, peekIssueId, isArchived]);
|
2023-12-06 14:28:47 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchIssueDetail();
|
2023-12-07 12:43:27 +00:00
|
|
|
}, [workspaceSlug, projectId, peekIssueId, fetchIssueDetail]);
|
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}`,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issue = isArchived ? getArchivedIssue : getIssue;
|
|
|
|
const isLoading = isArchived ? archivedIssueLoader : loader;
|
2023-10-18 14:28:05 +00:00
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueUpdate = async (_data: Partial<IIssue>) => {
|
|
|
|
if (handleIssue) {
|
2023-12-18 06:44:57 +00:00
|
|
|
await handleIssue(_data, EIssueActions.UPDATE);
|
2023-12-07 12:43:27 +00:00
|
|
|
fetchIssueActivity(workspaceSlug, projectId, issueId);
|
|
|
|
}
|
2023-10-18 14:28:05 +00:00
|
|
|
};
|
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueReactionCreate = (reaction: string) => createIssueReaction(workspaceSlug, projectId, issueId, reaction);
|
2023-10-20 07:03:39 +00:00
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueReactionRemove = (reaction: string) => removeIssueReaction(workspaceSlug, projectId, issueId, reaction);
|
2023-10-20 12:25:20 +00:00
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueCommentCreate = (comment: any) => createIssueComment(workspaceSlug, projectId, issueId, comment);
|
2023-10-20 12:25:20 +00:00
|
|
|
|
|
|
|
const issueCommentUpdate = (comment: any) =>
|
2023-12-07 12:43:27 +00:00
|
|
|
updateIssueComment(workspaceSlug, projectId, issueId, comment?.id, comment);
|
2023-10-20 12:25:20 +00:00
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueCommentRemove = (commentId: string) => removeIssueComment(workspaceSlug, projectId, issueId, commentId);
|
2023-10-20 12:25:20 +00:00
|
|
|
|
|
|
|
const issueCommentReactionCreate = (commentId: string, reaction: string) =>
|
2023-12-07 12:43:27 +00:00
|
|
|
creationIssueCommentReaction(workspaceSlug, projectId, issueId, commentId, reaction);
|
2023-10-20 12:25:20 +00:00
|
|
|
|
|
|
|
const issueCommentReactionRemove = (commentId: string, reaction: string) =>
|
2023-12-07 12:43:27 +00:00
|
|
|
removeIssueCommentReaction(workspaceSlug, projectId, issueId, commentId, reaction);
|
2023-10-20 07:03:39 +00:00
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueSubscriptionCreate = () => createIssueSubscription(workspaceSlug, projectId, issueId);
|
2023-11-01 08:52:29 +00:00
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
const issueSubscriptionRemove = () => removeIssueSubscription(workspaceSlug, projectId, issueId);
|
2023-11-01 08:52:29 +00:00
|
|
|
|
2023-12-11 16:56:29 +00:00
|
|
|
const issueLinkCreate = (formData: IIssueLink) => createIssueLink(workspaceSlug, projectId, issueId, formData);
|
|
|
|
|
|
|
|
const issueLinkUpdate = (formData: IIssueLink, linkId: string) =>
|
|
|
|
updateIssueLink(workspaceSlug, projectId, issueId, linkId, formData);
|
|
|
|
|
|
|
|
const issueLinkDelete = (linkId: string) => deleteIssueLink(workspaceSlug, projectId, issueId, linkId);
|
|
|
|
|
2023-11-03 14:50:05 +00:00
|
|
|
const handleDeleteIssue = async () => {
|
2023-12-07 12:43:27 +00:00
|
|
|
if (isArchived) await deleteArchivedIssue(workspaceSlug, projectId, issue!);
|
2023-12-18 06:44:57 +00:00
|
|
|
else await handleIssue(issue!, EIssueActions.DELETE);
|
2023-11-03 14:50:05 +00:00
|
|
|
const { query } = router;
|
|
|
|
if (query.peekIssueId) {
|
2023-12-07 12:43:27 +00:00
|
|
|
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-18 09:17:40 +00:00
|
|
|
const userRole =
|
|
|
|
(currentWorkspaceUserProjectsRole && currentWorkspaceUserProjectsRole[projectId]) ?? 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}
|
2023-12-11 16:56:29 +00:00
|
|
|
issueLinkCreate={issueLinkCreate}
|
|
|
|
issueLinkUpdate={issueLinkUpdate}
|
|
|
|
issueLinkDelete={issueLinkDelete}
|
2023-11-06 08:22:33 +00:00
|
|
|
handleDeleteIssue={handleDeleteIssue}
|
|
|
|
disableUserActions={[5, 10].includes(userRole)}
|
2023-12-07 12:43:27 +00:00
|
|
|
showCommentAccessSpecifier={currentProjectDetails?.is_deployed}
|
2023-11-06 08:22:33 +00:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</IssueView>
|
|
|
|
</Fragment>
|
2023-10-18 14:28:05 +00:00
|
|
|
);
|
|
|
|
});
|