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

#3494 sync businessPhone validation with member api #3507

Merged
merged 3 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,18 +63,17 @@ class ProfileSettingsForm extends Component {
countrySelected: country.name,
})
}
}

if (!businessPhoneValid) {
maxceem marked this conversation as resolved.
Show resolved Hide resolved
this.setState({
businessPhoneValid: true
})
}
} else if (businessPhoneValid) {
if (isValid) {
this.setState({
businessPhoneValid: true
})
} else {
this.setState({
businessPhoneValid: false
})
}

// external change means, the user didn't change the phone number field.
// But it was automatically changed due to country selection change. In such case, we should show
// the alert under country selection only.
Expand Down Expand Up @@ -137,6 +136,8 @@ class ProfileSettingsForm extends Component {
...this.props.values.settings,
...data,
}

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

this.setState({
Expand Down