fix: error state is updated

This commit is contained in:
Palash gupta 2022-05-10 18:23:47 +05:30
parent b4833eeb0e
commit 574088ad54
No known key found for this signature in database
GPG Key ID: 8FD05AE6F9150AD6

View File

@ -1,6 +1,7 @@
import { notification } from 'antd';
import getAll from 'api/alerts/getAll';
import Spinner from 'components/Spinner';
import React from 'react';
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useQuery } from 'react-query';
@ -13,6 +14,14 @@ function ListAlertRules(): JSX.Element {
cacheTime: 0,
});
useEffect(() => {
if (status === 'error' || (status === 'success' && data.statusCode !== 200)) {
notification.error({
message: data?.error || t('something_went_wrong'),
});
}
}, [data?.error, data?.statusCode, status, t]);
// api failed to load the data
if (isError) {
return <div>{data?.error || t('something_went_wrong')}</div>;
@ -20,7 +29,14 @@ function ListAlertRules(): JSX.Element {
// api is successful but error is present
if (status === 'success' && data.statusCode !== 200) {
return <div>{data?.error || t('something_went_wrong')}</div>;
return (
<ListAlert
{...{
allAlertRules: [],
refetch,
}}
/>
);
}
// in case of loading