2022-11-19 14:21:26 +00:00
|
|
|
import React from "react";
|
|
|
|
// react hook form
|
|
|
|
import { Controller } from "react-hook-form";
|
|
|
|
// headless ui
|
|
|
|
import { Listbox, Transition } from "@headlessui/react";
|
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
|
|
|
// components
|
|
|
|
import CreateUpdateSprintsModal from "components/project/cycles/CreateUpdateCyclesModal";
|
|
|
|
// icons
|
|
|
|
import { CheckIcon, ChevronDownIcon, PlusIcon } from "@heroicons/react/20/solid";
|
|
|
|
// types
|
|
|
|
import type { IIssue } from "types";
|
|
|
|
import type { Control } from "react-hook-form";
|
|
|
|
import { ArrowPathIcon } from "@heroicons/react/24/outline";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
control: Control<IIssue, any>;
|
|
|
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const SelectSprint: React.FC<Props> = ({ control, setIsOpen }) => {
|
2022-11-30 15:58:45 +00:00
|
|
|
const { cycles } = useUser();
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="sprints"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<Listbox as="div" value={value} onChange={onChange}>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<div className="relative">
|
|
|
|
<Listbox.Button className="flex items-center gap-1 hover:bg-gray-100 relative 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 sm:text-sm duration-300">
|
2022-12-03 13:41:07 +00:00
|
|
|
<ArrowPathIcon className="h-3 w-3 text-gray-500" />
|
2022-11-19 14:21:26 +00:00
|
|
|
<span className="block truncate">
|
2022-11-30 15:58:45 +00:00
|
|
|
{cycles?.find((i) => i.id.toString() === value?.toString())?.name ?? "Cycle"}
|
2022-11-19 14:21:26 +00:00
|
|
|
</span>
|
|
|
|
</Listbox.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
show={open}
|
|
|
|
as={React.Fragment}
|
|
|
|
leave="transition ease-in duration-100"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
2022-11-24 13:48:18 +00:00
|
|
|
<Listbox.Options className="absolute z-10 mt-1 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-11-19 14:21:26 +00:00
|
|
|
<div className="p-1">
|
2022-11-30 15:58:45 +00:00
|
|
|
{cycles?.map((cycle) => (
|
2022-11-19 14:21:26 +00:00
|
|
|
<Listbox.Option
|
2022-11-30 15:58:45 +00:00
|
|
|
key={cycle.id}
|
|
|
|
value={cycle.id}
|
2022-11-19 14:21:26 +00:00
|
|
|
className={({ active }) =>
|
|
|
|
`relative cursor-pointer select-none p-2 rounded-md ${
|
|
|
|
active ? "bg-theme text-white" : "text-gray-900"
|
|
|
|
}`
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{({ active, selected }) => (
|
|
|
|
<>
|
|
|
|
<span className={`block ${selected && "font-semibold"}`}>
|
2022-11-30 15:58:45 +00:00
|
|
|
{cycle.name}
|
2022-11-19 14:21:26 +00:00
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Listbox.Option>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="relative select-none py-2 pl-3 pr-9 flex items-center gap-x-2 text-gray-400 hover:text-gray-500"
|
|
|
|
onClick={() => setIsOpen(true)}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
<PlusIcon className="h-5 w-5 text-gray-400" aria-hidden="true" />
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
<span className="block truncate">Create cycle</span>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</Listbox.Options>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Listbox>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SelectSprint;
|