Skip to content

Commit e7aa0d2

Browse files
committed
Displays project.allowsMultipleEnrollments field
and it use for project create and update
1 parent 2eeb1a7 commit e7aa0d2

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const PROJECT_FULL_PROJECTION = (modulesManager) => [
7878
'workingDays',
7979
'activity {id, name}',
8080
'location' + modulesManager.getProjection('location.Location.FlatProjection'),
81+
'allowsMultipleEnrollments',
8182
'isDeleted',
8283
'userUpdated {username}',
8384
'version',
@@ -330,6 +331,8 @@ function formatProjectGQL(project) {
330331
${project?.name ? `name: "${formatGQLString(project.name)}"` : ''}
331332
${project?.targetBeneficiaries ? `targetBeneficiaries: ${project.targetBeneficiaries}` : ''}
332333
${project?.workingDays ? `workingDays: ${project.workingDays}` : ''}
334+
${(project?.allowsMultipleEnrollments !== undefined && project.allowsMultipleEnrollments !== null)
335+
? `allowsMultipleEnrollments: ${project.allowsMultipleEnrollments}` : ''}
333336
${project?.status ? `status: "${project.status}"` : ''}
334337
${project?.activity?.id ? `activityId: "${project.activity.id}"` : ''}
335338
${project?.location?.uuid ? `locationId: "${project.location.uuid}"` : ''}

src/components/ProjectHeadPanel.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '../actions';
1919
import ProjectStatusPicker from '../pickers/ProjectStatusPicker';
2020
import ActivityPicker from '../pickers/ActivityPicker';
21+
import ProjectAllowsMultiEnrollmentPicker from '../pickers/ProjectAllowsMultiEnrollmentPicker';
2122

2223
const styles = (theme) => ({
2324
item: theme.paper.item,
@@ -116,6 +117,16 @@ class ProjectHeadPanel extends FormPanel {
116117
/>
117118
</Grid>
118119

120+
<Grid item xs={4} className={classes.item}>
121+
<ProjectAllowsMultiEnrollmentPicker
122+
label="project.allowsMultipleEnrollments"
123+
value={project?.allowsMultipleEnrollments ?? false}
124+
onChange={(v) => this.updateAttribute('allowsMultipleEnrollments', v)}
125+
readOnly={readOnly}
126+
required={false}
127+
/>
128+
</Grid>
129+
119130
<Grid item xs={4} className={classes.item}>
120131
<ProjectStatusPicker
121132
required
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React, { useEffect } from 'react';
2+
import { formatMessage } from '@openimis/fe-core';
3+
import { injectIntl } from 'react-intl';
4+
import { withTheme, withStyles } from '@material-ui/core/styles';
5+
import {
6+
Select,
7+
InputLabel,
8+
FormControl,
9+
MenuItem,
10+
} from '@material-ui/core';
11+
import {
12+
MODULE_NAME,
13+
} from '../constants';
14+
15+
const styles = (theme) => ({
16+
label: {
17+
color: theme.palette.primary.main,
18+
},
19+
formControl: {
20+
position: 'relative',
21+
},
22+
});
23+
24+
function ProjectAllowsMultiEnrollmentPicker({
25+
intl,
26+
classes,
27+
value,
28+
label,
29+
onChange,
30+
required,
31+
readOnly = false,
32+
withNull = false,
33+
nullLabel = null,
34+
}) {
35+
const options = [
36+
{ value: true, label: formatMessage(intl, MODULE_NAME, 'common.true') },
37+
{ value: false, label: formatMessage(intl, MODULE_NAME, 'common.false') },
38+
];
39+
40+
const handleChange = (e) => {
41+
if (value !== e.target.value) {
42+
onChange(e.target.value);
43+
}
44+
};
45+
46+
useEffect(() => {
47+
if (withNull) {
48+
options.unshift({
49+
value: null,
50+
label: nullLabel || formatMessage(intl, MODULE_NAME, 'common.any'),
51+
});
52+
}
53+
}, []);
54+
55+
return (
56+
<FormControl required={required} fullWidth className={classes.formControl}>
57+
<InputLabel shrink className={classes.label}>
58+
{formatMessage(intl, MODULE_NAME, label)}
59+
</InputLabel>
60+
<Select
61+
readOnly={readOnly}
62+
options={options}
63+
value={value}
64+
onChange={handleChange}
65+
>
66+
{options.map((option) => (
67+
<MenuItem value={option.value}>
68+
{option.label}
69+
</MenuItem>
70+
))}
71+
</Select>
72+
</FormControl>
73+
);
74+
}
75+
76+
export default injectIntl(withTheme(withStyles(styles)(ProjectAllowsMultiEnrollmentPicker)));

src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"mutationLabel": "Enrolled {n} beneficiaries in project {name}"
214214
},
215215
"isDeleted": "Show Deleted",
216+
"allowsMultipleEnrollments": "Allow beneficiaries to enroll in multiple projects",
216217
"searcherResultsTitleHistory": "{projectsHistoryTotalCount} Historical Records Found",
217218
"version": "Version",
218219
"dateUpdated": "Date Updated",

0 commit comments

Comments
 (0)