// react import React from "react"; // ui import { Listbox, Transition } from "@headlessui/react"; // hooks import useUser from "lib/hooks/useUser"; // services import issuesServices from "lib/services/issues.services"; import stateServices from "lib/services/state.services"; // swr import useSWR, { mutate } from "swr"; // types import { IIssue, IssueResponse, IState } from "types"; // constants import { addSpaceIfCamelCase, classNames } from "constants/common"; import { STATE_LIST, USER_ISSUE } from "constants/fetch-keys"; type Props = { issue: IIssue; }; const ChangeStateDropdown = ({ issue }: Props) => { const { activeWorkspace } = useUser(); const partialUpdateIssue = (formData: Partial, projectId: string, issueId: string) => { if (!activeWorkspace) return; issuesServices .patchIssue(activeWorkspace.slug, projectId, issueId, formData) .then((response) => { // mutate( // USER_ISSUE, // (prevData) => ({ // ...(prevData as IssueResponse), // }), // false // ); }) .catch((error) => { console.log(error); }); }; const { data: states } = useSWR( activeWorkspace ? STATE_LIST(issue.project) : null, activeWorkspace ? () => stateServices.getStates(activeWorkspace.slug, issue.project) : null ); return ( <> { partialUpdateIssue({ state: data }, issue.project, issue.id); }} className="flex-shrink-0" > {({ open }) => ( <>
{addSpaceIfCamelCase(issue.state_detail.name)} {states?.map((state) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer select-none px-3 py-2" ) } value={state.id} > {addSpaceIfCamelCase(state.name)} ))}
)}
); }; export default ChangeStateDropdown;