import { useEffect, useState } from "react"; import { useTenants, useSelectTenant, useLogout } from "../../hooks/useAuth.jsx"; import { Link, useNavigate } from "react-router-dom"; import Dashboard from "../../components/Dashboard/Dashboard.jsx"; import Loader from "../../components/common/Loader.jsx"; const TenantSelectionPage = () => { const [pendingTenant, setPendingTenant] = useState(null); const navigate = useNavigate(); const { data, isLoading, isError, error } = useTenants(); const { mutate: chooseTenant, isPending } = useSelectTenant(() => { navigate("/dashboard"); }); const handleTenantselection = (tenantId) => { setPendingTenant(tenantId); localStorage.setItem("ctnt", tenantId); chooseTenant(tenantId); }; const {mutate:handleLogout,isPending:isLogouting} = useLogout(()=>{}) useEffect(() => { if (localStorage.getItem("ctnt")) { navigate("/dashboard"); } }, [navigate]); useEffect(() => { if (!isLoading && data?.data?.length === 1) { const tenant = data.data[0]; handleTenantselection(tenant.id); } }, [isLoading, data]); if (isLoading) return ; if (isLoading) { return ; } if (!data?.data?.length) { return (

No tenant assigned to your account.

); } return (
{/* Logo */}
marco-logo
{/* Heading */}

Welcome

Please select which dashboard you want to explore!!!

handleLogout()}> {isLogouting ? "Please Wait...":SignOut}
{/* Card Section */}
{data?.data.map((tenant) => (
{/* Image */}
{tenant.name}
{/* Content */}
{/* Title */}

{tenant?.name}

{/* Industry */}

Industry:

{tenant?.industry?.name || "Not Available"}

{/* Description */} {tenant?.description && (

{tenant?.description}

)} {/* Button */}
))}
); }; export default TenantSelectionPage;