Skip to content

Commit

Permalink
Merge pull request #57 from openimis/feature/CM-986
Browse files Browse the repository at this point in the history
CM-986: added viewing extra data on benefit level
  • Loading branch information
jdolkowski authored Aug 7, 2024
2 parents c23d4c0 + 81266b2 commit e850387
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/components/payroll/BenefitConsumptionSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PhotoCameraOutlinedIcon from '@material-ui/icons/PhotoCameraOutlined';
import { fetchBenefitConsumptions } from '../../actions';
import { BENEFIT_CONSUMPTION_STATUS, DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS } from '../../constants';
import BenefitConsumptionFilter from './BenefitConsumptionFilter';
import AdditionalFieldsDialog from './dialogs/AdditionalFieldsDialog';

function BenefitConsumptionSearcher({
fetchBenefitConsumptions,
Expand Down Expand Up @@ -39,6 +40,7 @@ function BenefitConsumptionSearcher({
'benefitConsumption.status',
'benefitConsumption.payedOnTime',
'benefitConsumption.paymentDate',
'',
];

const checkBenefitDueDate = (benefitConsumption) => {
Expand Down Expand Up @@ -74,6 +76,11 @@ function BenefitConsumptionSearcher({
? ''
: benefitConsumption?.benefitAttachment[0]?.bill?.datePayed
),
(benefitConsumption) => (
<AdditionalFieldsDialog
jsonExt={benefitConsumption?.jsonExt}
/>
),
];

const rowIdentifier = (benefitConsumption) => benefitConsumption.id;
Expand Down
7 changes: 7 additions & 0 deletions src/components/payroll/BenefitConsumptionSearcherModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import BenefitConsumptionFilterModal from './BenefitConsumptionFilterModal';
import ErrorSummaryModal from './dialogs/ErrorSummaryModal';
import { mutationLabel } from '../../utils/string-utils';
import AdditionalFieldsDialog from './dialogs/AdditionalFieldsDialog';

function BenefitConsumptionSearcherModal({
fetchBenefitAttachments,
Expand Down Expand Up @@ -86,6 +87,7 @@ function BenefitConsumptionSearcherModal({
'benefitConsumption.paymentDate',
'benefitConsumption.status',
'',
'',
];

const confirmDeleteBenefitConsumption = (benefit) => {
Expand Down Expand Up @@ -132,6 +134,11 @@ function BenefitConsumptionSearcherModal({
: benefitAttachment?.bill?.datePayed
),
(benefitAttachment) => benefitAttachment?.benefit?.status,
(benefitAttachment) => (
<AdditionalFieldsDialog
jsonExt={benefitAttachment?.benefit?.jsonExt}
/>
),
(benefitAttachment) => (
<Button
onClick={() => {}}
Expand Down
131 changes: 131 additions & 0 deletions src/components/payroll/dialogs/AdditionalFieldsDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React, { useState } from 'react';
import { Grid } from '@material-ui/core';
import { injectIntl } from 'react-intl';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import {
formatMessage,
renderInputComponent,
createFieldsBasedOnJSON,
} from '@openimis/fe-core';
import { withTheme, withStyles } from '@material-ui/core/styles';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { MODULE_NAME } from '../../../constants';

const styles = (theme) => ({
item: theme.paper.item,
});

function AdditionalFieldsDialog({
intl,
classes,
jsonExt,
}) {
// eslint-disable-next-line no-param-reassign
if (!jsonExt) jsonExt = '{}';
const [isOpen, setIsOpen] = useState(false);

const handleOpen = () => {
setIsOpen(true);
};

const handleClose = () => {
setIsOpen(false);
};
const jsonExtFields = createFieldsBasedOnJSON(JSON.stringify(JSON.parse(jsonExt).extra_info));

return (
<>
<Button
onClick={handleOpen}
variant="outlined"
color="#DFEDEF"
className={classes.button}
style={{
border: '0px',
marginTop: '6px',
}}
>
{formatMessage(intl, 'payroll', 'payroll.additonalFields.showAdditionalFields')}
</Button>
<Dialog
open={isOpen}
onClose={handleClose}
PaperProps={{
style: {
width: 1200,
maxWidth: 1200,
maxHeight: 900,
},
}}
>
<form noValidate>
<DialogTitle
style={{
marginTop: '10px',
}}
>
{formatMessage(intl, 'payroll', 'payroll.additonalFields.label')}
</DialogTitle>
<DialogContent>
<div
style={{ backgroundColor: '#DFEDEF', paddingLeft: '10px', paddingBottom: '10px' }}
>
<Grid container className={classes.item}>
{jsonExtFields?.map((jsonExtField) => (
<Grid item xs={6} className={classes.item}>
{renderInputComponent(MODULE_NAME, jsonExtField)}
</Grid>
))}
</Grid>
</div>
</DialogContent>
<DialogActions
style={{
display: 'inline',
paddingLeft: '10px',
marginTop: '25px',
marginBottom: '15px',
}}
>
<div style={{ maxWidth: '1000px' }}>
<div style={{ float: 'left' }}>
<Button
onClick={handleClose}
variant="outlined"
autoFocus
style={{
margin: '0 16px',
marginBottom: '15px',
}}
>
{formatMessage(intl, 'payroll', 'payroll.additonalFields.close')}
</Button>
</div>
<div style={{ float: 'right', paddingRight: '16px' }} />
</div>
</DialogActions>
</form>
</Dialog>
</>
);
}

const mapStateToProps = (state) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
}, dispatch);

export default injectIntl(
withTheme(
withStyles(styles)(
connect(mapStateToProps, mapDispatchToProps)(AdditionalFieldsDialog),
),
),
);
6 changes: 5 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,9 @@
"payroll.benefitConsumption.confirm": "Confirm",
"payroll.benefitConsumption.cancel": "Cancel",
"payroll.benefitConsumption.delete.confirm.title": "Delete Benefit Consumption",
"payroll.benefitConsumption.delete.confirm.message": "Are you sure you want to delete the Benefit Consumption? Once you click confirm, additional approval on the task level is required to permanently delete it."
"payroll.benefitConsumption.delete.confirm.message": "Are you sure you want to delete the Benefit Consumption? Once you click confirm, additional approval on the task level is required to permanently delete it.",

"payroll.additonalFields.label": "Additional Fields",
"payroll.additonalFields.showAdditionalFields": "Show Additional Fields",
"payroll.additonalFields.close": "Close"
}

0 comments on commit e850387

Please sign in to comment.