import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import { ProjectStateService } from "services/project"; // ui import { CustomSelect } from "components/ui"; import { Spinner, StateGroupIcon } from "@plane/ui"; // helpers import { getStatesList } from "helpers/state.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper"; // constants import { STATES_LIST } from "constants/fetch-keys"; type Props = { value: string; onChange: (val: string) => void; disabled?: boolean; }; // services const stateService = new ProjectStateService(); export const SidebarStateSelect: React.FC = ({ value, onChange, disabled = false }) => { const router = useRouter(); const { workspaceSlug, projectId, inboxIssueId } = router.query; const { data: stateGroups } = useSWR( workspaceSlug && projectId ? STATES_LIST(projectId as string) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); const states = getStatesList(stateGroups); const selectedState = states?.find((s) => s.id === value); return ( {selectedState ? (
{addSpaceIfCamelCase(selectedState?.name ?? "")}
) : inboxIssueId ? (
Triage
) : ( "None" )} } value={value} onChange={onChange} optionsClassName="w-min" disabled={disabled} > {states ? ( states.length > 0 ? ( states.map((state) => ( <> {state.name} )) ) : (
No states found
) ) : ( )}
); };