diff --git a/src/actions.js b/src/actions.js index 1162b72..daad912 100644 --- a/src/actions.js +++ b/src/actions.js @@ -62,7 +62,7 @@ const PAYMENTPLAN_FULL_PROJECTION = (modulesManager) => [ "isDeleted", ]; -const PAYMENTPLAN_PICKER_PROJECTION = () => ["id", "code", "name"]; +const PAYMENTPLAN_PICKER_PROJECTION = () => ["id", "code", "name", "benefitPlan"]; function dateTimeToDate(date) { return date.split("T")[0]; diff --git a/src/components/PaymentPlanForm.js b/src/components/PaymentPlanForm.js index 624c1ed..d385498 100644 --- a/src/components/PaymentPlanForm.js +++ b/src/components/PaymentPlanForm.js @@ -1,4 +1,4 @@ -import React, { Component, Fragment } from "react"; +import React, { Component } from "react"; import { Form, withModulesManager, @@ -22,6 +22,7 @@ const styles = theme => ({ paperHeader: theme.paper.header, paperHeaderAction: theme.paper.action, item: theme.paper.item, + lockedPage: theme.page.locked, }); class PaymentPlanForm extends Component { @@ -31,6 +32,7 @@ class PaymentPlanForm extends Component { paymentPlan: {}, jsonExtValid: true, requiredValid: false, + clientMutationId: null, }; } @@ -48,6 +50,9 @@ class PaymentPlanForm extends Component { } if (prevProps.submittingMutation && !this.props.submittingMutation) { this.props.journalize(this.props.mutation); + this.setState((state, props) => ({ + clientMutationId: props.mutation.clientMutationId, + })); } } @@ -96,9 +101,17 @@ class PaymentPlanForm extends Component { setRequiredValid = (valid) => this.setState({ requiredValid: !!valid }); render() { - const { intl, back, paymentPlanId, title, save, isReplacing = false } = this.props; + const { + intl, + back, + paymentPlanId, + save, + isReplacing = false, + classes, + } = this.props; + const shouldBeLocked = Boolean(this.state.clientMutationId); return ( - + - + ) } } diff --git a/src/components/PaymentPlanHeadPanel.js b/src/components/PaymentPlanHeadPanel.js index 777ef84..733ed0a 100644 --- a/src/components/PaymentPlanHeadPanel.js +++ b/src/components/PaymentPlanHeadPanel.js @@ -1,5 +1,5 @@ import React, { Fragment } from "react"; -import { Grid, Divider, Typography } from "@material-ui/core"; +import { Grid, Divider, Typography, Button } from "@material-ui/core"; import { withModulesManager, formatMessage, @@ -130,6 +130,7 @@ class PaymentPlanHeadPanel extends FormPanel { isCodeValid, isCodeValidating, validationError, + readOnly = false, } = this.props; const { benefitPlan: productOrBenefitPlan, calculation: calculationId, ...others } = this.props.edited; @@ -138,11 +139,17 @@ class PaymentPlanHeadPanel extends FormPanel { const paymentPlanType = paymentPlan?.benefitPlanTypeName; const { appliedCustomFilters, appliedFiltersRowStructure } = this.state; + const isBenefitPlanType = () => paymentPlanType.replace(/\s+/g, '') === PAYMENT_PLAN_TYPE.BENEFIT_PLAN; + if (paymentPlanType) { // probably could get rid of that if we use double JSON.parse in reducer const objectBenefitPlan = typeof paymentPlan.productOrBenefitPlan === 'object' ? paymentPlan.productOrBenefitPlan : JSON.parse(paymentPlan.productOrBenefitPlan || '{}'); paymentPlan.benefitPlan = objectBenefitPlan; + if (paymentPlanType === 'benefitplan' || paymentPlanType === 'benefit plan') { + paymentPlan.periodicity = 1; + this.state.data.periodicity = paymentPlan.periodicity; + } return ( @@ -161,20 +168,6 @@ class PaymentPlanHeadPanel extends FormPanel { id="paymentPlan.headPanel.title" /> - {paymentPlanType.replace(/\s+/g, '') === PAYMENT_PLAN_TYPE.BENEFIT_PLAN && ( - - )} @@ -188,12 +181,35 @@ class PaymentPlanHeadPanel extends FormPanel { )} + {paymentPlan.id && ( + { + const currentDateObject = new Date(); + const currentDate = currentDateObject.toISOString(); + paymentPlan.dateValidTo = currentDate; + this.updateAttribute("dateValidTo", currentDate); + }} + variant="outlined" + color="#DFEDEF" + className={classes.button} + disabled={readOnly} + style={{ + border: "0px", + textAlign: "right", + display: "block", + marginLeft: "auto", + marginRight: 0 + }} + > + {formatMessage(intl, "paymentPlan", "paymentPlan.deactivatePaymentPlan")} + + )} this.updateAttribute("name", v)} @@ -237,6 +254,7 @@ class PaymentPlanHeadPanel extends FormPanel { value={!!calculationId ? calculationId : null} onChange={this.updateAttribute} context={paymentPlanType} + readOnly={readOnly} required /> @@ -246,30 +264,35 @@ class PaymentPlanHeadPanel extends FormPanel { ? "product.ProductPicker" : "socialProtection.BenefitPlanPicker"} withNull={true} + readOnly={readOnly} label={formatMessage(intl, "paymentPlan", "benefitPlan")} required value={paymentPlan.benefitPlan !== undefined && paymentPlan.benefitPlan !== null ? (isEmptyObject(paymentPlan.benefitPlan) ? null : paymentPlan.benefitPlan) : null} onChange={(v) => this.updateAttribute("benefitPlan", v)} /> - - this.updateAttribute("periodicity", v)} - /> - + {paymentPlanType !== 'benefitplan' && paymentPlanType !== 'benefit plan' && ( + + this.updateAttribute("periodicity", v)} + /> + + )} this.updateAttribute("dateValidTo", v)} /> - - - - + + + {isBenefitPlanType() ? + : + + } + + + {isBenefitPlanType() && ( + <> + + + + + + + + + + + + + + + + + + + > + )} ); } diff --git a/src/components/PaymentPlanSearcher.js b/src/components/PaymentPlanSearcher.js index 562f75f..ea3633c 100644 --- a/src/components/PaymentPlanSearcher.js +++ b/src/components/PaymentPlanSearcher.js @@ -85,7 +85,7 @@ class PaymentPlanSearcher extends Component { value={paymentPlan.calculation} readOnly /> : "", - paymentPlan => { + paymentPlan => { const objectBenefitPlan = typeof paymentPlan.benefitPlan === 'object' ? paymentPlan.benefitPlan : JSON.parse(paymentPlan.benefitPlan || '{}'); paymentPlan.benefitPlan = objectBenefitPlan; diff --git a/src/dialogs/AdvancedCriteriaDialog.js b/src/dialogs/AdvancedCriteriaDialog.js index 4cae67d..35eca1f 100644 --- a/src/dialogs/AdvancedCriteriaDialog.js +++ b/src/dialogs/AdvancedCriteriaDialog.js @@ -37,18 +37,44 @@ const AdvancedCriteriaDialog = ({ setAppliedFiltersRowStructure, updateAttributes, getDefaultAppliedCustomFilters, + additionalParams, + confirmed, + edited, + readOnly = false, }) => { 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); @@ -60,13 +86,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 = () => { @@ -85,6 +104,12 @@ const AdvancedCriteriaDialog = ({ return updatedJsonExt; } + const handleRemoveFilter = () => { + setCurrentFilter(CLEARED_STATE_FILTER); + setAppliedFiltersRowStructure([CLEARED_STATE_FILTER]); + setFilters([]); + }; + const saveCriteria = () => { setAppliedFiltersRowStructure(filters); const outputFilters = JSON.stringify( @@ -101,6 +126,7 @@ const AdvancedCriteriaDialog = ({ handleClose(); }; + useEffect(() => { if (object && isEmptyObject(object) === false) { let paramsToFetchFilters = []; @@ -108,55 +134,22 @@ const AdvancedCriteriaDialog = ({ 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 ( <> - - {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria")} - - - - {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.AdvancedCriteria")} - - {filters.map((filter, index) => { return () })} + { !confirmed ? ( - + + } style={{ border: "0px", "marginBottom": "6px", fontSize: "0.8rem" }} + disabled={confirmed || readOnly} > {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.addFilters")} - - + ) : (<>>) } - - - {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.clearAllFilters")} - - - + - - {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.cancel")} - - - {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.filter")} - - + {formatMessage(intl, 'individual', 'paymentPlan.advancedCriteria.button.clearAllFilters')} + + + + + {formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.filter")} + - - - > + + > ); -}; +} const mapStateToProps = (state, props) => ({ rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [], diff --git a/src/dialogs/AdvancedCriteriaRowValue.js b/src/dialogs/AdvancedCriteriaRowValue.js index 8f6bc64..824af8c 100644 --- a/src/dialogs/AdvancedCriteriaRowValue.js +++ b/src/dialogs/AdvancedCriteriaRowValue.js @@ -33,6 +33,7 @@ const AdvancedCriteriaRowValue = ({ index, filters, setFilters, + readOnly, }) => { const onAttributeChange = (attribute) => (value) => { @@ -79,6 +80,7 @@ const AdvancedCriteriaRowValue = ({ return ( ); @@ -87,6 +89,7 @@ const AdvancedCriteriaRowValue = ({ ); @@ -96,12 +99,14 @@ const AdvancedCriteriaRowValue = ({ return ( ); } else { return ( ); diff --git a/src/index.js b/src/index.js index ba13ccc..dd7cc96 100644 --- a/src/index.js +++ b/src/index.js @@ -45,7 +45,7 @@ const DEFAULT_CONFIG = { { key: "contributionPlan.route.paymentPlans", ref: ROUTE_PAYMENT_PLANS }, { key: "contributionPlan.route.paymentPlan", ref: ROUTE_PAYMENT_PLAN }, { key: "contributionPlan.PaymentPlanPicker", ref: PaymentPlanPicker }, - { key: "contributionPlan.PaymentPlanPicker.projection", ref: ["id", "code", "name", "periodicity", "dateValidFrom", "dateValidTo", "isDeleted", "replacementUuid"] }, + { key: "contributionPlan.PaymentPlanPicker.projection", ref: ["id", "code", "name", "periodicity", "dateValidFrom", "dateValidTo", "isDeleted", "replacementUuid", "benefitPlan"] }, { key: "contributionPlan.route.replacePaymentPlan", ref: ROUTE_PAYMENT_PLAN_REPLACE }, ], "core.Router": [ diff --git a/src/pickers/PaymentPlanPicker.js b/src/pickers/PaymentPlanPicker.js index 2034f8c..ae63868 100644 --- a/src/pickers/PaymentPlanPicker.js +++ b/src/pickers/PaymentPlanPicker.js @@ -10,12 +10,15 @@ class PaymentPlanPicker extends Component { } queryParams = () => { - const { periodicity, withDeleted = false } = this.props; + const { periodicity, benefitPlanId, withDeleted = false } = this.props; let params = []; params.push(`isDeleted: ${withDeleted}`); if (!!periodicity) { params.push(`periodicity: ${periodicity}`); } + if (!!benefitPlanId) { + params.push(`benefitPlanId: "${benefitPlanId}"`); + } return params; } @@ -45,7 +48,7 @@ class PaymentPlanPicker extends Component { return (