Skip to content

Commit

Permalink
Group beneficiary fetches & displays the isEligible field
Browse files Browse the repository at this point in the history
also provide the UI to search by the field
  • Loading branch information
weilu committed Aug 27, 2024
1 parent 56104f7 commit 7cd50f8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const GROUP_BENEFICIARY_FULL_PROJECTION = () => [
'id',
'group {id, code, head {uuid}}',
'status',
'isEligible',
];

const WORKFLOWS_FULL_PROJECTION = () => [
Expand Down
33 changes: 27 additions & 6 deletions src/components/BenefitPlanGroupBeneficiariesFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import React from 'react';
import { injectIntl } from 'react-intl';
import { Grid } from '@material-ui/core';
import { withTheme, withStyles } from '@material-ui/core/styles';
import { formatMessage, TextInput } from '@openimis/fe-core';
import { formatMessage, TextInput, ConstantBasedPicker } from '@openimis/fe-core';
import _debounce from 'lodash/debounce';
import { defaultFilterStyles } from '../util/styles';
import BeneficiaryStatusPicker from '../pickers/BeneficiaryStatusPicker';
import { DEFAULT_DEBOUNCE_TIME, EMPTY_STRING } from '../constants';

function BenefitPlanBeneficiariesFilter({
intl, classes, filters, onChangeFilters, readOnly,
function BenefitPlanGroupBeneficiariesFilter({
intl, classes, filters, onChangeFilters, readOnly, status,
}) {
const any = formatMessage(intl, 'socialProtection', 'any');

const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFAULT_DEBOUNCE_TIME);

const filterTextFieldValue = (filterName) => filters?.[filterName]?.value ?? EMPTY_STRING;
Expand Down Expand Up @@ -42,8 +44,8 @@ function BenefitPlanBeneficiariesFilter({
label="beneficiary.beneficiaryStatusPicker"
withNull
readOnly={readOnly}
nullLabel={formatMessage(intl, 'socialProtection', 'any')}
value={filterValue('status')}
nullLabel={any}
value={status || filterValue('status')}
onChange={(value) => onChangeFilters([
{
id: 'status',
Expand All @@ -53,10 +55,29 @@ function BenefitPlanBeneficiariesFilter({
])}
/>
</Grid>
{status && (
<Grid item xs={2} className={classes.item}>
<ConstantBasedPicker
module="socialProtection"
label="beneficiary.isEligible"
constants={['true', 'false']}
withNull
nullLabel={any}
value={filterValue('isEligible')}
onChange={(value) => onChangeFilters([
{
id: 'isEligible',
value,
filter: `isEligible: ${value}`,
},
])}
/>
</Grid>
)}
</Grid>
);
}

export default injectIntl(withTheme(withStyles(defaultFilterStyles)(
BenefitPlanBeneficiariesFilter,
BenefitPlanGroupBeneficiariesFilter,
)));
31 changes: 27 additions & 4 deletions src/components/BenefitPlanGroupBeneficiariesSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
DialogContent,
} from '@material-ui/core';
import PreviewIcon from '@material-ui/icons/ListAlt';
import ErrorIcon from '@material-ui/icons/Error';
import CheckCircleIcon from '@material-ui/icons/CheckCircleOutline';
import {
fetchGroupBeneficiaries, downloadGroupBeneficiaries, clearGroupBeneficiaryExport, updateGroupBeneficiary,
} from '../actions';
Expand Down Expand Up @@ -61,10 +63,20 @@ function BenefitPlanGroupBeneficiariesSearcher({

const fetch = (params) => fetchGroupBeneficiaries(params);

const headers = () => [
'socialProtection.groupBeneficiary.code',
'socialProtection.groupBeneficiary.status',
];
const headers = () => {
const baseHeaders = [
'socialProtection.groupBeneficiary.code',
'socialProtection.groupBeneficiary.status',
];

if (status) {
baseHeaders.push('socialProtection.beneficiary.isEligible');
}

baseHeaders.push('');

return baseHeaders;
};

const openBenefitPackage = (groupBeneficiary) => history.push(`${benefitPlan?.id}/`
+ `${modulesManager.getRef('socialProtection.route.benefitPackage')}`
Expand Down Expand Up @@ -112,6 +124,16 @@ function BenefitPlanGroupBeneficiariesSearcher({
) : groupBeneficiary.status),
];

if (status) {
const yes = formatMessage(intl, 'socialProtection', 'beneficiary.isEligible.true');
const no = formatMessage(intl, 'socialProtection', 'beneficiary.isEligible.false');
result.push((beneficiary) => (
beneficiary.isEligible
? <Tooltip title={yes} placement="right"><CheckCircleIcon aria-label={yes} /></Tooltip>
: <Tooltip title={no} placement="right"><ErrorIcon aria-label={no} /></Tooltip>
));
}

if (rights.includes(RIGHT_GROUP_SEARCH)) {
result.push((groupBeneficiary) => (
<Tooltip title={formatMessage(intl, 'socialProtection', 'benefitPackage.overviewButtonTooltip')}>
Expand Down Expand Up @@ -185,6 +207,7 @@ function BenefitPlanGroupBeneficiariesSearcher({
filters={props.filters}
onChangeFilters={props.onChangeFilters}
readOnly={readOnly}
status={status}
/>
);

Expand Down

0 comments on commit 7cd50f8

Please sign in to comment.