import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // services import stateServices from "services/state.service"; // helpers import { addSpaceIfCamelCase } from "helpers/string.helper"; // types import { IIssue, IState } from "types"; // fetch-keys import { STATE_LIST } from "constants/fetch-keys"; type Props = { issue: IIssue; updateIssues: ( workspaceSlug: string, projectId: string, issueId: string, issue: Partial ) => void; }; const ChangeStateDropdown: React.FC = ({ issue, updateIssues }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { data: states } = useSWR( workspaceSlug ? STATE_LIST(issue.project) : null, workspaceSlug ? () => stateServices.getStates(workspaceSlug as string, issue.project) : null ); return ( <> { if (!workspaceSlug) return; updateIssues(workspaceSlug as string, issue.project, issue.id, { state: data, state_detail: states?.find((state) => state.id === data), }); }} className="flex-shrink-0" > {({ open }) => ( <>
{addSpaceIfCamelCase(issue.state_detail.name)} {states?.map((state) => ( `cursor-pointer select-none px-3 py-2 ${ active ? "bg-indigo-50" : "bg-white" }` } value={state.id} > {addSpaceIfCamelCase(state.name)} ))}
)}
); }; export default ChangeStateDropdown;