2023-06-19 18:09:47 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-08-25 12:11:23 +00:00
|
|
|
import useSWR, { mutate } from "swr";
|
2023-06-19 18:09:47 +00:00
|
|
|
|
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
// hooks
|
|
|
|
import useUserAuth from "hooks/use-user-auth";
|
2023-08-25 12:11:23 +00:00
|
|
|
import useToast from "hooks/use-toast";
|
2023-08-29 14:44:13 +00:00
|
|
|
import useProjectDetails from "hooks/use-project-details";
|
2023-06-19 18:09:47 +00:00
|
|
|
// contexts
|
|
|
|
import { useProjectMyMembership } from "contexts/project-member.context";
|
|
|
|
// components
|
|
|
|
import {
|
|
|
|
AddComment,
|
|
|
|
IssueActivitySection,
|
|
|
|
IssueAttachmentUpload,
|
|
|
|
IssueAttachments,
|
|
|
|
IssueDescriptionForm,
|
2023-07-27 13:25:03 +00:00
|
|
|
IssueReaction,
|
2023-06-19 18:09:47 +00:00
|
|
|
} from "components/issues";
|
2023-09-21 10:09:45 +00:00
|
|
|
import { SubIssuesRoot } from "./sub-issues";
|
2023-06-19 18:09:47 +00:00
|
|
|
// ui
|
|
|
|
import { CustomMenu } from "components/ui";
|
2023-07-31 06:15:10 +00:00
|
|
|
// icons
|
|
|
|
import { LayerDiagonalIcon } from "components/icons";
|
|
|
|
import { MinusCircleIcon } from "@heroicons/react/24/outline";
|
2023-06-19 18:09:47 +00:00
|
|
|
// types
|
2023-08-25 12:11:23 +00:00
|
|
|
import { IIssue, IIssueComment } from "types";
|
2023-06-19 18:09:47 +00:00
|
|
|
// fetch-keys
|
2023-08-25 12:11:23 +00:00
|
|
|
import { PROJECT_ISSUES_ACTIVITY, SUB_ISSUES } from "constants/fetch-keys";
|
2023-06-19 18:09:47 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issueDetails: IIssue;
|
|
|
|
submitChanges: (formData: Partial<IIssue>) => Promise<void>;
|
2023-07-13 11:34:24 +00:00
|
|
|
uneditable?: boolean;
|
2023-06-19 18:09:47 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 06:04:37 +00:00
|
|
|
export const IssueMainContent: React.FC<Props> = ({
|
|
|
|
issueDetails,
|
|
|
|
submitChanges,
|
2023-07-13 11:34:24 +00:00
|
|
|
uneditable = false,
|
2023-07-13 06:04:37 +00:00
|
|
|
}) => {
|
2023-06-19 18:09:47 +00:00
|
|
|
const router = useRouter();
|
2023-09-21 13:42:20 +00:00
|
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
2023-06-19 18:09:47 +00:00
|
|
|
|
2023-08-25 12:11:23 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2023-06-19 18:09:47 +00:00
|
|
|
const { user } = useUserAuth();
|
|
|
|
const { memberRole } = useProjectMyMembership();
|
|
|
|
|
2023-08-29 14:44:13 +00:00
|
|
|
const { projectDetails } = useProjectDetails();
|
|
|
|
|
2023-06-19 18:09:47 +00:00
|
|
|
const { data: siblingIssues } = useSWR(
|
|
|
|
workspaceSlug && projectId && issueDetails?.parent ? SUB_ISSUES(issueDetails.parent) : null,
|
|
|
|
workspaceSlug && projectId && issueDetails?.parent
|
|
|
|
? () =>
|
2023-08-25 12:11:23 +00:00
|
|
|
issuesService.subIssues(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
issueDetails.parent ?? ""
|
|
|
|
)
|
2023-06-19 18:09:47 +00:00
|
|
|
: null
|
|
|
|
);
|
2023-07-22 09:23:48 +00:00
|
|
|
const siblingIssuesList = siblingIssues?.sub_issues.filter((i) => i.id !== issueDetails.id);
|
2023-06-19 18:09:47 +00:00
|
|
|
|
2023-08-25 12:11:23 +00:00
|
|
|
const { data: issueActivity, mutate: mutateIssueActivity } = useSWR(
|
|
|
|
workspaceSlug && projectId && issueId ? PROJECT_ISSUES_ACTIVITY(issueId.toString()) : null,
|
|
|
|
workspaceSlug && projectId && issueId
|
|
|
|
? () =>
|
|
|
|
issuesService.getIssueActivities(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
projectId.toString(),
|
|
|
|
issueId.toString()
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-09-07 07:24:30 +00:00
|
|
|
const handleCommentUpdate = async (commentId: string, data: Partial<IIssueComment>) => {
|
2023-08-25 12:11:23 +00:00
|
|
|
if (!workspaceSlug || !projectId || !issueId) return;
|
|
|
|
|
|
|
|
await issuesService
|
|
|
|
.patchIssueComment(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
issueId as string,
|
2023-09-07 07:24:30 +00:00
|
|
|
commentId,
|
|
|
|
data,
|
2023-08-25 12:11:23 +00:00
|
|
|
user
|
|
|
|
)
|
|
|
|
.then(() => mutateIssueActivity());
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCommentDelete = async (commentId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId || !issueId) return;
|
|
|
|
|
|
|
|
mutateIssueActivity((prevData: any) => prevData?.filter((p: any) => p.id !== commentId), false);
|
|
|
|
|
|
|
|
await issuesService
|
|
|
|
.deleteIssueComment(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
issueId as string,
|
|
|
|
commentId,
|
|
|
|
user
|
|
|
|
)
|
|
|
|
.then(() => mutateIssueActivity());
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleAddComment = async (formData: IIssueComment) => {
|
|
|
|
if (!workspaceSlug || !issueDetails) return;
|
|
|
|
|
|
|
|
await issuesService
|
|
|
|
.createIssueComment(
|
|
|
|
workspaceSlug.toString(),
|
|
|
|
issueDetails.project,
|
|
|
|
issueDetails.id,
|
|
|
|
formData,
|
|
|
|
user
|
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
mutate(PROJECT_ISSUES_ACTIVITY(issueDetails.id));
|
|
|
|
})
|
|
|
|
.catch(() =>
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Comment could not be posted. Please try again.",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-06-19 18:09:47 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="rounded-lg">
|
2023-07-22 09:23:48 +00:00
|
|
|
{issueDetails?.parent ? (
|
2023-07-31 06:15:10 +00:00
|
|
|
<div className="mb-5 flex w-min items-center gap-3 whitespace-nowrap rounded-md bg-custom-background-80 border border-custom-border-300 py-1 px-2.5 text-xs">
|
2023-07-22 09:23:48 +00:00
|
|
|
<Link
|
|
|
|
href={`/${workspaceSlug}/projects/${issueDetails.parent_detail?.project_detail.id}/issues/${issueDetails.parent}`}
|
|
|
|
>
|
2023-07-31 06:15:10 +00:00
|
|
|
<a className="flex items-center gap-3">
|
|
|
|
<div className="flex items-center gap-2.5">
|
|
|
|
<span
|
|
|
|
className="block h-2 w-2 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: issueDetails.parent_detail?.state_detail.color,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<span className="flex-shrink-0 text-custom-text-200">
|
|
|
|
{issueDetails.parent_detail?.project_detail.identifier}-
|
|
|
|
{issueDetails.parent_detail?.sequence_id}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<span className="truncate text-custom-text-100">
|
2023-06-19 18:09:47 +00:00
|
|
|
{issueDetails.parent_detail?.name.substring(0, 50)}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
2023-10-11 06:35:53 +00:00
|
|
|
<CustomMenu ellipsis optionsClassName="px-1.5">
|
2023-07-22 09:23:48 +00:00
|
|
|
{siblingIssuesList ? (
|
|
|
|
siblingIssuesList.length > 0 ? (
|
|
|
|
<>
|
2023-07-31 06:15:10 +00:00
|
|
|
<h2 className="mb-1 text-custom-text-200 text-xs font-medium px-2 pb-1 border-b border-custom-border-300">
|
|
|
|
Sibling issues
|
|
|
|
</h2>
|
2023-07-22 09:23:48 +00:00
|
|
|
{siblingIssuesList.map((issue) => (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={issue.id}
|
|
|
|
renderAs="a"
|
2023-08-25 12:11:23 +00:00
|
|
|
href={`/${workspaceSlug}/projects/${projectId as string}/issues/${
|
|
|
|
issue.id
|
|
|
|
}`}
|
2023-07-31 06:15:10 +00:00
|
|
|
className="flex items-center gap-2 py-2"
|
2023-07-22 09:23:48 +00:00
|
|
|
>
|
2023-07-31 06:15:10 +00:00
|
|
|
<LayerDiagonalIcon className="h-4 w-4" />
|
2023-07-22 09:23:48 +00:00
|
|
|
{issueDetails.project_detail.identifier}-{issue.sequence_id}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<p className="flex items-center gap-2 whitespace-nowrap px-1 text-left text-xs text-custom-text-200 py-1">
|
|
|
|
No sibling issues
|
|
|
|
</p>
|
|
|
|
)
|
|
|
|
) : null}
|
2023-07-18 10:06:03 +00:00
|
|
|
<CustomMenu.MenuItem
|
|
|
|
renderAs="button"
|
|
|
|
onClick={() => submitChanges({ parent: null })}
|
2023-07-31 06:15:10 +00:00
|
|
|
className="flex items-center gap-2 text-red-500 py-2"
|
2023-07-18 10:06:03 +00:00
|
|
|
>
|
2023-07-31 06:15:10 +00:00
|
|
|
<MinusCircleIcon className="h-4 w-4" />
|
|
|
|
<span> Remove Parent Issue</span>
|
2023-07-18 10:06:03 +00:00
|
|
|
</CustomMenu.MenuItem>
|
2023-06-19 18:09:47 +00:00
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<IssueDescriptionForm
|
2023-08-19 13:28:54 +00:00
|
|
|
workspaceSlug={workspaceSlug as string}
|
2023-06-19 18:09:47 +00:00
|
|
|
issue={issueDetails}
|
|
|
|
handleFormSubmit={submitChanges}
|
2023-07-13 11:34:24 +00:00
|
|
|
isAllowed={memberRole.isMember || memberRole.isOwner || !uneditable}
|
2023-06-19 18:09:47 +00:00
|
|
|
/>
|
2023-07-27 13:25:03 +00:00
|
|
|
|
|
|
|
<IssueReaction workspaceSlug={workspaceSlug} issueId={issueId} projectId={projectId} />
|
|
|
|
|
2023-06-19 18:09:47 +00:00
|
|
|
<div className="mt-2 space-y-2">
|
2023-09-21 13:42:20 +00:00
|
|
|
<SubIssuesRoot parentIssue={issueDetails} user={user} />
|
2023-06-19 18:09:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-3 py-3">
|
|
|
|
<h3 className="text-lg">Attachments</h3>
|
|
|
|
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
2023-07-13 11:34:24 +00:00
|
|
|
<IssueAttachmentUpload disabled={uneditable} />
|
2023-06-19 18:09:47 +00:00
|
|
|
<IssueAttachments />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="space-y-5 pt-3">
|
2023-07-10 07:17:00 +00:00
|
|
|
<h3 className="text-lg text-custom-text-100">Comments/Activity</h3>
|
2023-07-13 06:04:37 +00:00
|
|
|
<IssueActivitySection
|
2023-08-25 12:11:23 +00:00
|
|
|
activity={issueActivity}
|
|
|
|
handleCommentUpdate={handleCommentUpdate}
|
|
|
|
handleCommentDelete={handleCommentDelete}
|
2023-09-07 07:24:30 +00:00
|
|
|
showAccessSpecifier={projectDetails && projectDetails.is_deployed}
|
2023-07-13 06:04:37 +00:00
|
|
|
/>
|
2023-08-29 14:44:13 +00:00
|
|
|
<AddComment
|
|
|
|
onSubmit={handleAddComment}
|
|
|
|
disabled={uneditable}
|
|
|
|
showAccessSpecifier={projectDetails && projectDetails.is_deployed}
|
|
|
|
/>
|
2023-06-19 18:09:47 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|