Skip to content

Commit

Permalink
adds requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 authored May 23, 2024
1 parent 1521be2 commit f928b53
Showing 1 changed file with 56 additions and 37 deletions.
93 changes: 56 additions & 37 deletions studio/src/pages/claims/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Typography,
Tooltip,
ConfigProvider,
Result
Result,
} from 'antd';
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
import { Link, useLocation, useHistory } from 'react-router-dom';
Expand Down Expand Up @@ -78,22 +78,24 @@ function Claims({ permission }) {
};

useEffect(() => {
fetchRatings()
fetchRatings();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, []);

const fetchRatings = () => {
dispatch(getRatings());
}

const { claimantsCount, ratingsCount, claimantsLoading } = useSelector(({ claimants, ratings }) => {
return {
claimantsCount: claimants?.req?.[0]?.data ? claimants?.req?.[0]?.data.length : 0,
ratingsCount: Object.keys(ratings.details).length,
claimantsLoading: claimants.loading
};
});
};

const { claimantsCount, ratingsCount, claimantsLoading, ratingsLoading } = useSelector(
({ claimants, ratings }) => {
return {
claimantsCount: claimants?.req?.[0]?.data ? claimants?.req?.[0]?.data.length : 0,
ratingsCount: Object.keys(ratings.details).length,
claimantsLoading: claimants.loading,
ratingsLoading: ratings.loading,
};
},
);

const { claims, total, loading } = useSelector((state) => {
const node = state.claims.req.find((item) => {
Expand Down Expand Up @@ -145,34 +147,51 @@ function Claims({ permission }) {
});
};

if (!loading && !claimantsLoading && claimantsCount === 0){
return (
<Result
status={'403'}
title={'Please create a claimant.'}
subTitle="You cannot create a claim without a claimant."
extra={
<Link to="/claimants/create">
<Button type="primary">Create claimant</Button>
</Link>
}
/>)
}
if (
(!loading && !claimantsLoading && claimantsCount === 0) ||
(!ratingsLoading && ratingsCount === 0)
) {
const isRatingsCountZero = !ratingsLoading && ratingsCount === 0;
const isClaimantsCountZero = !claimantsLoading && claimantsCount === 0;

if (!loading && ratingsCount === 0){
return (<Result
status={'403'}
title={'Please create Ratings.'}
subTitle="You cannot create a claim without a ratings."
extra={
<Link to="/ratings/create">
<Button type="primary">Create Ratings</Button>
</Link>
}
/>)
const title =
isClaimantsCountZero && isRatingsCountZero
? 'No claimants and ratings found'
: isClaimantsCountZero
? 'No claimants found'
: 'No ratings found';

const subTitle =
isClaimantsCountZero && isRatingsCountZero
? 'Create claimants and ratings first to create claims'
: isClaimantsCountZero
? 'Create claimants to first to create claims'
: 'Create ratings first to create claims';

const extra =
isClaimantsCountZero && isRatingsCountZero ? (
<Space align="center" direction="horizontal">
<Link to="/claimants/create">
<Button type="primary">Create claimant</Button>
</Link>
<Link to="/ratings/create">
<Button type="primary">Create Ratings</Button>
</Link>
</Space>
) : isClaimantsCountZero ? (
<Link to="/claimants/create">
<Button type="primary">Create claimant</Button>
</Link>
) : (
<Link to="/ratings/create">
<Button type="primary">Create Ratings</Button>
</Link>
);

return <Result status={'403'} title={title} subTitle={subTitle} extra={extra} />;
}

return (loading) ? (
return loading ? (
<Loader />
) : (
<Space direction="vertical">
Expand Down

0 comments on commit f928b53

Please sign in to comment.