2022-12-15 04:17:56 +00:00
|
|
|
// react
|
|
|
|
import React, { useState } from "react";
|
|
|
|
// react-hook-form
|
|
|
|
import { Control, Controller, UseFormWatch } from "react-hook-form";
|
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
|
|
|
// components
|
2022-12-16 16:20:09 +00:00
|
|
|
import IssuesListModal from "components/project/issues/issues-list-modal";
|
2022-12-15 04:17:56 +00:00
|
|
|
// icons
|
|
|
|
import { UserIcon } from "@heroicons/react/24/outline";
|
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
control: Control<IIssue, any>;
|
|
|
|
submitChanges: (formData: Partial<IIssue>) => void;
|
|
|
|
issuesList: IIssue[];
|
|
|
|
customDisplay: JSX.Element;
|
2022-12-16 16:20:09 +00:00
|
|
|
watch: UseFormWatch<IIssue>;
|
2022-12-15 04:17:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SelectParent: React.FC<Props> = ({
|
|
|
|
control,
|
|
|
|
submitChanges,
|
|
|
|
issuesList,
|
|
|
|
customDisplay,
|
2022-12-16 16:20:09 +00:00
|
|
|
watch,
|
2022-12-15 04:17:56 +00:00
|
|
|
}) => {
|
|
|
|
const [isParentModalOpen, setIsParentModalOpen] = useState(false);
|
|
|
|
|
|
|
|
const { activeProject, issues } = useUser();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex items-center py-2 flex-wrap">
|
|
|
|
<div className="flex items-center gap-x-2 text-sm sm:basis-1/2">
|
|
|
|
<UserIcon className="flex-shrink-0 h-4 w-4" />
|
|
|
|
<p>Parent</p>
|
|
|
|
</div>
|
|
|
|
<div className="sm:basis-1/2">
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="parent"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<IssuesListModal
|
|
|
|
isOpen={isParentModalOpen}
|
|
|
|
handleClose={() => setIsParentModalOpen(false)}
|
|
|
|
onChange={(val) => {
|
|
|
|
submitChanges({ parent: val });
|
|
|
|
onChange(val);
|
|
|
|
}}
|
|
|
|
issues={issuesList}
|
|
|
|
title="Select Parent"
|
|
|
|
value={value}
|
|
|
|
customDisplay={customDisplay}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex justify-between items-center gap-1 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"
|
|
|
|
onClick={() => setIsParentModalOpen(true)}
|
|
|
|
>
|
2022-12-16 16:20:09 +00:00
|
|
|
{watch("parent") && watch("parent") !== ""
|
2022-12-15 04:17:56 +00:00
|
|
|
? `${activeProject?.identifier}-${
|
2022-12-16 16:20:09 +00:00
|
|
|
issues?.results.find((i) => i.id === watch("parent"))?.sequence_id
|
2022-12-15 04:17:56 +00:00
|
|
|
}`
|
2022-12-16 16:20:09 +00:00
|
|
|
: "Select issue"}
|
2022-12-15 04:17:56 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SelectParent;
|