import { useRouter } from "next/router"; import useSWR from "swr"; // services import stateService from "services/state.service"; // ui import { CustomSelect } from "components/ui"; // 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; partialUpdateIssue: (formData: Partial) => void; position?: "left" | "right"; isNotAllowed: boolean; }; export const ViewStateSelect: React.FC = ({ issue, partialUpdateIssue, position, isNotAllowed, }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: states } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); return ( s.id === issue.state)?.color, }} /> {addSpaceIfCamelCase(states?.find((s) => s.id === issue.state)?.name ?? "")} } value={issue.state} onChange={(data: string) => { partialUpdateIssue({ state: data }); }} maxHeight="md" noChevron disabled={isNotAllowed} > {states?.map((state) => ( <> {addSpaceIfCamelCase(state.name)} ))} ); };