Skip to content

Commit

Permalink
OP-1962: block form if payment plan saved/updated
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Apr 10, 2024
1 parent f3c26f9 commit a246d57
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
20 changes: 17 additions & 3 deletions src/components/PaymentPlanForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,6 +32,7 @@ class PaymentPlanForm extends Component {
paymentPlan: {},
jsonExtValid: true,
requiredValid: false,
clientMutationId: null,
};
}

Expand All @@ -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,
}));
}
}

Expand Down Expand Up @@ -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 (
<Fragment>
<div className={shouldBeLocked ? classes.lockedPage : null}>
<Helmet title={formatMessageWithValues(this.props.intl, "paymentPlan", "paymentPlan.page.title", this.titleParams())} />
<Form
module="paymentPlan"
Expand All @@ -117,8 +130,9 @@ class PaymentPlanForm extends Component {
paymentPlanId={paymentPlanId}
isReplacing={isReplacing}
openDirty={save}
readOnly={shouldBeLocked}
/>
</Fragment>
</div>
)
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/components/PaymentPlanHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class PaymentPlanHeadPanel extends FormPanel {
isCodeValid,
isCodeValidating,
validationError,
readOnly = false,
}
= this.props;
const { benefitPlan: productOrBenefitPlan, calculation: calculationId, ...others } = this.props.edited;
Expand Down Expand Up @@ -191,6 +192,7 @@ class PaymentPlanHeadPanel extends FormPanel {
variant="outlined"
color="#DFEDEF"
className={classes.button}
disabled={readOnly}
style={{
border: "0px",
textAlign: "right",
Expand All @@ -207,7 +209,7 @@ class PaymentPlanHeadPanel extends FormPanel {
<PaymentPlanTypePicker
module="contributionPlan"
label="type"
readOnly={!!paymentPlan.id}
readOnly={!!paymentPlan.id || readOnly}
withNull={false}
required
value={paymentPlan?.benefitPlanTypeName?.replace(/\s+/g, '') ?? ''}
Expand All @@ -221,7 +223,7 @@ class PaymentPlanHeadPanel extends FormPanel {
label="code"
required={true}
value={!!paymentPlan.code ? paymentPlan.code : ""}
readOnly={!!paymentPlan.id}
readOnly={!!paymentPlan.id || readOnly}
itemQueryIdentifier="paymentPlanCode"
codeTakenLabel="paymentPlan.codeTaken"
shouldValidate={this.shouldValidate}
Expand All @@ -239,6 +241,7 @@ class PaymentPlanHeadPanel extends FormPanel {
<TextInput
module="contributionPlan"
label="name"
readOnly={readOnly}
required
value={!!paymentPlan.name ? paymentPlan.name : ""}
onChange={(v) => this.updateAttribute("name", v)}
Expand All @@ -251,6 +254,7 @@ class PaymentPlanHeadPanel extends FormPanel {
value={!!calculationId ? calculationId : null}
onChange={this.updateAttribute}
context={paymentPlanType}
readOnly={readOnly}
required
/>
</Grid>
Expand All @@ -260,6 +264,7 @@ 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}
Expand All @@ -270,6 +275,7 @@ class PaymentPlanHeadPanel extends FormPanel {
<Grid item xs={GRID_ITEM_SIZE} className={classes.item}>
<NumberInput
module="contributionPlan"
readOnly={readOnly}
label="periodicity"
required
/**
Expand All @@ -286,6 +292,7 @@ class PaymentPlanHeadPanel extends FormPanel {
<PublishedComponent
pubRef="core.DatePicker"
module="contributionPlan"
readOnly={readOnly}
label="dateValidFrom"
required
value={!!paymentPlan.dateValidFrom ? paymentPlan.dateValidFrom : null}
Expand All @@ -296,6 +303,7 @@ class PaymentPlanHeadPanel extends FormPanel {
<PublishedComponent
pubRef="core.DatePicker"
module="contributionPlan"
readOnly={readOnly}
label="dateValidTo"
value={!!paymentPlan.dateValidTo ? paymentPlan.dateValidTo : null}
onChange={(v) => this.updateAttribute("dateValidTo", v)}
Expand All @@ -318,6 +326,7 @@ class PaymentPlanHeadPanel extends FormPanel {
intl={intl}
className={PAYMENTPLAN_CLASSNAME}
entity={paymentPlan}
readOnly={readOnly}
requiredRights={[!!paymentPlan.id ? RIGHT_CALCULATION_UPDATE : RIGHT_CALCULATION_WRITE]}
value={!!paymentPlan.jsonExt ? paymentPlan.jsonExt : null}
onChange={this.updateAttribute}
Expand Down Expand Up @@ -355,7 +364,9 @@ class PaymentPlanHeadPanel extends FormPanel {
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
edited={this.props.edited} />
edited={this.props.edited}
readOnly={readOnly}
/>

</Grid>
</Fragment>
Expand Down
30 changes: 16 additions & 14 deletions src/dialogs/AdvancedCriteriaDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const AdvancedCriteriaDialog = ({
additionalParams,
confirmed,
edited,
readOnly = false,
}) => {

const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -157,32 +158,33 @@ const AdvancedCriteriaDialog = ({
index={index}
filters={filters}
setFilters={setFilters}
readOnly={confirmed}
readOnly={confirmed || readOnly}
/>)
})}
{ !confirmed ? (
<div
style={{ backgroundColor: "#DFEDEF", paddingLeft: "10px", paddingBottom: "10px" }}
>
<AddCircle
style={{
border: "thin solid",
borderRadius: "40px",
width: "16px",
height: "16px"
}}
onClick={handleAddFilter}
disabled={confirmed}
/>

<Button
onClick={handleAddFilter}
variant="outlined"
startIcon={
<AddCircle
style={{
border: 'thin solid',
borderRadius: '40px',
width: '16px',
height: '16px',
}}
/>
}
style={{
border: "0px",
"marginBottom": "6px",
fontSize: "0.8rem"
}}
disabled={confirmed}
disabled={confirmed || readOnly}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.addFilters")}
</Button>
Expand All @@ -196,7 +198,7 @@ const AdvancedCriteriaDialog = ({
style={{
border: '0px',
}}
disabled={confirmed}
disabled={confirmed || readOnly}
>
{formatMessage(intl, 'individual', 'paymentPlan.advancedCriteria.button.clearAllFilters')}
</Button>
Expand All @@ -211,7 +213,7 @@ const AdvancedCriteriaDialog = ({
variant="contained"
color="primary"
autoFocus
disabled={!object || confirmed}
disabled={!object || confirmed || readOnly}
>
{formatMessage(intl, "paymentPlan", "paymentPlan.advancedCriteria.button.filter")}
</Button>
Expand Down

0 comments on commit a246d57

Please sign in to comment.