From c8d640ebb55410ba4dea69b13439e7396b734638 Mon Sep 17 00:00:00 2001 From: Tola Leng Date: Fri, 16 May 2025 22:22:03 +0800 Subject: [PATCH] Updated SSL Domain page and API --- application/src/api/index.ts | 2 +- application/src/pages/SslDomain.tsx | 86 ++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/application/src/api/index.ts b/application/src/api/index.ts index 52190d5..ab26202 100644 --- a/application/src/api/index.ts +++ b/application/src/api/index.ts @@ -31,4 +31,4 @@ const api = { } }; -export default api; +export default api; \ No newline at end of file diff --git a/application/src/pages/SslDomain.tsx b/application/src/pages/SslDomain.tsx index e7ecdcf..0aeea86 100644 --- a/application/src/pages/SslDomain.tsx +++ b/application/src/pages/SslDomain.tsx @@ -1,5 +1,5 @@ -import React from "react"; +import React, { useEffect } from "react"; import { useQuery } from "@tanstack/react-query"; import { authService } from "@/services/authService"; import { useNavigate } from "react-router-dom"; @@ -7,6 +7,7 @@ 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"; const SslDomain = () => { // State for sidebar collapse functionality @@ -17,12 +18,95 @@ const SslDomain = () => { 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 ( +
+ +
+
+ +
+
+ ); + } + + // Show error state + if (error) { + return ( +
+ +
+
+
+

Error Loading SSL Certificates

+

+ {error instanceof Error ? error.message : "Unknown error occurred"} +

+ +
+
+
+ ); + } + + // Render with data return (