From b26f204899098c643a3c46fecdae4be1cdc179f3 Mon Sep 17 00:00:00 2001 From: tipusinghaw Date: Sun, 27 Aug 2023 22:50:58 +0530 Subject: [PATCH] feat: handled agent health for empty organization Signed-off-by: tipusinghaw --- src/commonComponents/AgentHealth.tsx | 61 ++++++++++++++++------------ 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/commonComponents/AgentHealth.tsx b/src/commonComponents/AgentHealth.tsx index 65ee70c16..1d8edabdc 100644 --- a/src/commonComponents/AgentHealth.tsx +++ b/src/commonComponents/AgentHealth.tsx @@ -16,6 +16,7 @@ const AgentHealth = () => { const [agentHealthDetails, setAgentHealthDetails] = useState(); const [loader, setLoader] = useState(true); const [agentErrMessage, setAgentErrMessage] = useState(''); + const [checkOrgExist, setCheckOrgExist] = useState(0); useEffect(() => { setTimeout(() => { @@ -26,42 +27,52 @@ const AgentHealth = () => { const getAgentHealthDetails = async () => { try { const organizationId = await getFromLocalStorage(storageKeys.ORG_ID); - const agentData = await getAgentHealth(Number(organizationId)); - const { data } = agentData as AxiosResponse; - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - setAgentHealthDetails(data?.data); - setLoader(false); + setCheckOrgExist(Number(organizationId)) + if (Number(organizationId) !== 0) { + const agentData = await getAgentHealth(Number(organizationId)); + const { data } = agentData as AxiosResponse; + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + setAgentHealthDetails(data?.data); + setLoader(false); + } else { + setLoader(false); + setAgentErrMessage(agentData as string); + } } else { - setLoader(false); - setAgentErrMessage(agentData as string); + console.error("Organization not created yet") } + } catch (error) { setLoader(false); console.error("An error occurred:", error); } }; - return (
- {loader ? ( -
- -
- ) : ( - agentHealthDetails?.isInitialized ? ( -
-
- SSI Agent is up and running -
- ) : ( - - - {/* {agentErrMessage} */} - SSI Agent is not running - - ) + {checkOrgExist !== 0 && ( + <> + {loader ? ( +
+ +
+ ) : ( + agentHealthDetails?.isInitialized ? ( +
+
+ SSI Agent is up and running +
+ ) : ( + + + {/* {agentErrMessage} */} + SSI Agent is not running + + ) + )} + )}
+ ); };