Skip to content

Commit

Permalink
CM-770: moved payment plan criteria from dialog to form
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Mar 13, 2024
1 parent bbfc064 commit 9a04a03
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 104 deletions.
38 changes: 24 additions & 14 deletions src/components/PaymentPlanHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,6 @@ class PaymentPlanHeadPanel extends FormPanel {
id="paymentPlan.headPanel.title"
/>
</Typography>
{paymentPlanType.replace(/\s+/g, '') === PAYMENT_PLAN_TYPE.BENEFIT_PLAN && (
<AdvancedCriteriaDialog
object={paymentPlan.benefitPlan}
objectToSave={paymentPlan}
moduleName="social_protection"
objectType="BenefitPlan"
setAppliedCustomFilters={this.setAppliedCustomFilters}
appliedCustomFilters={appliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
/>
)}
</Grid>
</Grid>
</Grid>
Expand Down Expand Up @@ -292,6 +278,30 @@ class PaymentPlanHeadPanel extends FormPanel {
/>
</Grid>
</Grid>
<Divider />
<Fragment>
<div className={classes.item}>
<FormattedMessage module="contributionPlan" id="paymentPlan.advancedCriteria" />
</div>
<Divider />
<Grid container className={classes.item}>
{paymentPlanType.replace(/\s+/g, '') === PAYMENT_PLAN_TYPE.BENEFIT_PLAN && (
<AdvancedCriteriaDialog
object={paymentPlan.benefitPlan}
objectToSave={paymentPlan}
moduleName="social_protection"
objectType="BenefitPlan"
setAppliedCustomFilters={this.setAppliedCustomFilters}
appliedCustomFilters={appliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
edited={this.props.edited}
/>
)}
</Grid>
</Fragment>
<Divider />
<Fragment>
<div className={classes.item}>
Expand Down
160 changes: 70 additions & 90 deletions src/dialogs/AdvancedCriteriaDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,43 @@ const AdvancedCriteriaDialog = ({
setAppliedFiltersRowStructure,
updateAttributes,
getDefaultAppliedCustomFilters,
additionalParams,
confirmed,
edited,
}) => {

const [isOpen, setIsOpen] = useState(false);
const [currentFilter, setCurrentFilter] = useState({ field: "", filter: "", type: "", value: "", amount: "" })
const [filters, setFilters] = useState(getDefaultAppliedCustomFilters());

const createParams = (moduleName, objectTypeName, uuidOfObject=null) => {
return [
const getBenefitPlanDefaultCriteria = () => {
const { jsonExt } = edited?.benefitPlan ?? {};
try {
const jsonData = JSON.parse(jsonExt);
return jsonData.advanced_criteria || [];
} catch (error) {
return [];
}
};

useEffect(() => {
if (!getDefaultAppliedCustomFilters().length) {
setFilters(getBenefitPlanDefaultCriteria());
}
}, [edited]);

const createParams = (moduleName, objectTypeName, uuidOfObject = null, additionalParams = null) => {
const params = [
`moduleName: "${moduleName}"`,
`objectTypeName: "${objectTypeName}"`,
uuidOfObject !== null ? `uuidOfObject: "${uuidOfObject}"`: ``,
];
if (uuidOfObject) {
params.push(`uuidOfObject: "${uuidOfObject}"`);
}
if (additionalParams) {
params.push(`additionalParams: ${JSON.stringify(JSON.stringify(additionalParams))}`);
}
return params;
};

const fetchFilters = (params) => fetchCustomFilter(params);
Expand All @@ -60,13 +85,6 @@ const AdvancedCriteriaDialog = ({

const handleClose = () => {
setCurrentFilter(CLEARED_STATE_FILTER);
setIsOpen(false);
};

const handleRemoveFilter = () => {
setCurrentFilter(CLEARED_STATE_FILTER);
setAppliedFiltersRowStructure([CLEARED_STATE_FILTER]);
setFilters([CLEARED_STATE_FILTER]);
};

const handleAddFilter = () => {
Expand All @@ -85,6 +103,12 @@ const AdvancedCriteriaDialog = ({
return updatedJsonExt;
}

const handleRemoveFilter = () => {
setCurrentFilter(CLEARED_STATE_FILTER);
setAppliedFiltersRowStructure([CLEARED_STATE_FILTER]);
setFilters([]);
};

const saveCriteria = () => {
setAppliedFiltersRowStructure(filters);
const outputFilters = JSON.stringify(
Expand All @@ -101,62 +125,30 @@ const AdvancedCriteriaDialog = ({
handleClose();
};


useEffect(() => {
if (object && isEmptyObject(object) === false) {
let paramsToFetchFilters = [];
if (objectType === BENEFIT_PLAN) {
paramsToFetchFilters = createParams(
moduleName,
objectType,
isBase64Encoded(object.id) ? decodeId(object.id) : object.id
isBase64Encoded(object.id) ? decodeId(object.id) : object.id,
additionalParams,
);
} else {
paramsToFetchFilters = createParams(
moduleName,
objectType,
additionalParams,
);
}
fetchFilters(paramsToFetchFilters);
}
}, [object]);

useEffect(() => {}, [filters]);

return (
<>
<Button
onClick={handleOpen}
variant="outlined"
color="#DFEDEF"
className={classes.button}
style={{
border: "0px",
textAlign: "right",
display: "block",
marginLeft: "auto",
marginRight: 0
}}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria")}
</Button>
<Dialog
open={isOpen}
onClose={handleClose}
PaperProps={{
style: {
width: 900,
maxWidth: 900,
},
}}
>
<DialogTitle
style={{
marginTop: "10px",
}}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.AdvancedCriteria")}
</DialogTitle>
<DialogContent>
{filters.map((filter, index) => {
return (<AdvancedCriteriaRowValue
customFilters={customFilters}
Expand All @@ -165,8 +157,10 @@ const AdvancedCriteriaDialog = ({
index={index}
filters={filters}
setFilters={setFilters}
readOnly={confirmed}
/>)
})}
{ !confirmed ? (
<div
style={{ backgroundColor: "#DFEDEF", paddingLeft: "10px", paddingBottom: "10px" }}
>
Expand All @@ -178,6 +172,7 @@ const AdvancedCriteriaDialog = ({
height: "16px"
}}
onClick={handleAddFilter}
disabled={confirmed}
/>
<Button
onClick={handleAddFilter}
Expand All @@ -187,59 +182,44 @@ const AdvancedCriteriaDialog = ({
"marginBottom": "6px",
fontSize: "0.8rem"
}}
disabled={confirmed}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.addFilters")}
</Button>
</div>
</DialogContent>
<DialogActions
style={{
display: "inline",
paddingLeft: "10px",
marginTop: "25px",
marginBottom: "15px"
}}
>
) : (<></>) }
<div>
<div style={{ float: "left" }}>
<Button
onClick={handleRemoveFilter}
variant="outlined"
style={{
border: "0px"
}}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.clearAllFilters")}
</Button>
</div>
<div style={{
float: "right",
paddingRight: "16px"
<div style={{ float: 'left' }}>
<Button
onClick={handleRemoveFilter}
variant="outlined"
style={{
border: '0px',
}}
disabled={confirmed}
>
<Button
onClick={handleClose}
variant="outlined"
autoFocus
style={{ margin: "0 16px" }}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.cancel")}
</Button>
<Button
onClick={saveCriteria}
variant="contained"
color="primary"
autoFocus
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.filter")}
</Button>
</div>
{formatMessage(intl, 'individual', 'paymentPlan.advancedCriteria.button.clearAllFilters')}
</Button>
</div>
<div style={{
float: 'right',
paddingRight: '16px',
}}
>
<Button
onClick={saveCriteria}
variant="contained"
color="primary"
autoFocus
disabled={!object || confirmed}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.filter")}
</Button>
</div>
</DialogActions>
</Dialog>
</>
</div>
</>
);
};
}

const mapStateToProps = (state, props) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
Expand Down
5 changes: 5 additions & 0 deletions src/dialogs/AdvancedCriteriaRowValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const AdvancedCriteriaRowValue = ({
index,
filters,
setFilters,
readOnly,
}) => {

const onAttributeChange = (attribute) => (value) => {
Expand Down Expand Up @@ -79,6 +80,7 @@ const AdvancedCriteriaRowValue = ({
return (
<SelectInput
options={BOOL_OPTIONS}
readOnly={readOnly}
{...commonProps}
/>
);
Expand All @@ -87,6 +89,7 @@ const AdvancedCriteriaRowValue = ({
<NumberInput
min={0}
displayZero
readOnly={readOnly}
{...commonProps}
/>
);
Expand All @@ -96,12 +99,14 @@ const AdvancedCriteriaRowValue = ({
return (
<PublishedComponent
pubRef="core.DatePicker"
readOnly={readOnly}
{...commonProps}
/>
);
} else {
return (
<TextInput
readOnly={readOnly}
{...commonProps}
/>
);
Expand Down

0 comments on commit 9a04a03

Please sign in to comment.