2024-01-10 14:39:45 +00:00
|
|
|
import { FC, useMemo } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// components
|
2024-01-16 07:16:03 +00:00
|
|
|
import { IssuePeekOverview } from "components/issues";
|
2024-01-10 14:39:45 +00:00
|
|
|
import { IssueMainContent } from "./main-content";
|
|
|
|
import { IssueDetailsSidebar } from "./sidebar";
|
|
|
|
// ui
|
|
|
|
import { EmptyState } from "components/common";
|
|
|
|
// images
|
|
|
|
import emptyIssue from "public/empty-state/issue.svg";
|
|
|
|
// hooks
|
2024-01-16 07:16:03 +00:00
|
|
|
import { useIssueDetail, useIssues, useUser } from "hooks/store";
|
2024-01-10 14:39:45 +00:00
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// types
|
|
|
|
import { TIssue } from "@plane/types";
|
2024-01-11 12:56:58 +00:00
|
|
|
// constants
|
|
|
|
import { EUserProjectRoles } from "constants/project";
|
2024-01-16 07:16:03 +00:00
|
|
|
import { EIssuesStoreType } from "constants/issue";
|
2024-01-10 14:39:45 +00:00
|
|
|
|
|
|
|
export type TIssueOperations = {
|
2024-01-11 12:56:58 +00:00
|
|
|
fetch: (workspaceSlug: string, projectId: string, issueId: string) => Promise<void>;
|
2024-01-16 07:16:03 +00:00
|
|
|
update: (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
data: Partial<TIssue>,
|
|
|
|
showToast?: boolean
|
|
|
|
) => Promise<void>;
|
2024-01-10 14:39:45 +00:00
|
|
|
remove: (workspaceSlug: string, projectId: string, issueId: string) => Promise<void>;
|
2024-01-24 15:03:54 +00:00
|
|
|
addIssueToCycle?: (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => Promise<void>;
|
|
|
|
removeIssueFromCycle?: (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => Promise<void>;
|
2024-01-30 09:53:20 +00:00
|
|
|
addModulesToIssue?: (workspaceSlug: string, projectId: string, issueId: string, moduleIds: string[]) => Promise<void>;
|
2024-01-24 15:03:54 +00:00
|
|
|
removeIssueFromModule?: (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
moduleId: string,
|
|
|
|
issueId: string
|
|
|
|
) => Promise<void>;
|
2024-01-30 09:53:20 +00:00
|
|
|
removeModulesFromIssue?: (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
moduleIds: string[]
|
|
|
|
) => Promise<void>;
|
2024-01-10 14:39:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type TIssueDetailRoot = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
issueId: string;
|
|
|
|
is_archived?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const IssueDetailRoot: FC<TIssueDetailRoot> = (props) => {
|
2024-01-11 12:56:58 +00:00
|
|
|
const { workspaceSlug, projectId, issueId, is_archived = false } = props;
|
2024-01-10 14:39:45 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
// hooks
|
|
|
|
const {
|
|
|
|
issue: { getIssueById },
|
2024-01-11 12:56:58 +00:00
|
|
|
fetchIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
|
|
|
addIssueToCycle,
|
|
|
|
removeIssueFromCycle,
|
2024-01-30 09:53:20 +00:00
|
|
|
addModulesToIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
removeIssueFromModule,
|
2024-01-30 09:53:20 +00:00
|
|
|
removeModulesFromIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
} = useIssueDetail();
|
2024-01-16 07:16:03 +00:00
|
|
|
const {
|
|
|
|
issues: { removeIssue: removeArchivedIssue },
|
|
|
|
} = useIssues(EIssuesStoreType.ARCHIVED);
|
2024-01-10 14:39:45 +00:00
|
|
|
const { setToastAlert } = useToast();
|
2024-01-11 12:56:58 +00:00
|
|
|
const {
|
|
|
|
membership: { currentProjectRole },
|
|
|
|
} = useUser();
|
2024-01-10 14:39:45 +00:00
|
|
|
|
|
|
|
const issueOperations: TIssueOperations = useMemo(
|
|
|
|
() => ({
|
2024-01-11 12:56:58 +00:00
|
|
|
fetch: async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
await fetchIssue(workspaceSlug, projectId, issueId);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching the parent issue");
|
|
|
|
}
|
|
|
|
},
|
2024-01-16 07:16:03 +00:00
|
|
|
update: async (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
data: Partial<TIssue>,
|
|
|
|
showToast: boolean = true
|
|
|
|
) => {
|
2024-01-10 14:39:45 +00:00
|
|
|
try {
|
|
|
|
await updateIssue(workspaceSlug, projectId, issueId, data);
|
2024-01-16 07:16:03 +00:00
|
|
|
if (showToast) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Issue updated successfully",
|
|
|
|
type: "success",
|
|
|
|
message: "Issue updated successfully",
|
|
|
|
});
|
|
|
|
}
|
2024-01-10 14:39:45 +00:00
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Issue update failed",
|
|
|
|
type: "error",
|
|
|
|
message: "Issue update failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
remove: async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
|
|
try {
|
2024-01-16 07:16:03 +00:00
|
|
|
if (is_archived) await removeArchivedIssue(workspaceSlug, projectId, issueId);
|
|
|
|
else await removeIssue(workspaceSlug, projectId, issueId);
|
2024-01-10 14:39:45 +00:00
|
|
|
setToastAlert({
|
|
|
|
title: "Issue deleted successfully",
|
|
|
|
type: "success",
|
|
|
|
message: "Issue deleted successfully",
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Issue delete failed",
|
|
|
|
type: "error",
|
|
|
|
message: "Issue delete failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addIssueToCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueIds: string[]) => {
|
|
|
|
try {
|
2024-01-27 09:50:36 +00:00
|
|
|
await addIssueToCycle(workspaceSlug, projectId, cycleId, issueIds);
|
|
|
|
setToastAlert({
|
|
|
|
title: "Cycle added to issue successfully",
|
|
|
|
type: "success",
|
|
|
|
message: "Issue added to issue successfully",
|
|
|
|
});
|
2024-01-10 14:39:45 +00:00
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Cycle add to issue failed",
|
|
|
|
type: "error",
|
|
|
|
message: "Cycle add to issue failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeIssueFromCycle: async (workspaceSlug: string, projectId: string, cycleId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
await removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueId);
|
|
|
|
setToastAlert({
|
|
|
|
title: "Cycle removed from issue successfully",
|
|
|
|
type: "success",
|
|
|
|
message: "Cycle removed from issue successfully",
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Cycle remove from issue failed",
|
|
|
|
type: "error",
|
|
|
|
message: "Cycle remove from issue failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2024-01-30 09:53:20 +00:00
|
|
|
addModulesToIssue: async (workspaceSlug: string, projectId: string, issueId: string, moduleIds: string[]) => {
|
2024-01-10 14:39:45 +00:00
|
|
|
try {
|
2024-01-30 09:53:20 +00:00
|
|
|
await addModulesToIssue(workspaceSlug, projectId, issueId, moduleIds);
|
2024-01-27 09:50:36 +00:00
|
|
|
setToastAlert({
|
|
|
|
title: "Module added to issue successfully",
|
|
|
|
type: "success",
|
|
|
|
message: "Module added to issue successfully",
|
|
|
|
});
|
2024-01-10 14:39:45 +00:00
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Module add to issue failed",
|
|
|
|
type: "error",
|
|
|
|
message: "Module add to issue failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeIssueFromModule: async (workspaceSlug: string, projectId: string, moduleId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
await removeIssueFromModule(workspaceSlug, projectId, moduleId, issueId);
|
|
|
|
setToastAlert({
|
|
|
|
title: "Module removed from issue successfully",
|
|
|
|
type: "success",
|
|
|
|
message: "Module removed from issue successfully",
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Module remove from issue failed",
|
|
|
|
type: "error",
|
|
|
|
message: "Module remove from issue failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2024-01-30 09:53:20 +00:00
|
|
|
removeModulesFromIssue: async (
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
|
|
|
issueId: string,
|
|
|
|
moduleIds: string[]
|
|
|
|
) => {
|
|
|
|
try {
|
|
|
|
await removeModulesFromIssue(workspaceSlug, projectId, issueId, moduleIds);
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
2024-01-31 10:06:55 +00:00
|
|
|
title: "Successful!",
|
|
|
|
message: "Issue removed from module successfully.",
|
2024-01-30 09:53:20 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
2024-01-31 10:06:55 +00:00
|
|
|
title: "Error!",
|
|
|
|
message: "Issue could not be removed from module. Please try again.",
|
2024-01-30 09:53:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2024-01-10 14:39:45 +00:00
|
|
|
}),
|
|
|
|
[
|
2024-01-16 07:16:03 +00:00
|
|
|
is_archived,
|
2024-01-11 12:56:58 +00:00
|
|
|
fetchIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
updateIssue,
|
|
|
|
removeIssue,
|
2024-01-16 07:16:03 +00:00
|
|
|
removeArchivedIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
addIssueToCycle,
|
|
|
|
removeIssueFromCycle,
|
2024-01-30 09:53:20 +00:00
|
|
|
addModulesToIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
removeIssueFromModule,
|
2024-01-30 09:53:20 +00:00
|
|
|
removeModulesFromIssue,
|
2024-01-10 14:39:45 +00:00
|
|
|
setToastAlert,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-01-16 07:16:03 +00:00
|
|
|
// issue details
|
2024-01-10 14:39:45 +00:00
|
|
|
const issue = getIssueById(issueId);
|
2024-01-16 07:16:03 +00:00
|
|
|
// checking if issue is editable, based on user role
|
2024-01-11 12:56:58 +00:00
|
|
|
const is_editable = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER;
|
2024-01-10 14:39:45 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{!issue ? (
|
|
|
|
<EmptyState
|
|
|
|
image={emptyIssue}
|
|
|
|
title="Issue does not exist"
|
|
|
|
description="The issue you are looking for does not exist, has been archived, or has been deleted."
|
|
|
|
primaryButton={{
|
|
|
|
text: "View other issues",
|
|
|
|
onClick: () => router.push(`/${workspaceSlug}/projects/${projectId}/issues`),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="flex h-full overflow-hidden">
|
|
|
|
<div className="h-full w-2/3 space-y-5 divide-y-2 divide-custom-border-300 overflow-y-auto p-5">
|
|
|
|
<IssueMainContent
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
issueId={issueId}
|
|
|
|
issueOperations={issueOperations}
|
2024-01-24 13:20:54 +00:00
|
|
|
is_editable={!is_archived && is_editable}
|
2024-01-10 14:39:45 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="h-full w-1/3 space-y-5 overflow-hidden border-l border-custom-border-300 py-5">
|
|
|
|
<IssueDetailsSidebar
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
issueId={issueId}
|
|
|
|
issueOperations={issueOperations}
|
|
|
|
is_archived={is_archived}
|
2024-01-24 13:20:54 +00:00
|
|
|
is_editable={!is_archived && is_editable}
|
2024-01-10 14:39:45 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2024-01-16 07:16:03 +00:00
|
|
|
|
|
|
|
{/* peek overview */}
|
|
|
|
<IssuePeekOverview />
|
2024-01-10 14:39:45 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|