import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { Control, Controller } from "react-hook-form"; // services import stateService from "lib/services/state.service"; // icons import { Squares2X2Icon } from "@heroicons/react/24/outline"; // constants import { classNames } from "constants/common"; import { STATE_LIST } from "constants/fetch-keys"; // types import { IIssue } from "types"; // ui import { Spinner, CustomSelect } from "ui"; type Props = { control: Control; submitChanges: (formData: Partial) => void; }; const SelectState: React.FC = ({ control, submitChanges }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: states } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); return (

State

( {value ? ( <> option.id === value)?.color, }} > {states?.find((option) => option.id === value)?.name} ) : ( "None" )} } value={value} onChange={(value: any) => { submitChanges({ state: value }); }} > {states ? ( states.length > 0 ? ( states.map((option) => ( <> {option.color && ( )} {option.name} )) ) : (
No states found
) ) : ( )}
)} />
); }; export default SelectState;