1+ import { eventBus } from "src/core/utils/eventBus"
12import { useQuery } from "@blitzjs/rpc"
3+ import React , { useEffect , useRef } from "react"
24import "react-circular-progressbar/dist/styles.css"
35import { Milestone } from "@prisma/client"
46import { completedTaskPercentage } from "src/widgets/utils/completedTaskPercentage"
@@ -18,25 +20,20 @@ interface MilestoneSummaryProps {
1820
1921export const MilestoneSummary : React . FC < MilestoneSummaryProps > = ( { milestone, projectId } ) => {
2022 // Get tasks
21- const [ { tasks } ] = useQuery ( getTasks , {
22- include : {
23- roles : true ,
24- } ,
25- where : {
26- projectId : projectId ,
27- milestoneId : milestone . id ,
28- } ,
23+ const taskQuery = useQuery ( getTasks , {
24+ include : { roles : true } ,
25+ where : { projectId : projectId , milestoneId : milestone . id } ,
2926 } )
27+ const [ { tasks } , { refetch : refetchTasks } ] = taskQuery
3028
3129 // get taskLogs for those tasks
32- const [ fetchedTaskLogs ] = useQuery ( getTaskLogs , {
30+ const taskLogsQuery = useQuery ( getTaskLogs , {
3331 where : {
3432 taskId : { in : tasks . map ( ( task ) => task . id ) } ,
3533 } ,
36- include : {
37- task : true ,
38- } ,
39- } ) as unknown as TaskLogWithTask [ ]
34+ include : { task : true } ,
35+ } )
36+ const [ fetchedTaskLogs , { refetch : refetchLogs } ] = taskLogsQuery as any
4037
4138 // Cast and handle the possibility of `undefined`
4239 const taskLogs : TaskLogWithTask [ ] = ( fetchedTaskLogs ?? [ ] ) as TaskLogWithTask [ ]
@@ -49,6 +46,16 @@ export const MilestoneSummary: React.FC<MilestoneSummaryProps> = ({ milestone, p
4946 const taskPercent = completedTaskPercentage ( tasks )
5047 const rolePercent = completedRolePercentage ( tasks )
5148
49+ // Listen for custom event to refetch tasks/logs
50+ useEffect ( ( ) => {
51+ const handler = ( ) => {
52+ void refetchTasks ( )
53+ void refetchLogs ( )
54+ }
55+ eventBus . on ( "milestoneTasksUpdated" , handler )
56+ return ( ) => eventBus . off ( "milestoneTasksUpdated" , handler )
57+ } , [ refetchTasks , refetchLogs ] )
58+
5259 return (
5360 < CollapseCard title = "Milestone Statistics" className = "mt-4" >
5461 < div className = "stats flex justify-between items-center gap-4 bg-base-300 text-lg font-bold" >
0 commit comments