@@ -3,44 +3,63 @@ import { useQuery } from "@apollo/client";
33import { ParticipantContext } from "../../common/ParticipantContext" ;
44import { EditGoal } from "./components/EditGoal" ;
55import { SetGoal } from "./components/SetGoal" ;
6- import { GET_PARTICIPANT_BY_ID } from "../../../gql/queries" ;
6+ import {
7+ GET_PARTICIPANT_BY_ID ,
8+ GET_WEEKLY_EARNINGS ,
9+ } from "../../../gql/queries" ;
710import WeeklyEarningsChart from "./components/EarningsWidget" ;
811import BucksGoalCard from "./elements/BucksGoalCard" ;
912
1013export default function ParticipantsProgressPage ( ) {
1114 const [ editGoal , setEditGoal ] = useState ( false ) ;
1215 const [ setGoal , setSetGoal ] = useState ( false ) ;
1316 const participantContext = useContext ( ParticipantContext ) ;
14- const sampleWeeklyEarnings = [ 10 , 15 , 8 , 20 , 12 , 18 , 35 ] ;
1517
16- // Fetch participant data to get current goal
17- const { data, loading, refetch } = useQuery ( GET_PARTICIPANT_BY_ID , {
18+ // Fetch participant data
19+ const {
20+ data : participantData ,
21+ loading : loadingParticipant ,
22+ refetch : refetchParticipant ,
23+ } = useQuery ( GET_PARTICIPANT_BY_ID , {
1824 variables : { participantId : participantContext ?. id } ,
1925 skip : ! participantContext ?. id ,
2026 } ) ;
2127
22- const participant = data ?. getParticipantById ;
28+ // Fetch earnings data
29+ const {
30+ data : earningsData ,
31+ loading : loadingEarnings ,
32+ refetch : refetchEarnings ,
33+ } = useQuery ( GET_WEEKLY_EARNINGS , {
34+ variables : { participant_id : participantContext ?. id } ,
35+ skip : ! participantContext ?. id ,
36+ } ) ;
37+
38+ const weeklyEarnings = earningsData ?. getWeeklyEarnings || [
39+ 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
40+ ] ;
41+ const participant = participantData ?. getParticipantById ;
2342 const currentGoal = participant ?. marillac_bucks_goal ;
2443 const currentBalance = participant ?. marillac_bucks || 0 ;
2544
45+ const loading = loadingParticipant || loadingEarnings ;
46+
2647 const handleClose = ( ) => {
2748 setSetGoal ( false ) ;
2849 setEditGoal ( false ) ;
2950 } ;
3051
3152 const handleGoalSet = async ( ) => {
32- await refetch ( ) ; // Refresh data to show new goal
53+ await refetchParticipant ( ) ;
3354 handleClose ( ) ;
3455 } ;
3556
3657 const handleGoalUpdated = async ( ) => {
37- await refetch ( ) ; // Refresh data to show updated goal
58+ await refetchParticipant ( ) ;
3859 handleClose ( ) ;
3960 } ;
40-
41- // Don't render goal section until data is loaded to avoid flickering
4261 if ( loading ) {
43- return null ; // or return a loading spinner if preferred
62+ return null ;
4463 }
4564
4665 const handleGoalClick = ( ) => {
@@ -70,7 +89,7 @@ export default function ParticipantsProgressPage() {
7089 />
7190 ) }
7291 < div style = { { padding : "10px 20px" } } >
73- < WeeklyEarningsChart weeklyEarnings = { sampleWeeklyEarnings } />
92+ < WeeklyEarningsChart weeklyEarnings = { weeklyEarnings } />
7493 </ div >
7594 </ >
7695 ) ;
0 commit comments