Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/tksio 549 #103

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- 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
Expand Down
100 changes: 53 additions & 47 deletions react/ProfileField.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,71 @@ 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
render() {
const { field, data, options, Input, userProfile, blockDocument } = this.props

if(blockDocument && field.name === 'document' && userProfile['document'].value !== null){
field.disabled = true
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 (
<Input
field={field}
data={data}
options={options}
inputRef={this.inputRef}
onChange={this.handleChange}
onBlur={this.handleBlur}
/>
)
}
}

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