From 917498846564076e81b2816caeacef1d9f1bd0c9 Mon Sep 17 00:00:00 2001 From: "jailson.damasceno" Date: Thu, 18 Mar 2021 11:30:42 -0300 Subject: [PATCH 1/2] Add verification if the user's document is empty --- CHANGELOG.md | 1 + react/ProfileField.js | 99 +++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed58de60..c775b4a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added +- Added verification if the user's document is empty - Added prop `blockDocument` to Enables or disables editing the document field in my account ## [3.4.0] - 2021-01-06 diff --git a/react/ProfileField.js b/react/ProfileField.js index 484e3406..513fd5ac 100644 --- a/react/ProfileField.js +++ b/react/ProfileField.js @@ -5,65 +5,70 @@ import RuleFieldShape from './RuleFieldShape' import ProfileFieldShape from './ProfileFieldShape' class ProfileField extends Component { - componentDidUpdate() { - const { field, data, onFieldUpdate } = this.props - if (data.focus && this.el) { - this.el.focus() - onFieldUpdate({ [field.name]: { ...data, focus: false } }) + componentDidUpdate() { + const { field, data, onFieldUpdate } = this.props + if (data.focus && this.el) { + this.el.focus() + onFieldUpdate({ + [field.name]: {...data, focus: false } + }) + } } - } - handleChange = e => { - const { field, data, onFieldUpdate } = this.props - const { value } = e.target + handleChange = e => { + const { field, data, onFieldUpdate } = this.props + const { value } = e.target - const error = data.touched ? applyValidation(field, value) : null - const maskedValue = applyMask(field, value) + const error = data.touched ? applyValidation(field, value) : null + const maskedValue = applyMask(field, value) - onFieldUpdate({ [field.name]: { ...data, value: maskedValue, error } }) - } + onFieldUpdate({ + [field.name]: {...data, value: maskedValue, error } + }) + } - handleBlur = () => { - const { field, data, onFieldUpdate } = this.props - const error = applyValidation(field, data.value) + handleBlur = () => { + const { field, data, onFieldUpdate } = this.props + const error = applyValidation(field, data.value) - onFieldUpdate({ [field.name]: { ...data, touched: true, error } }) - } + onFieldUpdate({ + [field.name]: {...data, touched: true, error } + }) + } - inputRef = el => { - this.el = el - } + inputRef = el => { + this.el = el + } - render() { - const { field, data, options, Input, userProfile, blockDocument } = this.props - if(blockDocument && field.name === 'document' && userProfile['document'].value !== null){ - field.disabled = true + render() { + const { field, data, options, Input, userProfile, blockDocument } = this.props + if (blockDocument && field.name === 'document' && (userProfile['document'].value !== null && userProfile['document'].value !== "")) { + field.disabled = true + } + return ( < + Input field = { field } + data = { data } + options = { options } + inputRef = { this.inputRef } + onChange = { this.handleChange } + onBlur = { this.handleBlur } + /> + ) } - return ( - - ) - } } ProfileField.propTypes = { - /** Rules for the field this component represents */ - field: RuleFieldShape.isRequired, - /** Data to be displayed by this component */ - data: ProfileFieldShape.isRequired, - /** Additional options to modify this input */ - options: PropTypes.object, - /** Function to be called when data changes */ - onFieldUpdate: PropTypes.func.isRequired, - /** Component to be used as input for the field */ - Input: PropTypes.func.isRequired, + /** Rules for the field this component represents */ + field: RuleFieldShape.isRequired, + /** Data to be displayed by this component */ + data: ProfileFieldShape.isRequired, + /** Additional options to modify this input */ + options: PropTypes.object, + /** Function to be called when data changes */ + onFieldUpdate: PropTypes.func.isRequired, + /** Component to be used as input for the field */ + Input: PropTypes.func.isRequired, } -export default ProfileField +export default ProfileField \ No newline at end of file From efc057b4245854be87de89ee8c9a14ca4b151f28 Mon Sep 17 00:00:00 2001 From: "jailson.damasceno" Date: Thu, 18 Mar 2021 11:36:18 -0300 Subject: [PATCH 2/2] Add verification if the user's document is empty not only null --- CHANGELOG.md | 2 +- react/ProfileField.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c775b4a7..ad47975c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added -- Added verification if the user's document is empty +- Add verification if the user's document is empty not only null - Added prop `blockDocument` to Enables or disables editing the document field in my account ## [3.4.0] - 2021-01-06 diff --git a/react/ProfileField.js b/react/ProfileField.js index 513fd5ac..b6ee9175 100644 --- a/react/ProfileField.js +++ b/react/ProfileField.js @@ -43,6 +43,7 @@ class ProfileField extends Component { render() { const { field, data, options, Input, userProfile, blockDocument } = this.props + if (blockDocument && field.name === 'document' && (userProfile['document'].value !== null && userProfile['document'].value !== "")) { field.disabled = true }