Skip to content

Commit

Permalink
[Upd #101] Refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Mar 19, 2024
1 parent 1ffac3f commit 9665f65
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions src/components/record/Record.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,37 @@ class Record extends React.Component {
this.setState({ form });
};

_filterQuestionsBySeverity = (severity) => {
return filterObjectsByKeyValuePair(this.getFormQuestionsData(), SConstants.HAS_VALIDATION_SEVERITY, severity);
};

_handleOnSave = () => {
const { form } = this.state;
if (form) {
this.validateForm();
this.setState(
{
invalidQuestions: filterObjectsByKeyValuePair(
this.getFormQuestionsData(),
SConstants.HAS_VALIDATION_SEVERITY,
"error",
),
},
() => {
const { invalidQuestions } = this.state;
if (invalidQuestions.length > 0) {
this.setState({ showModal: true });
} else {
this.props.handlers.onSave();
}
},
);
const invalidQuestions = this._filterQuestionsBySeverity("error");
this.setState({ invalidQuestions }, () => {
if (invalidQuestions.length > 0) {
this.setState({ showModal: true });
} else {
this.props.handlers.onSave();
}
});
}
};

_handleOnComplete = () => {
const { form } = this.state;
if (form) {
this.validateForm();
this.setState(
{
incompleteQuestions: filterObjectsByKeyValuePair(
this.getFormQuestionsData(),
SConstants.HAS_VALIDATION_SEVERITY,
"warning",
),
},
() => {
const { incompleteQuestions } = this.state;
if (incompleteQuestions.length > 0) {
this.setState({ showModal: true });
} else {
this.props.handlers.onComplete();
}
},
);
const incompleteQuestions = this._filterQuestionsBySeverity("warning");
this.setState({ incompleteQuestions }, () => {
if (incompleteQuestions.length > 0) {
this.setState({ showModal: true });
} else {
this.props.handlers.onComplete();
}
});
}
};

Expand Down

0 comments on commit 9665f65

Please sign in to comment.