@@ -172,6 +172,17 @@ const [employeeDataResponse, setEmployeeDataResponse] = useState<any[]>([]);
172172 const allCompletedCourseIds = Array . from ( new Set ( [ ...completedMandatoryCourseIds , ...completedOptionalCourseIds ] ) ) ;
173173 console . log ( 'Unique Completed Course IDs (duplicates removed):' , allCompletedCourseIds ) ;
174174
175+ // If no completed courses, set empty top performers data and return
176+ if ( allCompletedCourseIds . length === 0 ) {
177+ console . log ( 'No completed courses found, setting empty top performers data' ) ;
178+ setTopPerformersData ( {
179+ usersData : {
180+ '5 Highest Course Completing Users' : [ ]
181+ }
182+ } ) ;
183+ return ;
184+ }
185+
175186 // Collect structured course data from all completed courses
176187 const getAllStructuredCourseData = async ( ) => {
177188 const allStructuredData : Array < { courseId : string , units : Array < { unitId : string , contentIds : string [ ] } > } > = [ ] ;
@@ -288,7 +299,11 @@ const [employeeDataResponse, setEmployeeDataResponse] = useState<any[]>([]);
288299
289300 console . log ( 'individualProgressData' , apiResponse ?. getUserDetails ) ;
290301 console . log ( 'totalCount' , apiResponse ?. totalCount ) ;
291- const currentEmployeeIds = apiResponse ?. getUserDetails ?. map ( ( item : any ) => item . userId ) ;
302+ // Handle empty array or undefined getUserDetails
303+ const userDetails = apiResponse ?. getUserDetails || [ ] ;
304+ const currentEmployeeIds = userDetails . length > 0
305+ ? userDetails . map ( ( item : any ) => item . userId )
306+ : [ ] ;
292307
293308 // Fetch certificate status for current employees if course identifiers are available
294309 let userMandatoryCertificateStatus = { data : [ ] } ;
@@ -377,7 +392,8 @@ const [employeeDataResponse, setEmployeeDataResponse] = useState<any[]>([]);
377392 } ) ;
378393
379394 // Transform API data to EmployeeProgress format with calculated progress
380- const transformedProgressData : EmployeeProgress [ ] = apiResponse ?. getUserDetails ?. map ( ( user : any ) => {
395+ const transformedProgressData : EmployeeProgress [ ] = userDetails . length > 0
396+ ? userDetails . map ( ( user : any ) => {
381397 const mandatoryStats = mandatoryStatusMap . get ( user . userId ) || {
382398 completed : 0 ,
383399 inProgress : 0 ,
@@ -424,7 +440,8 @@ const [employeeDataResponse, setEmployeeDataResponse] = useState<any[]>([]);
424440 mandatoryCompletedIdentifiers : mandatoryStats . completedIdentifiers || [ ] ,
425441 optionalCompletedIdentifiers : optionalStats . completedIdentifiers || [ ]
426442 } ;
427- } ) || [ ] ;
443+ } )
444+ : [ ] ;
428445
429446
430447 console . log ( 'transformedProgressData with calculated progress' , transformedProgressData ) ;
@@ -526,9 +543,14 @@ const [employeeDataResponse, setEmployeeDataResponse] = useState<any[]>([]);
526543 filters : { emp_manager :userId } ,
527544 } ) ;
528545 console . log ( 'employeeDataResponse' , employeeDataResponse ) ;
529- setEmployeeDataResponse ( employeeDataResponse ?. getUserDetails || [ ] ) ;
530- employeeUserIds = employeeDataResponse ?. getUserDetails ?. map ( ( item : any ) => item . userId ) ;
531- setEmployeeUserIds ( employeeUserIds ) ;
546+
547+ // Handle empty array or undefined getUserDetails
548+ const employeeDetails = employeeDataResponse ?. getUserDetails || [ ] ;
549+ setEmployeeDataResponse ( employeeDetails ) ;
550+ employeeUserIds = employeeDetails . length > 0
551+ ? employeeDetails . map ( ( item : any ) => item . userId )
552+ : [ ] ;
553+ setEmployeeUserIds ( employeeUserIds ) ;
532554 }
533555 console . log ( 'employeeUserIds' , employeeUserIds ) ;
534556 // Check if tenantId is available before calling certificate status APIs
0 commit comments