import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import { ProjectStateService } from "services/project"; // ui import { CustomSearchSelect, DoubleCircleIcon, StateGroupIcon } from "@plane/ui"; // icons import { Plus } from "lucide-react"; // helpers import { getStatesList } from "helpers/state.helper"; // fetch keys import { STATES_LIST } from "constants/fetch-keys"; type Props = { setIsOpen: React.Dispatch>; value: string; onChange: (value: string) => void; projectId: string; }; // services const projectStateService = new ProjectStateService(); export const IssueStateSelect: React.FC = ({ setIsOpen, value, onChange, projectId }) => { // states const router = useRouter(); const { workspaceSlug } = router.query; const { data: stateGroups } = useSWR( workspaceSlug && projectId ? STATES_LIST(projectId) : null, workspaceSlug && projectId ? () => projectStateService.getStates(workspaceSlug as string, projectId) : null ); const states = getStatesList(stateGroups); const options = states?.map((state) => ({ value: state.id, query: state.name, content: (
{state.name}
), })); const selectedOption = states?.find((s) => s.id === value); const currentDefaultState = states?.find((s) => s.default); return ( {selectedOption ? ( ) : currentDefaultState ? ( ) : ( )} {selectedOption?.name ? selectedOption.name : currentDefaultState?.name ?? State} } footerOption={ } noChevron /> ); };