11
2- import React from "react" ;
2+ import React , { useEffect } from "react" ;
33import { useQuery } from "@tanstack/react-query" ;
44import { authService } from "@/services/authService" ;
55import { useNavigate } from "react-router-dom" ;
66import { Header } from "@/components/dashboard/Header" ;
77import { Sidebar } from "@/components/dashboard/Sidebar" ;
88import { SSLDomainContent } from "@/components/ssl-domain/SSLDomainContent" ;
99import { LoadingState } from "@/components/services/LoadingState" ;
10+ import { fetchSSLCertificates , shouldRunDailyCheck , checkAllCertificatesAndNotify } from "@/services/sslCertificateService" ;
1011
1112const SslDomain = ( ) => {
1213 // State for sidebar collapse functionality
@@ -17,12 +18,95 @@ const SslDomain = () => {
1718 const currentUser = authService . getCurrentUser ( ) ;
1819 const navigate = useNavigate ( ) ;
1920
21+ // Fetch SSL certificates with error handling and debugging
22+ const { data : certificates = [ ] , isLoading, error, refetch } = useQuery ( {
23+ queryKey : [ 'ssl-certificates' ] ,
24+ queryFn : async ( ) => {
25+ console . log ( "Fetching SSL certificates from SslDomain page..." ) ;
26+ try {
27+ const result = await fetchSSLCertificates ( ) ;
28+ console . log ( "SSL certificates fetch successful, count:" , result . length ) ;
29+ return result ;
30+ } catch ( err ) {
31+ console . error ( "Error fetching SSL certificates from page:" , err ) ;
32+ throw err ;
33+ }
34+ } ,
35+ refetchOnWindowFocus : false ,
36+ refetchInterval : 300000 , // Refresh every 5 minutes
37+ retry : 3 , // Retry failed requests 3 times
38+ } ) ;
39+
40+ // Check all SSL certificates once per day
41+ useEffect ( ( ) => {
42+ const checkCertificates = async ( ) => {
43+ // Check if we should run daily check
44+ if ( shouldRunDailyCheck ( ) ) {
45+ console . log ( "Running daily SSL certificate check..." ) ;
46+ await checkAllCertificatesAndNotify ( ) ;
47+ // Refresh certificate list after daily check
48+ refetch ( ) ;
49+ }
50+ } ;
51+
52+ // Run check when component mounts
53+ checkCertificates ( ) ;
54+ } , [ refetch ] ) ;
55+
2056 // Handle logout
2157 const handleLogout = ( ) => {
2258 authService . logout ( ) ;
2359 navigate ( "/login" ) ;
2460 } ;
2561
62+ // Show loading state while fetching data
63+ if ( isLoading ) {
64+ return (
65+ < div className = "flex h-screen overflow-hidden bg-background text-foreground" >
66+ < Sidebar collapsed = { sidebarCollapsed } />
67+ < div className = "flex flex-col flex-1" >
68+ < Header
69+ currentUser = { currentUser }
70+ onLogout = { handleLogout }
71+ sidebarCollapsed = { sidebarCollapsed }
72+ toggleSidebar = { toggleSidebar }
73+ />
74+ < LoadingState />
75+ </ div >
76+ </ div >
77+ ) ;
78+ }
79+
80+ // Show error state
81+ if ( error ) {
82+ return (
83+ < div className = "flex h-screen overflow-hidden bg-background text-foreground" >
84+ < Sidebar collapsed = { sidebarCollapsed } />
85+ < div className = "flex flex-col flex-1" >
86+ < Header
87+ currentUser = { currentUser }
88+ onLogout = { handleLogout }
89+ sidebarCollapsed = { sidebarCollapsed }
90+ toggleSidebar = { toggleSidebar }
91+ />
92+ < div className = "flex flex-col items-center justify-center h-full p-6" >
93+ < h2 className = "text-xl font-bold mb-2" > Error Loading SSL Certificates</ h2 >
94+ < p className = "text-muted-foreground mb-4" >
95+ { error instanceof Error ? error . message : "Unknown error occurred" }
96+ </ p >
97+ < button
98+ className = "px-4 py-2 bg-primary text-primary-foreground rounded-md"
99+ onClick = { ( ) => refetch ( ) }
100+ >
101+ Retry
102+ </ button >
103+ </ div >
104+ </ div >
105+ </ div >
106+ ) ;
107+ }
108+
109+ // Render with data
26110 return (
27111 < div className = "flex h-screen overflow-hidden bg-background text-foreground" >
28112 < Sidebar collapsed = { sidebarCollapsed } />
0 commit comments