// 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 { useClaimCertificate } from "../../../hooks/useCertificates"; 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, refetch: refetchCertificates } = useMyCertificates(); // const { claim, loading: claiming, error: claimError } = useClaimCertificate(); 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.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; // const handleClaim = async () => { // if (!project?.id) return; // const result = await claim(project.id); // if (result) { // refetchCertificates(); // } // }; if (isLoading) { return (
Memuat Data...
); } return (

Certificates

View and download internship certificates

{myCertificateForProject ? ( ) : ( )}
); };