From 9139e1f6dc909bb055b8816d7c33216065890ca3 Mon Sep 17 00:00:00 2001 From: hudy9x <95471659+hudy9x@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:28:05 +0700 Subject: [PATCH] fix(goal): show an inaccurate progress percentage (#229) --- .../app/_features/Project/Vision/index.tsx | 9 ++++--- packages/ui-app/app/_hooks/useStatusUtils.ts | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/ui-app/app/_features/Project/Vision/index.tsx b/packages/ui-app/app/_features/Project/Vision/index.tsx index 684b1dfb..cdb50576 100644 --- a/packages/ui-app/app/_features/Project/Vision/index.tsx +++ b/packages/ui-app/app/_features/Project/Vision/index.tsx @@ -13,7 +13,8 @@ import VisionContainer from './VisionContainer' import './style.css' import { Vision } from '@prisma/client' import { useTaskStore } from '@/store/task' -import { useProjectStatusStore } from '@/store/status' +// import { useProjectStatusStore } from '@/store/status' +import { useStatusFuncs } from '@/hooks/useStatusUtils' const useVisionByDates = (visions: VisionField[]) => { const visionByDays: VisionByDays = {} @@ -34,7 +35,8 @@ const useVisionByDates = (visions: VisionField[]) => { const useVisionProgress = ({ visions }: { visions: VisionField[] }) => { const { tasks } = useTaskStore() - const { statusDoneId } = useProjectStatusStore() + // const { statusDoneId } = useProjectStatusStore() + const { isDoneStatus } = useStatusFuncs() // const visionProgress: { [key: string]: { total: number; done: number; assigneeIds: string[] } @@ -60,7 +62,8 @@ const useVisionProgress = ({ visions }: { visions: VisionField[] }) => { }) } - if (taskStatusId === statusDoneId) { + // if (taskStatusId === statusDoneId) { + if (isDoneStatus(taskStatusId || '')) { visionProgress[visionId].done += 1 taskDone += 1 } diff --git a/packages/ui-app/app/_hooks/useStatusUtils.ts b/packages/ui-app/app/_hooks/useStatusUtils.ts index 0f5f400d..2a4418ce 100644 --- a/packages/ui-app/app/_hooks/useStatusUtils.ts +++ b/packages/ui-app/app/_hooks/useStatusUtils.ts @@ -41,3 +41,29 @@ export const useStatusUtils = () => { getStatusTypeByTaskId, } } + + +export const useStatusFuncs = () => { + + const { statuses } = useProjectStatusStore() + + const doneStatus = useMemo(() => { + const doneIds: string[] = [] + statuses.forEach(stt => { + if (stt.type === StatusType.DONE) { + doneIds.push(stt.id) + } + }) + + return doneIds + }, [statuses.toString()]) + + const isDoneStatus = (statusId: string) => { + return doneStatus.includes(statusId) + } + + + return { + isDoneStatus, + } +}