// src/pages/intern/SertificatePage.tsx import { useMemo } from "react"; import { useParams, useLocation } from "react-router-dom"; import CertificateAvailable from "./components/CertificateAvailabe"; import CertificateNotAvailable from "./components/CertificateNotAvailable"; import SertificateHistory from "./components/CertificateHistory"; import { useProjectDetail } from "../../../hooks/useProjects"; import { useMyCertificates } from "../../../hooks/useCertificates"; import type { Project } from "../../../types/project.types"; export default function InternCertificateDetail() { const { slug } = useParams<{ slug: string }>(); const location = useLocation(); const projectFromList = location.state?.project as Project | undefined; const { project: projectDetail, loading: projectLoading } = useProjectDetail(slug ?? ""); const { certificates, loading: certLoading } = useMyCertificates(); const myCertificateForProject = useMemo(() => { if (!projectDetail) return null; return certificates.find((cert) => cert.id_project === projectDetail.id); }, [projectDetail, certificates]); const project = useMemo(() => { if (!projectDetail) return null; return { ...projectDetail, task_done: projectFromList?.task_done ?? 0, total_tasks: projectFromList?.total_tasks ?? projectDetail.total_tasks, }; }, [projectDetail, projectFromList]); const allTasksDone = !projectLoading && !!project && (project.total_tasks ?? 0) > 0 && project.task_done >= project.total_tasks; const progress = project && project.total_tasks > 0 ? Math.round((project.task_done / project.total_tasks) * 100) : 0; const remainingTasks = project ? project.total_tasks - project.task_done : 0; const isLoading = projectLoading || certLoading; if (isLoading) { return (

Certificates

View and download internship certificates

); } return (

Certificates

View and download internship certificates

{myCertificateForProject && (project?.total_tasks ?? 0) > 0 ? ( ) : ( )}
); };