2022-11-30 15:58:45 +00:00
|
|
|
import React, { useState } from "react";
|
2022-11-19 14:21:26 +00:00
|
|
|
// swr
|
|
|
|
import useSWR from "swr";
|
|
|
|
// headless ui
|
|
|
|
import { Listbox, Transition } from "@headlessui/react";
|
|
|
|
// react hook form
|
2022-12-07 23:27:10 +00:00
|
|
|
import { useForm, Controller, UseFormWatch } from "react-hook-form";
|
2022-11-19 14:21:26 +00:00
|
|
|
// services
|
2022-12-12 04:49:52 +00:00
|
|
|
import issuesServices from "lib/services/issues.service";
|
2022-11-19 14:21:26 +00:00
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
2022-12-07 23:27:10 +00:00
|
|
|
import useToast from "lib/hooks/useToast";
|
2022-11-19 14:21:26 +00:00
|
|
|
// fetching keys
|
2022-12-16 16:20:09 +00:00
|
|
|
import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys";
|
2022-11-19 14:21:26 +00:00
|
|
|
// commons
|
2022-12-16 16:20:09 +00:00
|
|
|
import { copyTextToClipboard } from "constants/common";
|
2022-11-19 14:21:26 +00:00
|
|
|
// ui
|
2022-11-29 14:19:39 +00:00
|
|
|
import { Input, Button, Spinner } from "ui";
|
2022-11-30 15:58:45 +00:00
|
|
|
import { Popover } from "@headlessui/react";
|
2022-11-19 14:21:26 +00:00
|
|
|
// icons
|
2022-11-24 13:48:18 +00:00
|
|
|
import {
|
|
|
|
TagIcon,
|
|
|
|
ChevronDownIcon,
|
|
|
|
ClipboardDocumentIcon,
|
|
|
|
LinkIcon,
|
2022-12-01 14:29:21 +00:00
|
|
|
CalendarDaysIcon,
|
2022-12-13 15:52:44 +00:00
|
|
|
TrashIcon,
|
|
|
|
PlusIcon,
|
|
|
|
XMarkIcon,
|
2022-11-24 13:48:18 +00:00
|
|
|
} from "@heroicons/react/24/outline";
|
2022-11-19 14:21:26 +00:00
|
|
|
// types
|
|
|
|
import type { Control } from "react-hook-form";
|
2022-12-16 16:20:09 +00:00
|
|
|
import type { IIssue, IIssueLabels, NestedKeyOf } from "types";
|
2022-11-30 15:58:45 +00:00
|
|
|
import { TwitterPicker } from "react-color";
|
2022-12-13 15:52:44 +00:00
|
|
|
import { positionEditorElement } from "components/lexical/helpers/editor";
|
2022-12-15 04:17:56 +00:00
|
|
|
import SelectState from "./select-state";
|
|
|
|
import SelectPriority from "./select-priority";
|
|
|
|
import SelectParent from "./select-parent";
|
|
|
|
import SelectCycle from "./select-cycle";
|
|
|
|
import SelectAssignee from "./select-assignee";
|
2022-12-16 16:20:09 +00:00
|
|
|
import SelectBlocker from "./select-blocker";
|
|
|
|
import SelectBlocked from "./select-blocked";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
control: Control<IIssue, any>;
|
|
|
|
submitChanges: (formData: Partial<IIssue>) => void;
|
2022-11-24 13:48:18 +00:00
|
|
|
issueDetail: IIssue | undefined;
|
2022-12-07 23:27:10 +00:00
|
|
|
watch: UseFormWatch<IIssue>;
|
2022-12-13 15:52:44 +00:00
|
|
|
setDeleteIssueModal: React.Dispatch<React.SetStateAction<boolean>>;
|
2022-11-19 14:21:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultValues: Partial<IIssueLabels> = {
|
|
|
|
name: "",
|
2022-11-30 15:58:45 +00:00
|
|
|
colour: "#ff0000",
|
2022-11-19 14:21:26 +00:00
|
|
|
};
|
|
|
|
|
2022-12-07 23:27:10 +00:00
|
|
|
const IssueDetailSidebar: React.FC<Props> = ({
|
|
|
|
control,
|
|
|
|
submitChanges,
|
|
|
|
issueDetail,
|
2022-12-13 15:52:44 +00:00
|
|
|
watch: watchIssue,
|
|
|
|
setDeleteIssueModal,
|
2022-12-07 23:27:10 +00:00
|
|
|
}) => {
|
2022-12-13 15:52:44 +00:00
|
|
|
const [createLabelForm, setCreateLabelForm] = useState(false);
|
2022-12-07 23:27:10 +00:00
|
|
|
|
2022-12-16 16:20:09 +00:00
|
|
|
const { activeWorkspace, activeProject, issues } = useUser();
|
2022-11-19 14:21:26 +00:00
|
|
|
|
2022-12-01 14:29:21 +00:00
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
const { data: issueLabels, mutate: issueLabelMutate } = useSWR<IIssueLabels[]>(
|
|
|
|
activeProject && activeWorkspace ? PROJECT_ISSUE_LABELS(activeProject.id) : null,
|
|
|
|
activeProject && activeWorkspace
|
|
|
|
? () => issuesServices.getIssueLabels(activeWorkspace.slug, activeProject.id)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const {
|
|
|
|
register,
|
|
|
|
handleSubmit,
|
|
|
|
formState: { isSubmitting },
|
|
|
|
reset,
|
2022-11-30 15:58:45 +00:00
|
|
|
watch,
|
|
|
|
control: controlLabel,
|
2022-11-19 14:21:26 +00:00
|
|
|
} = useForm({
|
|
|
|
defaultValues,
|
|
|
|
});
|
|
|
|
|
2022-12-15 04:17:56 +00:00
|
|
|
const handleNewLabel = (formData: any) => {
|
2022-11-19 14:21:26 +00:00
|
|
|
if (!activeWorkspace || !activeProject || isSubmitting) return;
|
|
|
|
issuesServices
|
|
|
|
.createIssueLabel(activeWorkspace.slug, activeProject.id, formData)
|
|
|
|
.then((res) => {
|
|
|
|
console.log(res);
|
|
|
|
reset(defaultValues);
|
|
|
|
issueLabelMutate((prevData) => [...(prevData ?? []), res], false);
|
2022-12-19 15:00:09 +00:00
|
|
|
submitChanges({ labels_list: [res.id] });
|
2022-11-19 14:21:26 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-29 14:19:39 +00:00
|
|
|
const handleCycleChange = (cycleId: string) => {
|
|
|
|
if (activeWorkspace && activeProject && issueDetail)
|
2022-12-13 15:52:44 +00:00
|
|
|
issuesServices.addIssueToCycle(activeWorkspace.slug, activeProject.id, cycleId, {
|
2022-11-29 14:19:39 +00:00
|
|
|
issue: issueDetail.id,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-12-19 15:00:09 +00:00
|
|
|
console.log(issueDetail?.labels, issueDetail?.labels_list);
|
2022-12-16 16:20:09 +00:00
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
return (
|
2022-12-13 15:52:44 +00:00
|
|
|
<>
|
|
|
|
<div className="h-full w-full divide-y-2 divide-gray-100">
|
|
|
|
<div className="flex justify-between items-center pb-3">
|
|
|
|
<h4 className="text-sm font-medium">
|
|
|
|
{activeProject?.identifier}-{issueDetail?.sequence_id}
|
|
|
|
</h4>
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="p-2 hover:bg-gray-100 border rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 duration-300"
|
|
|
|
onClick={() =>
|
|
|
|
copyTextToClipboard(
|
|
|
|
`https://app.plane.so/projects/${activeProject?.id}/issues/${issueDetail?.id}`
|
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Copied to clipboard",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Some error occurred",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<LinkIcon className="h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="p-2 hover:bg-gray-100 border rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 duration-300"
|
|
|
|
onClick={() =>
|
|
|
|
copyTextToClipboard(`${issueDetail?.id}`)
|
|
|
|
.then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Copied to clipboard",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "error",
|
|
|
|
title: "Some error occurred",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ClipboardDocumentIcon className="h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="p-2 hover:bg-red-50 text-red-500 border border-red-500 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 duration-300"
|
|
|
|
onClick={() => setDeleteIssueModal(true)}
|
|
|
|
>
|
|
|
|
<TrashIcon className="h-3.5 w-3.5" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-11-30 15:58:45 +00:00
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
<div className="divide-y-2 divide-gray-100">
|
2022-12-15 04:17:56 +00:00
|
|
|
<div className="py-1">
|
|
|
|
<SelectState control={control} submitChanges={submitChanges} />
|
|
|
|
<SelectAssignee control={control} submitChanges={submitChanges} />
|
2022-12-16 16:20:09 +00:00
|
|
|
<SelectPriority control={control} submitChanges={submitChanges} watch={watchIssue} />
|
2022-12-15 04:17:56 +00:00
|
|
|
</div>
|
|
|
|
<div className="py-1">
|
|
|
|
<SelectParent
|
|
|
|
control={control}
|
|
|
|
submitChanges={submitChanges}
|
|
|
|
issuesList={
|
|
|
|
issues?.results.filter(
|
|
|
|
(i) =>
|
|
|
|
i.id !== issueDetail?.id &&
|
|
|
|
i.id !== issueDetail?.parent &&
|
|
|
|
i.parent !== issueDetail?.id
|
|
|
|
) ?? []
|
|
|
|
}
|
|
|
|
customDisplay={
|
|
|
|
issueDetail?.parent_detail ? (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex items-center gap-2 bg-gray-100 px-3 py-2 text-xs rounded"
|
|
|
|
onClick={() => submitChanges({ parent: null })}
|
|
|
|
>
|
|
|
|
{issueDetail.parent_detail?.name}
|
|
|
|
<XMarkIcon className="h-3 w-3" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<div className="inline-block bg-gray-100 px-3 py-2 text-xs rounded">
|
|
|
|
No parent selected
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2022-12-16 16:20:09 +00:00
|
|
|
watch={watchIssue}
|
|
|
|
/>
|
|
|
|
<SelectBlocker
|
|
|
|
submitChanges={submitChanges}
|
|
|
|
issuesList={issues?.results.filter((i) => i.id !== issueDetail?.id) ?? []}
|
|
|
|
watch={watchIssue}
|
|
|
|
/>
|
|
|
|
<SelectBlocked
|
|
|
|
submitChanges={submitChanges}
|
|
|
|
issuesList={issues?.results.filter((i) => i.id !== issueDetail?.id) ?? []}
|
|
|
|
watch={watchIssue}
|
2022-12-15 04:17:56 +00:00
|
|
|
/>
|
|
|
|
<div className="flex items-center py-2 flex-wrap">
|
|
|
|
<div className="flex items-center gap-x-2 text-sm sm:basis-1/2">
|
|
|
|
<CalendarDaysIcon className="flex-shrink-0 h-4 w-4" />
|
|
|
|
<p>Due date</p>
|
|
|
|
</div>
|
|
|
|
<div className="sm:basis-1/2">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="target_date"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<input
|
|
|
|
type="date"
|
|
|
|
value={value ?? ""}
|
|
|
|
onChange={(e: any) => {
|
|
|
|
submitChanges({ target_date: e.target.value });
|
|
|
|
onChange(e.target.value);
|
|
|
|
}}
|
|
|
|
className="hover:bg-gray-100 border rounded-md shadow-sm px-2 py-1 cursor-pointer focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 text-xs duration-300 w-full"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="py-1">
|
|
|
|
<SelectCycle control={control} handleCycleChange={handleCycleChange} />
|
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
</div>
|
|
|
|
<div className="pt-3 space-y-3">
|
|
|
|
<div className="flex justify-between items-start">
|
|
|
|
<div className="flex items-center gap-x-2 text-sm basis-1/2">
|
|
|
|
<TagIcon className="w-4 h-4" />
|
|
|
|
<p>Label</p>
|
|
|
|
</div>
|
|
|
|
<div className="basis-1/2">
|
|
|
|
<div className="flex gap-1 flex-wrap">
|
2022-12-19 15:00:09 +00:00
|
|
|
{issueDetail?.labels.map((label) => {
|
|
|
|
const singleLabel = issueLabels?.find((l) => l.id === label);
|
|
|
|
|
|
|
|
if (!singleLabel) return null;
|
|
|
|
|
|
|
|
return (
|
2022-12-13 15:52:44 +00:00
|
|
|
<span
|
2022-12-19 15:00:09 +00:00
|
|
|
key={singleLabel.id}
|
|
|
|
className="group flex items-center gap-1 border rounded-2xl text-xs px-1 py-0.5 hover:bg-red-50 hover:border-red-500 cursor-pointer"
|
|
|
|
onClick={() => {
|
|
|
|
const updatedLabels = issueDetail?.labels.filter((l) => l !== label);
|
|
|
|
// submitChanges({
|
|
|
|
// labels_list: updatedLabels,
|
|
|
|
// });
|
|
|
|
console.log(updatedLabels);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className="h-2 w-2 rounded-full flex-shrink-0"
|
|
|
|
style={{ backgroundColor: singleLabel.colour ?? "green" }}
|
|
|
|
></span>
|
|
|
|
{singleLabel.name}
|
|
|
|
<XMarkIcon className="h-2 w-2 group-hover:text-red-500" />
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
})}
|
2022-12-13 15:52:44 +00:00
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="labels_list"
|
|
|
|
render={({ field: { value } }) => (
|
|
|
|
<Listbox
|
|
|
|
as="div"
|
|
|
|
value={value}
|
2022-12-16 16:20:09 +00:00
|
|
|
onChange={(val: any) => submitChanges({ labels_list: val })}
|
2022-12-13 15:52:44 +00:00
|
|
|
className="flex-shrink-0"
|
2022-12-19 15:00:09 +00:00
|
|
|
multiple
|
2022-12-13 15:52:44 +00:00
|
|
|
>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<Listbox.Label className="sr-only">Label</Listbox.Label>
|
|
|
|
<div className="relative">
|
2022-12-15 04:17:56 +00:00
|
|
|
<Listbox.Button className="flex items-center gap-2 border rounded-2xl text-xs px-2 py-0.5 hover:bg-gray-100 cursor-pointer">
|
|
|
|
Select Label
|
2022-12-13 15:52:44 +00:00
|
|
|
</Listbox.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
show={open}
|
|
|
|
as={React.Fragment}
|
|
|
|
leave="transition ease-in duration-100"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
|
|
|
<Listbox.Options className="absolute z-10 right-0 mt-1 w-40 bg-white shadow-lg max-h-28 rounded-md py-1 text-xs ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none">
|
2022-12-16 16:20:09 +00:00
|
|
|
<div className="py-1">
|
2022-12-13 15:52:44 +00:00
|
|
|
{issueLabels ? (
|
|
|
|
issueLabels.length > 0 ? (
|
|
|
|
issueLabels.map((label: IIssueLabels) => (
|
|
|
|
<Listbox.Option
|
|
|
|
key={label.id}
|
|
|
|
className={({ active, selected }) =>
|
|
|
|
`${
|
2022-12-16 16:20:09 +00:00
|
|
|
active || selected ? "bg-indigo-50" : ""
|
|
|
|
} flex items-center gap-2 text-gray-900 cursor-pointer select-none relative p-2 truncate`
|
2022-12-13 15:52:44 +00:00
|
|
|
}
|
|
|
|
value={label.id}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className="h-2 w-2 rounded-full flex-shrink-0"
|
|
|
|
style={{ backgroundColor: label.colour ?? "green" }}
|
|
|
|
></span>
|
|
|
|
{label.name}
|
|
|
|
</Listbox.Option>
|
|
|
|
))
|
2022-11-30 15:58:45 +00:00
|
|
|
) : (
|
2022-12-13 15:52:44 +00:00
|
|
|
<div className="text-center">No labels found</div>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<Spinner />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Listbox.Options>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
</>
|
2022-11-19 14:21:26 +00:00
|
|
|
)}
|
2022-12-13 15:52:44 +00:00
|
|
|
</Listbox>
|
2022-11-19 14:21:26 +00:00
|
|
|
)}
|
2022-12-13 15:52:44 +00:00
|
|
|
/>
|
2022-12-15 04:17:56 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex items-center gap-1 border rounded-2xl text-xs px-2 py-0.5 hover:bg-gray-100 cursor-pointer"
|
|
|
|
onClick={() => setCreateLabelForm((prevData) => !prevData)}
|
|
|
|
>
|
|
|
|
{createLabelForm ? (
|
|
|
|
<>
|
|
|
|
<XMarkIcon className="h-3 w-3" /> Cancel
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<PlusIcon className="h-3 w-3" /> New
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</button>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
</div>
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
{createLabelForm && (
|
2022-12-15 04:17:56 +00:00
|
|
|
<form className="flex items-center gap-x-2" onSubmit={handleSubmit(handleNewLabel)}>
|
2022-12-13 15:52:44 +00:00
|
|
|
<div>
|
|
|
|
<Popover className="relative">
|
2022-11-30 15:58:45 +00:00
|
|
|
{({ open }) => (
|
|
|
|
<>
|
2022-12-13 15:52:44 +00:00
|
|
|
<Popover.Button
|
|
|
|
className={`bg-white flex items-center gap-1 rounded-md p-1 outline-none focus:ring-2 focus:ring-indigo-500`}
|
|
|
|
>
|
|
|
|
{watch("colour") && watch("colour") !== "" && (
|
2022-11-30 15:58:45 +00:00
|
|
|
<span
|
2022-12-13 15:52:44 +00:00
|
|
|
className="w-5 h-5 rounded"
|
|
|
|
style={{
|
|
|
|
backgroundColor: watch("colour") ?? "green",
|
|
|
|
}}
|
|
|
|
></span>
|
|
|
|
)}
|
|
|
|
<ChevronDownIcon className="h-3 w-3" />
|
|
|
|
</Popover.Button>
|
2022-11-30 15:58:45 +00:00
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
<Transition
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="transition ease-out duration-200"
|
|
|
|
enterFrom="opacity-0 translate-y-1"
|
|
|
|
enterTo="opacity-100 translate-y-0"
|
|
|
|
leave="transition ease-in duration-150"
|
|
|
|
leaveFrom="opacity-100 translate-y-0"
|
|
|
|
leaveTo="opacity-0 translate-y-1"
|
|
|
|
>
|
|
|
|
<Popover.Panel className="absolute z-10 transform right-0 mt-1 px-2 max-w-xs sm:px-0">
|
|
|
|
<Controller
|
|
|
|
name="colour"
|
|
|
|
control={controlLabel}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<TwitterPicker
|
|
|
|
color={value}
|
|
|
|
onChange={(value) => onChange(value.hex)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
2022-11-30 15:58:45 +00:00
|
|
|
</>
|
|
|
|
)}
|
2022-12-13 15:52:44 +00:00
|
|
|
</Popover>
|
|
|
|
</div>
|
|
|
|
<Input
|
|
|
|
id="name"
|
|
|
|
name="name"
|
|
|
|
placeholder="Title"
|
|
|
|
register={register}
|
|
|
|
validations={{
|
|
|
|
required: "This is required",
|
|
|
|
}}
|
|
|
|
autoComplete="off"
|
|
|
|
/>
|
|
|
|
<Button type="submit" theme="success" disabled={isSubmitting}>
|
|
|
|
+
|
|
|
|
</Button>
|
|
|
|
</form>
|
|
|
|
)}
|
2022-11-19 14:21:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
</>
|
2022-11-19 14:21:26 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default IssueDetailSidebar;
|