@@ -8,10 +8,24 @@ import {
88import { VolunteerDashboardLayout } from '@/components/dashboard/VolunteerDashboardLayout' ;
99import ProfileCard from '@/components/dashboard/ProfileCard' ;
1010import { getCurrentUser } from '@/APIClients/authAPIClient' ;
11+ import baseAPIClient from '@/APIClients/baseAPIClient' ;
12+
13+ interface MatchedParticipant {
14+ id : number ;
15+ name : string ;
16+ pronouns : string ;
17+ age : number ;
18+ timezone : string ;
19+ diagnosis : string ;
20+ treatments : string [ ] ;
21+ experiences : string [ ] ;
22+ initials : string ;
23+ }
1124
1225const VolunteerDashboardPage : React . FC = ( ) => {
1326 const [ userName , setUserName ] = useState ( '' ) ;
14- const [ matchedParticipants , setMatchedParticipants ] = useState ( [ ] ) ;
27+ const [ matchedParticipants , setMatchedParticipants ] = useState < MatchedParticipant [ ] > ( [ ] ) ;
28+ const [ loading , setLoading ] = useState ( true ) ;
1529
1630 useEffect ( ( ) => {
1731 const loadData = async ( ) => {
@@ -22,26 +36,72 @@ const VolunteerDashboardPage: React.FC = () => {
2236 setUserName ( firstName ) ;
2337 }
2438
25- // TODO: Fetch matched participants from API
26- // const fetchMatches = async () => {
27- // try {
28- // const response = await baseAPIClient.get('/matching/my-matches');
29- // setMatchedParticipants(response.data.matches);
30- // } catch (error) {
31- // console.error('Error fetching matches:', error);
32- // }
33- // };
34- // fetchMatches();
39+ // Fetch matched participants from API
40+ try {
41+ const response = await baseAPIClient . get ( '/matches/volunteer/me' ) ;
42+ const matches = response . data . matches || [ ] ;
43+
44+ // Filter matches that need to be scheduled (pending or awaiting_volunteer_acceptance)
45+ const matchesNeedingScheduling = matches . filter ( ( match : any ) => {
46+ const status = match . matchStatus ?. toLowerCase ( ) || '' ;
47+ return status === 'pending' || status === 'awaiting_volunteer_acceptance' ;
48+ } ) ;
49+
50+ // Transform API response to match ProfileCard format
51+ const transformedMatches = matchesNeedingScheduling . map ( ( match : any ) => {
52+ const participant = match . participant ;
53+ const firstName = participant . firstName || '' ;
54+ const lastName = participant . lastName || '' ;
55+ const fullName = `${ firstName } ${ lastName } ` . trim ( ) ;
56+
57+ return {
58+ id : match . id , // Use match ID instead of participant UUID
59+ name : fullName || participant . email ,
60+ pronouns : participant . pronouns ?. join ( '/' ) || '' ,
61+ age : participant . age || 0 ,
62+ timezone : participant . timezone || 'N/A' ,
63+ diagnosis : participant . diagnosis || 'N/A' ,
64+ treatments : participant . treatments || [ ] ,
65+ experiences : participant . experiences || [ ] ,
66+ initials : `${ firstName . charAt ( 0 ) } ${ lastName . charAt ( 0 ) } ` . toUpperCase ( ) || '?'
67+ } ;
68+ } ) ;
69+
70+ setMatchedParticipants ( transformedMatches ) ;
71+ } catch ( error ) {
72+ console . error ( 'Error fetching matches:' , error ) ;
73+ } finally {
74+ setLoading ( false ) ;
75+ }
3576 } ;
3677
3778 loadData ( ) ;
3879 } , [ ] ) ;
3980
81+ if ( loading ) {
82+ return (
83+ < VolunteerDashboardLayout >
84+ < Box display = "flex" justifyContent = "center" w = "100%" >
85+ < Box w = "711px" >
86+ < Text
87+ fontSize = "16px"
88+ color = "#6B7280"
89+ fontFamily = "'Open Sans', sans-serif"
90+ textAlign = "left"
91+ >
92+ Loading matches...
93+ </ Text >
94+ </ Box >
95+ </ Box >
96+ </ VolunteerDashboardLayout >
97+ ) ;
98+ }
99+
40100 return (
41101 < VolunteerDashboardLayout >
42102 < Box display = "flex" justifyContent = "center" w = "100%" >
43103 < Box w = "711px" >
44- < Heading
104+ < Heading
45105 fontSize = "2.25rem"
46106 fontWeight = { 600 }
47107 lineHeight = "100%"
@@ -51,29 +111,29 @@ const VolunteerDashboardPage: React.FC = () => {
51111 textAlign = "left"
52112 mb = { 2 }
53113 >
54- { matchedParticipants . length > 0
114+ { matchedParticipants . length > 0
55115 ? `Participants have matched with you, ${ userName } !`
56116 : `No New Matches${ userName ? `, ${ userName } ` : '' } `
57117 }
58118 </ Heading >
59-
60- < Text
61- fontSize = "16px"
62- color = "#6B7280"
119+
120+ < Text
121+ fontSize = "16px"
122+ color = "#6B7280"
63123 fontFamily = "'Open Sans', sans-serif"
64124 textAlign = "left"
65125 mb = { 8 }
66126 >
67- { matchedParticipants . length > 0
127+ { matchedParticipants . length > 0
68128 ? "Please schedule calls with your matches."
69129 : "Keep an eye out on your inbox! We'll notify you when we match you with a participant."
70130 }
71131 </ Text >
72132
73133 { matchedParticipants . length > 0 && (
74134 < VStack gap = { 6 } align = "flex-start" >
75- { matchedParticipants . map ( ( participant : any ) => (
76- < ProfileCard
135+ { matchedParticipants . map ( ( participant ) => (
136+ < ProfileCard
77137 key = { participant . id }
78138 participant = { participant }
79139 onScheduleCall = { ( ) => {
0 commit comments