import React, { useEffect } from "react"; import { useQuery } from "@tanstack/react-query"; import { authService } from "@/services/authService"; import { useNavigate } from "react-router-dom"; import { Header } from "@/components/dashboard/Header"; import { Sidebar } from "@/components/dashboard/Sidebar"; import { SSLDomainContent } from "@/components/ssl-domain/SSLDomainContent"; import { LoadingState } from "@/components/services/LoadingState"; import { fetchSSLCertificates, shouldRunDailyCheck, checkAllCertificatesAndNotify, } from "@/services/sslCertificateService"; import { useLanguage } from "@/contexts/LanguageContext"; import { useSidebar } from "@/contexts/SidebarContext"; const SslDomain = () => { // Get language context for translations const { t } = useLanguage(); // Use shared sidebar state const { sidebarCollapsed, toggleSidebar } = useSidebar(); // Get current user const currentUser = authService.getCurrentUser(); const navigate = useNavigate(); // Fetch SSL certificates with error handling and debugging const { data: certificates = [], isLoading, error, refetch, } = useQuery({ queryKey: ["ssl-certificates"], queryFn: async () => { // console.log("Fetching SSL certificates from SslDomain page..."); try { const result = await fetchSSLCertificates(); // console.log("SSL certificates fetch successful, count:", result.length); return result; } catch (err) { // console.error("Error fetching SSL certificates from page:", err); throw err; } }, refetchOnWindowFocus: false, refetchInterval: 300000, // Refresh every 5 minutes retry: 3, // Retry failed requests 3 times }); // Check all SSL certificates once per day useEffect(() => { const checkCertificates = async () => { // Check if we should run daily check if (shouldRunDailyCheck()) { // console.log("Running daily SSL certificate check..."); await checkAllCertificatesAndNotify(); // Refresh certificate list after daily check refetch(); } }; // Run check when component mounts checkCertificates(); }, [refetch]); // Handle logout const handleLogout = () => { authService.logout(); navigate("/login"); }; // Show loading state while fetching data if (isLoading) { return (
{error instanceof Error ? error.message : t("unknown")}