phone number widget fixes

This commit is contained in:
or-else
2023-01-25 18:41:19 -08:00
parent e2f3201ddb
commit 6c36324ed4
16 changed files with 35 additions and 26 deletions
-1
View File
@@ -70,7 +70,6 @@ export default class CreateAccountView extends React.PureComponent {
}
handlePhoneChange(number) {
console.log('handlePhoneChange', number)
this.setState({meth: 'tel', tel: number});
}
-2
View File
@@ -1728,14 +1728,12 @@ class TinodeWeb extends React.Component {
}
handleShowCountrySelector(code, dial, selectedCallback) {
console.log('handleShowCountrySelector', code, dial);
this.handleShowAlert("Select country",
<Suspense fallback={<div><FormattedMessage id="loading_note" defaultMessage="Loading..."
description="Message shown when component is loading"/></div>}>
<PhoneCountrySelector
selected={code}
onSubmit={(c, d) => {
console.log("handleShowCountrySelector click", c, d);
this.setState({alertVisible: false});
selectedCallback(c, d);
}} />
+9 -1
View File
@@ -28,12 +28,20 @@ class PhoneCountrySelector extends React.PureComponent {
this.countries.sort((a, b) => a.name.localeCompare(b.name));
}
componentDidMount() {
if (this.selectedRef) {
this.selectedRef.scrollIntoView({block: 'center', inline: 'nearest'});
}
}
render() {
const countries = [];
const selected = this.props.selected || 'US';
this.countries.forEach((c, idx) => {
const style = (c.code == selected ? 'selected ' : '');
countries.push(<li className={style} key={idx} onClick={_ => this.props.onSubmit(c.code, c.dial)}>
countries.push(<li className={style} key={idx}
ref={ref => {if (c.code == selected) {this.selectedRef = ref}}}
onClick={_ => this.props.onSubmit(c.code, c.dial)}>
<span className="country-flag">{c.flag}</span>
<span className="country">&nbsp;{c.name}</span>
<span className="dial-code">&nbsp;+{c.dial}</span>
+2 -5
View File
@@ -60,7 +60,6 @@ class PhoneEdit extends React.PureComponent {
showCountrySelector() {
this.props.onShowCountrySelector(this.state.countryCode, this.state.dialCode,
(code, dial) => {
console.log('Callback', code, dial);
this.setState({
countryCode: code,
dialCode: dial,
@@ -80,13 +79,11 @@ class PhoneEdit extends React.PureComponent {
}
placeholderNumber(code, dial) {
console.log('In nplaceholder', code, dial);
const number = getExampleNumber(code, examples).formatInternational();
return number.substring(dial.length + 1).trim();
const sample = getExampleNumber(code, examples);
return sample ? sample.formatInternational().substring(dial.length + 1).trim() : '123 456';
}
render() {
console.log('placeholder:', this.state.placeholderNumber);
return (
<>
<span className="dial-code" onClick={this.showCountrySelector}>