Skip to content

Commit

Permalink
Merge pull request #159 from credebl/dashboard-and-sidebar
Browse files Browse the repository at this point in the history
fix: handled agent health for empty organization
  • Loading branch information
nishad-ayanworks authored Aug 28, 2023
2 parents a5464a1 + b26f204 commit fee165b
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions src/commonComponents/AgentHealth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const AgentHealth = () => {
const [agentHealthDetails, setAgentHealthDetails] = useState<Agent>();
const [loader, setLoader] = useState<boolean>(true);
const [agentErrMessage, setAgentErrMessage] = useState<string>('');
const [checkOrgExist, setCheckOrgExist] = useState<number>(0);

useEffect(() => {
setTimeout(() => {
Expand All @@ -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 (
<div className='pr-4'>
{loader ? (
<div>
<Spinner color="info" />
</div>
) : (
agentHealthDetails?.isInitialized ? (
<div className="inline-flex items-center bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded-full dark:bg-green-900 dark:text-green-300">
<div className="w-2 h-2 mr-1 bg-green-500 rounded-full" />
SSI Agent is up and running
</div>
) : (
<span className="inline-flex items-center bg-red-100 text-red-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded-full dark:bg-red-900 dark:text-red-300">
<span className="w-2 h-2 mr-1 bg-red-500 rounded-full" />
{/* {agentErrMessage} */}
SSI Agent is not running
</span>
)
{checkOrgExist !== 0 && (
<>
{loader ? (
<div>
<Spinner color="info" />
</div>
) : (
agentHealthDetails?.isInitialized ? (
<div className="inline-flex items-center bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded-full dark:bg-green-900 dark:text-green-300">
<div className="w-2 h-2 mr-1 bg-green-500 rounded-full" />
SSI Agent is up and running
</div>
) : (
<span className="inline-flex items-center bg-red-100 text-red-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded-full dark:bg-red-900 dark:text-red-300">
<span className="w-2 h-2 mr-1 bg-red-500 rounded-full" />
{/* {agentErrMessage} */}
SSI Agent is not running
</span>
)
)}
</>
)}
</div>

);
};

Expand Down

0 comments on commit fee165b

Please sign in to comment.