import React from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import projectService from "services/project.service"; import estimatesService from "services/estimates.service"; // ui import { CustomSelect } from "components/ui"; // icons // fetch-keys import { ESTIMATE_POINTS_LIST, PROJECT_DETAILS } from "constants/fetch-keys"; type Props = { value: number; onChange: (value: number) => void; }; export const IssueEstimateSelect: React.FC = ({ value, onChange }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: projectDetails } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? () => projectService.getProject(workspaceSlug as string, projectId as string) : null ); const { data: estimatePoints } = useSWR( workspaceSlug && projectId && projectDetails && projectDetails.estimate ? ESTIMATE_POINTS_LIST(projectDetails.estimate) : null, workspaceSlug && projectId && projectDetails && projectDetails.estimate ? () => estimatesService.getEstimatesPointsList( workspaceSlug as string, projectId as string, projectDetails.estimate ) : null ); return ( {estimatePoints?.find((e) => e.key === value)?.value ?? "Estimate points"} } onChange={onChange} position="right" width="w-full" > {estimatePoints && estimatePoints.map((point) => ( {point.value} ))} ); };