2023-11-01 08:52:29 +00:00
|
|
|
import { FC, useState } from "react";
|
|
|
|
import { mutate } from "swr";
|
|
|
|
import { useRouter } from "next/router";
|
2023-11-02 11:41:33 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-10-18 14:28:05 +00:00
|
|
|
// ui icons
|
2023-12-05 10:35:50 +00:00
|
|
|
import { DiceIcon, DoubleCircleIcon, UserGroupIcon, ContrastIcon } from "@plane/ui";
|
|
|
|
import { CalendarDays, Link2, Plus, Signal, Tag, Triangle, LayoutPanelTop } from "lucide-react";
|
2023-11-01 08:52:29 +00:00
|
|
|
import {
|
|
|
|
SidebarAssigneeSelect,
|
|
|
|
SidebarCycleSelect,
|
|
|
|
SidebarEstimateSelect,
|
|
|
|
SidebarLabelSelect,
|
|
|
|
SidebarModuleSelect,
|
|
|
|
SidebarParentSelect,
|
|
|
|
SidebarPrioritySelect,
|
|
|
|
SidebarStateSelect,
|
|
|
|
} from "../sidebar-select";
|
2023-11-29 08:55:57 +00:00
|
|
|
// services
|
|
|
|
import { IssueService } from "services/issue";
|
2023-11-01 08:52:29 +00:00
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
2023-10-18 14:28:05 +00:00
|
|
|
// components
|
2023-11-01 08:52:29 +00:00
|
|
|
import { CustomDatePicker } from "components/ui";
|
|
|
|
import { LinkModal, LinksList } from "components/core";
|
2023-10-18 14:28:05 +00:00
|
|
|
// types
|
2023-12-05 14:02:25 +00:00
|
|
|
import { IIssue, IIssueLink, TIssuePriorities, ILinkDetails } from "types";
|
2023-11-29 08:55:57 +00:00
|
|
|
// fetch-keys
|
2023-11-01 08:52:29 +00:00
|
|
|
import { ISSUE_DETAILS } from "constants/fetch-keys";
|
2023-11-29 08:55:57 +00:00
|
|
|
// constants
|
|
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
2023-10-18 14:28:05 +00:00
|
|
|
|
|
|
|
interface IPeekOverviewProperties {
|
|
|
|
issue: IIssue;
|
|
|
|
issueUpdate: (issue: Partial<IIssue>) => void;
|
2023-11-03 13:43:10 +00:00
|
|
|
disableUserActions: boolean;
|
2023-10-18 14:28:05 +00:00
|
|
|
}
|
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
const issueService = new IssueService();
|
|
|
|
|
2023-11-02 11:41:33 +00:00
|
|
|
export const PeekOverviewProperties: FC<IPeekOverviewProperties> = observer((props) => {
|
2023-11-03 13:43:10 +00:00
|
|
|
const { issue, issueUpdate, disableUserActions } = props;
|
|
|
|
// states
|
2023-11-01 08:52:29 +00:00
|
|
|
const [linkModal, setLinkModal] = useState(false);
|
2023-12-05 14:02:25 +00:00
|
|
|
const [selectedLinkToUpdate, setSelectedLinkToUpdate] = useState<ILinkDetails | null>(null);
|
2023-10-18 14:28:05 +00:00
|
|
|
|
2023-11-29 08:55:57 +00:00
|
|
|
const {
|
|
|
|
user: { currentProjectRole },
|
|
|
|
cycleIssues: { addIssueToCycle },
|
|
|
|
moduleIssues: { addIssueToModule },
|
|
|
|
} = useMobxStore();
|
2023-11-02 11:41:33 +00:00
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const { setToastAlert } = useToast();
|
2023-10-18 14:28:05 +00:00
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
const handleState = (_state: string) => {
|
|
|
|
issueUpdate({ ...issue, state: _state });
|
|
|
|
};
|
2023-10-25 14:17:58 +00:00
|
|
|
const handlePriority = (_priority: TIssuePriorities) => {
|
|
|
|
issueUpdate({ ...issue, priority: _priority });
|
2023-10-18 14:28:05 +00:00
|
|
|
};
|
|
|
|
const handleAssignee = (_assignees: string[]) => {
|
2023-10-25 14:17:58 +00:00
|
|
|
issueUpdate({ ...issue, assignees: _assignees });
|
2023-10-18 14:28:05 +00:00
|
|
|
};
|
2023-11-01 08:52:29 +00:00
|
|
|
const handleEstimate = (_estimate: number | null) => {
|
|
|
|
issueUpdate({ ...issue, estimate_point: _estimate });
|
|
|
|
};
|
|
|
|
const handleStartDate = (_startDate: string | null) => {
|
2023-10-25 14:17:58 +00:00
|
|
|
issueUpdate({ ...issue, start_date: _startDate });
|
2023-10-18 14:28:05 +00:00
|
|
|
};
|
2023-11-01 08:52:29 +00:00
|
|
|
const handleTargetDate = (_targetDate: string | null) => {
|
2023-10-25 14:17:58 +00:00
|
|
|
issueUpdate({ ...issue, target_date: _targetDate });
|
2023-10-18 14:28:05 +00:00
|
|
|
};
|
2023-11-01 08:52:29 +00:00
|
|
|
const handleParent = (_parent: string) => {
|
|
|
|
issueUpdate({ ...issue, parent: _parent });
|
|
|
|
};
|
2023-11-29 08:55:57 +00:00
|
|
|
const handleAddIssueToCycle = async (cycleId: string) => {
|
2023-11-03 12:31:34 +00:00
|
|
|
if (!workspaceSlug || !issue || !cycleId) return;
|
2023-11-29 08:55:57 +00:00
|
|
|
|
|
|
|
addIssueToCycle(workspaceSlug.toString(), cycleId, [issue.id]);
|
2023-11-01 08:52:29 +00:00
|
|
|
};
|
2023-11-03 12:31:34 +00:00
|
|
|
|
2023-11-29 08:55:57 +00:00
|
|
|
const handleAddIssueToModule = async (moduleId: string) => {
|
2023-11-03 12:31:34 +00:00
|
|
|
if (!workspaceSlug || !issue || !moduleId) return;
|
|
|
|
|
2023-11-29 08:55:57 +00:00
|
|
|
addIssueToModule(workspaceSlug.toString(), moduleId, [issue.id]);
|
2023-11-01 08:52:29 +00:00
|
|
|
};
|
|
|
|
const handleLabels = (formData: Partial<IIssue>) => {
|
|
|
|
issueUpdate({ ...issue, ...formData });
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCreateLink = async (formData: IIssueLink) => {
|
|
|
|
if (!workspaceSlug || !projectId || !issue) return;
|
|
|
|
|
|
|
|
const payload = { metadata: {}, ...formData };
|
|
|
|
|
|
|
|
await issueService
|
|
|
|
.createIssueLink(workspaceSlug as string, projectId as string, issue.id, payload)
|
|
|
|
.then(() => mutate(ISSUE_DETAILS(issue.id)))
|
|
|
|
.catch((err) => {
|
|
|
|
if (err.status === 400)
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "This URL already exists for this issue.",
|
|
|
|
});
|
|
|
|
else
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Error!",
|
|
|
|
message: "Something went wrong. Please try again.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleUpdateLink = async (formData: IIssueLink, linkId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId || !issue) return;
|
|
|
|
|
|
|
|
const payload = { metadata: {}, ...formData };
|
|
|
|
|
|
|
|
const updatedLinks = issue.issue_link.map((l) =>
|
|
|
|
l.id === linkId
|
|
|
|
? {
|
|
|
|
...l,
|
|
|
|
title: formData.title,
|
|
|
|
url: formData.url,
|
|
|
|
}
|
|
|
|
: l
|
|
|
|
);
|
|
|
|
|
|
|
|
mutate<IIssue>(
|
|
|
|
ISSUE_DETAILS(issue.id),
|
|
|
|
(prevData) => ({ ...(prevData as IIssue), issue_link: updatedLinks }),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
await issueService
|
|
|
|
.updateIssueLink(workspaceSlug as string, projectId as string, issue.id, linkId, payload)
|
|
|
|
.then(() => {
|
|
|
|
mutate(ISSUE_DETAILS(issue.id));
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-12-05 14:02:25 +00:00
|
|
|
const handleEditLink = (link: ILinkDetails) => {
|
2023-11-01 08:52:29 +00:00
|
|
|
setSelectedLinkToUpdate(link);
|
|
|
|
setLinkModal(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDeleteLink = async (linkId: string) => {
|
|
|
|
if (!workspaceSlug || !projectId || !issue) return;
|
|
|
|
|
|
|
|
const updatedLinks = issue.issue_link.filter((l) => l.id !== linkId);
|
|
|
|
|
|
|
|
mutate<IIssue>(
|
|
|
|
ISSUE_DETAILS(issue.id),
|
|
|
|
(prevData) => ({ ...(prevData as IIssue), issue_link: updatedLinks }),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
await issueService
|
|
|
|
.deleteIssueLink(workspaceSlug as string, projectId as string, issue.id, linkId)
|
|
|
|
.then(() => {
|
|
|
|
mutate(ISSUE_DETAILS(issue.id));
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const minDate = issue.start_date ? new Date(issue.start_date) : null;
|
|
|
|
minDate?.setDate(minDate.getDate());
|
|
|
|
|
|
|
|
const maxDate = issue.target_date ? new Date(issue.target_date) : null;
|
|
|
|
maxDate?.setDate(maxDate.getDate());
|
|
|
|
|
2023-10-18 14:28:05 +00:00
|
|
|
return (
|
2023-11-01 08:52:29 +00:00
|
|
|
<>
|
|
|
|
<LinkModal
|
|
|
|
isOpen={linkModal}
|
|
|
|
handleClose={() => {
|
|
|
|
setLinkModal(false);
|
|
|
|
setSelectedLinkToUpdate(null);
|
|
|
|
}}
|
|
|
|
data={selectedLinkToUpdate}
|
|
|
|
status={selectedLinkToUpdate ? true : false}
|
|
|
|
createIssueLink={handleCreateLink}
|
|
|
|
updateIssueLink={handleUpdateLink}
|
|
|
|
/>
|
|
|
|
<div className="flex flex-col">
|
|
|
|
<div className="flex flex-col gap-5 py-5 w-full">
|
|
|
|
{/* state */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<DoubleCircleIcon className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>State</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarStateSelect value={issue?.state || ""} onChange={handleState} disabled={disableUserActions} />
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
{/* assignee */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<UserGroupIcon className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Assignees</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarAssigneeSelect
|
|
|
|
value={issue.assignees || []}
|
|
|
|
onChange={handleAssignee}
|
|
|
|
disabled={disableUserActions}
|
|
|
|
/>
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
{/* priority */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<Signal className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Priority</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarPrioritySelect
|
|
|
|
value={issue.priority || ""}
|
|
|
|
onChange={handlePriority}
|
|
|
|
disabled={disableUserActions}
|
|
|
|
/>
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
{/* estimate */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<Triangle className="h-4 w-4 flex-shrink-0 " />
|
|
|
|
<p>Estimate</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarEstimateSelect
|
|
|
|
value={issue.estimate_point}
|
|
|
|
onChange={handleEstimate}
|
|
|
|
disabled={disableUserActions}
|
|
|
|
/>
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* start date */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<CalendarDays className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Start date</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<CustomDatePicker
|
|
|
|
placeholder="Start date"
|
|
|
|
value={issue.start_date}
|
|
|
|
onChange={handleStartDate}
|
2023-11-08 12:25:28 +00:00
|
|
|
className="bg-custom-background-80 !rounded border-none !px-2.5 !py-0.5"
|
2023-11-01 08:52:29 +00:00
|
|
|
maxDate={maxDate ?? undefined}
|
2023-11-03 13:43:10 +00:00
|
|
|
disabled={disableUserActions}
|
2023-11-01 08:52:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* due date */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<CalendarDays className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Due date</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<CustomDatePicker
|
|
|
|
placeholder="Due date"
|
|
|
|
value={issue.target_date}
|
|
|
|
onChange={handleTargetDate}
|
2023-11-08 12:25:28 +00:00
|
|
|
className="bg-custom-background-80 !rounded border-none !px-2.5 !py-0.5"
|
2023-11-01 08:52:29 +00:00
|
|
|
minDate={minDate ?? undefined}
|
2023-11-03 13:43:10 +00:00
|
|
|
disabled={disableUserActions}
|
2023-11-01 08:52:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* parent */}
|
|
|
|
<div className="flex items-center gap-2 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-12-05 10:35:50 +00:00
|
|
|
<LayoutPanelTop className="h-4 w-4 flex-shrink-0" />
|
2023-11-01 08:52:29 +00:00
|
|
|
<p>Parent</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarParentSelect onChange={handleParent} issueDetails={issue} disabled={disableUserActions} />
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-11-01 08:52:29 +00:00
|
|
|
<span className="border-t border-custom-border-200" />
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-5 py-5 w-full">
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-full">
|
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<ContrastIcon className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Cycle</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarCycleSelect
|
|
|
|
issueDetail={issue}
|
2023-11-29 08:55:57 +00:00
|
|
|
handleCycleChange={handleAddIssueToCycle}
|
2023-11-03 13:43:10 +00:00
|
|
|
disabled={disableUserActions}
|
|
|
|
/>
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-11-07 10:28:42 +00:00
|
|
|
<div className="flex items-center gap-2 w-full">
|
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<DiceIcon className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Module</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
<SidebarModuleSelect
|
|
|
|
issueDetail={issue}
|
2023-11-29 08:55:57 +00:00
|
|
|
handleModuleChange={handleAddIssueToModule}
|
2023-11-03 13:43:10 +00:00
|
|
|
disabled={disableUserActions}
|
|
|
|
/>
|
2023-11-01 08:52:29 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-start gap-2 w-full">
|
2023-11-03 12:31:34 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm flex-shrink-0">
|
2023-11-01 08:52:29 +00:00
|
|
|
<Tag className="h-4 w-4 flex-shrink-0" />
|
|
|
|
<p>Label</p>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-3 w-full">
|
|
|
|
<SidebarLabelSelect
|
|
|
|
issueDetails={issue}
|
|
|
|
labelList={issue.labels}
|
|
|
|
submitChanges={handleLabels}
|
2023-11-03 13:43:10 +00:00
|
|
|
isNotAllowed={disableUserActions}
|
|
|
|
uneditable={disableUserActions}
|
2023-11-01 08:52:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-01 08:52:29 +00:00
|
|
|
|
|
|
|
<span className="border-t border-custom-border-200" />
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-5 pt-5 w-full">
|
|
|
|
<div className="flex flex-col gap-2 w-full">
|
|
|
|
<div className="flex items-center gap-2 w-80">
|
2023-11-03 12:31:34 +00:00
|
|
|
<div className="flex items-center gap-2 w-40 text-sm">
|
|
|
|
<Link2 className="h-4 w-4 flex-shrink-0" />
|
2023-11-01 08:52:29 +00:00
|
|
|
<p>Links</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-11-03 13:43:10 +00:00
|
|
|
{!disableUserActions && (
|
2023-11-01 08:52:29 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`flex ${
|
2023-11-03 13:43:10 +00:00
|
|
|
disableUserActions ? "cursor-not-allowed" : "cursor-pointer hover:bg-custom-background-90"
|
2023-11-01 08:52:29 +00:00
|
|
|
} items-center gap-1 rounded-2xl border border-custom-border-100 px-2 py-0.5 text-xs hover:text-custom-text-200 text-custom-text-300`}
|
|
|
|
onClick={() => setLinkModal(true)}
|
|
|
|
disabled={false}
|
|
|
|
>
|
|
|
|
<Plus className="h-3 w-3" /> New
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
{issue?.issue_link && issue.issue_link.length > 0 ? (
|
|
|
|
<LinksList
|
|
|
|
links={issue.issue_link}
|
|
|
|
handleDeleteLink={handleDeleteLink}
|
|
|
|
handleEditLink={handleEditLink}
|
2023-11-02 11:41:33 +00:00
|
|
|
userAuth={{
|
2023-11-29 08:55:57 +00:00
|
|
|
isGuest: currentProjectRole === EUserWorkspaceRoles.GUEST,
|
|
|
|
isViewer: currentProjectRole === EUserWorkspaceRoles.VIEWER,
|
|
|
|
isMember: currentProjectRole === EUserWorkspaceRoles.MEMBER,
|
|
|
|
isOwner: currentProjectRole === EUserWorkspaceRoles.ADMIN,
|
2023-11-02 11:41:33 +00:00
|
|
|
}}
|
2023-11-01 08:52:29 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-10-18 14:28:05 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-01 08:52:29 +00:00
|
|
|
</>
|
2023-10-18 14:28:05 +00:00
|
|
|
);
|
2023-11-02 11:41:33 +00:00
|
|
|
});
|