Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/app/(auth)/dashboard/certificate/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -71,9 +73,9 @@ export default function Page() {
</div>

<div className='grid grid-cols-1 md:grid-cols-3 gap-6'>
{currentCertificates.map((certificate) => (
<div key={certificate._id} className="min-h-[430px]">
<CertificateCard certificate={certificate} />
{currentCertificates.map((certificate: any, idx: number) => (
<div key={certificate?._id || `cert-${startIndex + idx}`} className="min-h-[430px]">
{certificate ? <CertificateCard certificate={certificate} /> : null}
</div>
))}
{Array.from({ length: placeholderCount }).map((_, idx) => (
Expand Down
Loading