plane/web/hooks/use-estimate-option.tsx
Anmol Singh Bhatia 60a69e28e3
fix: issue activity estimate value bug fix (#2281)
* fix: issue activity estimate value bug fix

* fix: activity typo fix
2023-09-28 13:18:35 +05:30

47 lines
1.4 KiB
TypeScript

import { useRouter } from "next/router";
import useSWR from "swr";
// services
import estimatesService from "services/estimates.service";
// hooks
import useProjectDetails from "hooks/use-project-details";
// helpers
import { orderArrayBy } from "helpers/array.helper";
// fetch-keys
import { ESTIMATE_DETAILS } from "constants/fetch-keys";
const useEstimateOption = (estimateKey?: number | null) => {
const router = useRouter();
const { workspaceSlug, projectId } = router.query;
const { projectDetails } = useProjectDetails();
const { data: estimateDetails, error: estimateDetailsError } = useSWR(
workspaceSlug && projectId && projectDetails && projectDetails?.estimate
? ESTIMATE_DETAILS(projectDetails.estimate as string)
: null,
workspaceSlug && projectId && projectDetails && projectDetails.estimate
? () =>
estimatesService.getEstimateDetails(
workspaceSlug.toString(),
projectId.toString(),
projectDetails.estimate as string
)
: null
);
const estimateValue: any =
estimateKey || estimateKey === 0
? estimateDetails?.points?.find((e) => e.key === estimateKey)?.value
: "None";
return {
isEstimateActive: projectDetails?.estimate ? true : false,
estimatePoints: orderArrayBy(estimateDetails?.points ?? [], "key"),
estimateValue,
};
};
export default useEstimateOption;