Skip to content

Commit

Permalink
Merge pull request #3507 from yoution/cf20
Browse files Browse the repository at this point in the history
Accounts App issue 3494 sync businessPhone validation with member api
  • Loading branch information
maxceem authored Jan 25, 2020
2 parents f2341f0 + 03a57c7 commit 39eb1de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,19 @@ export const createEvent = (eventName) => {
export const delay = (milliseconds) => new Promise((resolve) => {
setTimeout(resolve, milliseconds)
})


/**
* format phone bofore send to server
* if phone is not head with '+', add '+'
*
* @param {String} phone
* @returns {String}
*/
export const formatPhone = (phone) => {
if(phone[0] === '+') {
return phone
}else{
return '+' + phone
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Formsy = FormsyForm.Formsy
import ProfileSettingsAvatar from './ProfileSettingsAvatar'
import FormsySelect from '../../../../../components/Select/FormsySelect'
import ISOCountries from '../../../../../helpers/ISOCountries'

import { formatPhone } from '../../../../../helpers/utils'
import './ProfileSettingsForm.scss'

const countries = _.orderBy(ISOCountries, ['name'], ['asc']).map(country => ({
Expand Down Expand Up @@ -52,8 +52,8 @@ class ProfileSettingsForm extends Component {
}
}

onBusinessPhoneCountryChange({ country, externalChange }) {
const { businessPhoneValid, countrySelected: previousSelectedCountry } = this.state
onBusinessPhoneCountryChange({ country, externalChange, isValid}) {
const { countrySelected: previousSelectedCountry } = this.state

if (country && country.code) {
if (previousSelectedCountry !== country.name && country.name) {
Expand All @@ -63,13 +63,14 @@ class ProfileSettingsForm extends Component {
countrySelected: country.name,
})
}

if (!businessPhoneValid) {
if(!this.state.businessPhoneValid && isValid) {
this.setState({
businessPhoneValid: true
})
}
} else if (businessPhoneValid) {
}

if (this.state.businessPhoneValid && !isValid){
this.setState({
businessPhoneValid: false
})
Expand Down Expand Up @@ -137,6 +138,8 @@ class ProfileSettingsForm extends Component {
...this.props.values.settings,
...data,
}

updatedData.businessPhone = formatPhone(updatedData.businessPhone)
this.props.saveSettings(updatedData)

this.setState({
Expand Down

0 comments on commit 39eb1de

Please sign in to comment.