import { useEffect, useState } from "react"; import { useSearchParams } from "react-router-dom"; import { supabase } from "../services/supabase"; import "./EmployeeCard.css"; function toDriveDirectUrl(url) { if (!url) return url; // Detectamos si es una URL de Google Drive if (url.includes("drive.google.com")) { // Expresión regular para extraer el ID const match = url.match(/(?:file\/d\/|id=)([a-zA-Z0-9_-]+)/); if (match) { const fileId = match[1]; // Usamos el endpoint de thumbnail que no tiene problemas de CORS return `https://drive.google.com/thumbnail?id=${fileId}&sz=w1000`; } } // Si es de BambooHR u otra URL, la devolvemos tal cual return url; } export default function EmployeeCard() { const [searchParams] = useSearchParams(); const employeeNumber = searchParams.get("id"); const [employee, setEmployee] = useState(null); const [loading, setLoading] = useState(true); const [notFound, setNotFound] = useState(false); useEffect(() => { async function loadEmployee() { const { data, error } = await supabase .rpc("get_carnet_publico", { p_cedula: employeeNumber }); if (error || !data || data.length === 0) { setNotFound(true); } else { setEmployee(data[0]); } setLoading(false); } loadEmployee(); }, [employeeNumber]); if (loading) { return (

Cargando...

); } if (notFound) { return (

Empleado no encontrado

); } console.log("1. URL original de Supabase:", employee.photo_url); // Procesamos la URL final directamente aquí const finalPhotoSrc = toDriveDirectUrl(employee.photo_url); console.log("2. URL final a renderizar:", finalPhotoSrc); const active = employee.status?.toLowerCase() === "active"; return (
{active ? "Empleado Activo" : "Empleado No Activo"}
{employee.photo_url ? ( {employee.name} ) : (
Sin foto
)}
Nombre
{employee.name}
Puesto
{employee.job_title}
País
{employee.country}
Estado
{employee.status}
); }