diff --git a/src/app/(auth)/dashboard/certificate/page.tsx b/src/app/(auth)/dashboard/certificate/page.tsx index eceb48a..0a97dad 100644 --- a/src/app/(auth)/dashboard/certificate/page.tsx +++ b/src/app/(auth)/dashboard/certificate/page.tsx @@ -20,9 +20,11 @@ export default function Page() { const loading = userLoading || (isInstructor ? instructorCertificatesLoading : allCertificatesLoading); const error = userError || (isInstructor ? instructorCertificatesError : allCertificatesError); - const totalPages = Math.ceil((certificates?.length || 0) / ITEMS_PER_PAGE); + // Sanitize certificates to avoid nulls and items without _id + const sanitizedCertificates = (certificates || []).filter((c: any) => c && c._id); + const totalPages = Math.ceil((sanitizedCertificates.length || 0) / ITEMS_PER_PAGE); const startIndex = (currentPage - 1) * ITEMS_PER_PAGE; - const currentCertificates = certificates?.slice(startIndex, startIndex + ITEMS_PER_PAGE) || []; + const currentCertificates = sanitizedCertificates.slice(startIndex, startIndex + ITEMS_PER_PAGE) || []; const placeholderCount = Math.max(0, ITEMS_PER_PAGE - currentCertificates.length); if (loading) { @@ -71,9 +73,9 @@ export default function Page() {
- {currentCertificates.map((certificate) => ( -
- + {currentCertificates.map((certificate: any, idx: number) => ( +
+ {certificate ? : null}
))} {Array.from({ length: placeholderCount }).map((_, idx) => (