import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // react-hook-form import { Control, Controller } from "react-hook-form"; // services import stateService from "services/state.service"; // ui import { Spinner, CustomSelect } from "components/ui"; // icons import { Squares2X2Icon } from "@heroicons/react/24/outline"; // helpers import { getStatesList } from "helpers/state.helper"; // types import { IIssue, UserAuth } from "types"; // constants import { STATE_LIST } from "constants/fetch-keys"; type Props = { control: Control; submitChanges: (formData: Partial) => void; userAuth: UserAuth; }; export const SidebarStateSelect: React.FC = ({ control, submitChanges, userAuth }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: stateGroups } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); const states = getStatesList(stateGroups ?? {}); const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return (

State

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