Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

studio: show a message or error component when there are no claimants #669 #924

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions studio/src/pages/claimants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function Claimants({ permission }) {
useEffect(() => {
if (form) form.setFieldsValue(new Filters(params));
}, [params]);

React.useEffect(() => {
fetchClaimants();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
61 changes: 60 additions & 1 deletion studio/src/pages/claims/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Typography,
Tooltip,
ConfigProvider,
Result
} from 'antd';
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
import { Link, useLocation, useHistory } from 'react-router-dom';
Expand All @@ -23,6 +24,8 @@ import getUrlParams from '../../utils/getUrlParams';
import Loader from '../../components/Loader';
import { Helmet } from 'react-helmet';
import Filters from '../../utils/filters';
import { getRatings } from '../../actions/ratings';
import { getClaimants } from '../../actions/claimants';

const { Option } = Select;

Expand Down Expand Up @@ -65,6 +68,33 @@ function Claims({ permission }) {
dispatch(getClaims(params));
};

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

const fetchClaimants = () => {
dispatch(getClaimants());
};

useEffect(() => {
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 { claims, total, loading } = useSelector((state) => {
const node = state.claims.req.find((item) => {
return deepEqual(item.query, params);
Expand All @@ -86,6 +116,8 @@ function Claims({ permission }) {
return { claims: [], total: 0, loading: state.claims.loading };
});

console.log(ratingsCount, loading)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishpaul777 remove logs


const onSave = (values) => {
let searchFilter = new URLSearchParams();
Object.keys(values).forEach(function (key) {
Expand Down Expand Up @@ -115,7 +147,34 @@ function Claims({ permission }) {
});
};

return loading ? (
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>
}
/>)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishpaul777 can the case when both ratings and claimants aren't present be handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean showing both at same time ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can refactor this to have create rating and create claimants button inside and then conditionally render both or one.

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>
}
/>)
}

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