fix: fix bug form country code init error (#1591)

This commit is contained in:
Yaodong Yu 2023-02-27 22:07:28 +08:00 committed by GitHub
parent 5caceb4ae2
commit afd3c4ed25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 16 deletions

View File

@ -311,7 +311,7 @@ class UserEditPage extends React.Component {
<PhoneNumberInput <PhoneNumberInput
style={{width: "30%"}} style={{width: "30%"}}
// disabled={!Setting.isLocalAdminUser(this.props.account) ? true : disabled} // disabled={!Setting.isLocalAdminUser(this.props.account) ? true : disabled}
countryCode={this.state.user.countryCode} value={this.state.user.countryCode}
onChange={(value) => { onChange={(value) => {
this.updateUserField("countryCode", value); this.updateUserField("countryCode", value);
}} }}

View File

@ -98,10 +98,6 @@ class SignupPage extends React.Component {
} else { } else {
Setting.showMessage("error", `Unknown application name: ${applicationName}`); Setting.showMessage("error", `Unknown application name: ${applicationName}`);
} }
} else {
this.setState({
countryCode: this.getApplicationObj().organizationObj.countryCodes?.[0],
});
} }
} }
@ -115,7 +111,6 @@ class SignupPage extends React.Component {
this.onUpdateApplication(application); this.onUpdateApplication(application);
this.setState({ this.setState({
application: application, application: application,
countryCode: application?.organizationObj.countryCodes?.[0],
}); });
if (application !== null && application !== undefined) { if (application !== null && application !== undefined) {
@ -398,25 +393,23 @@ class SignupPage extends React.Component {
]} ]}
> >
<PhoneNumberInput <PhoneNumberInput
showSearsh={true}
style={{width: "35%"}} style={{width: "35%"}}
countryCode={this.state.countryCode}
onChange={(value) => {this.setState({countryCode: value});}}
countryCodes={this.getApplicationObj().organizationObj.countryCodes} countryCodes={this.getApplicationObj().organizationObj.countryCodes}
/> />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="phone" name="phone"
key="phone" key="phone"
dependencies={["countryCode"]}
noStyle noStyle
rules={[ rules={[
{ {
required: required, required: required,
message: i18next.t("signup:Please input your phone number!"), message: i18next.t("signup:Please input your phone number!"),
}, },
{ ({getFieldValue}) => ({
validator: (_, value) => { validator: (_, value) => {
if (this.state.phone !== "" && !Setting.isValidPhone(this.state.phone, this.state.countryCode)) { if (value !== "" && !Setting.isValidPhone(value, getFieldValue("countryCode"))) {
this.setState({validPhone: false}); this.setState({validPhone: false});
return Promise.reject(i18next.t("signup:The input is not valid Phone!")); return Promise.reject(i18next.t("signup:The input is not valid Phone!"));
} }
@ -424,7 +417,7 @@ class SignupPage extends React.Component {
this.setState({validPhone: true}); this.setState({validPhone: true});
return Promise.resolve(); return Promise.resolve();
}, },
}, }),
]} ]}
> >
<Input <Input
@ -555,6 +548,7 @@ class SignupPage extends React.Component {
initialValues={{ initialValues={{
application: application.name, application: application.name,
organization: application.organization, organization: application.organization,
countryCode: application.organizationObj.countryCodes?.[0],
}} }}
size="large" size="large"
layout={Setting.isMobile() ? "vertical" : "horizontal"} layout={Setting.isMobile() ? "vertical" : "horizontal"}

View File

@ -17,11 +17,11 @@ import * as Setting from "../Setting";
import React from "react"; import React from "react";
export const PhoneNumberInput = (props) => { export const PhoneNumberInput = (props) => {
const {onChange, style, disabled, countryCode} = props; const {onChange, style, disabled, value} = props;
const countryCodes = props.countryCodes ?? []; const countryCodes = props.countryCodes ?? [];
const handleOnChange = (e) => { const handleOnChange = (value) => {
onChange?.(e); onChange?.(value);
}; };
return ( return (
@ -30,7 +30,7 @@ export const PhoneNumberInput = (props) => {
showSearch showSearch
style={style} style={style}
disabled={disabled} disabled={disabled}
value={countryCode} value={value}
dropdownMatchSelectWidth={false} dropdownMatchSelectWidth={false}
optionLabelProp={"label"} optionLabelProp={"label"}
onChange={handleOnChange} onChange={handleOnChange}