feat: add country code to validate phone number when Code method's rule is Phone only (#4089)

This commit is contained in:
DacongDA
2025-08-17 16:56:25 +08:00
committed by GitHub
parent 955e73ddd1
commit 645716e485

View File

@@ -39,6 +39,7 @@ import {GoogleOneTapLoginVirtualButton} from "./GoogleLoginButton";
import * as ProviderButton from "./ProviderButton";
import {createFormAndSubmit, goToLink} from "../Setting";
import WeChatLoginPanel from "./WeChatLoginPanel";
import {CountryCodeSelect} from "../common/select/CountryCodeSelect";
const FaceRecognitionCommonModal = lazy(() => import("../common/modal/FaceRecognitionCommonModal"));
const FaceRecognitionModal = lazy(() => import("../common/modal/FaceRecognitionModal"));
@@ -677,6 +678,62 @@ class LoginPage extends React.Component {
if (this.state.loginMethod === "wechat") {
return (<WeChatLoginPanel application={application} loginMethod={this.state.loginMethod} />);
}
if (this.state.loginMethod === "verificationCodePhone") {
return <Form.Item className="signin-phone" required={true}>
<Input.Group compact>
<Form.Item
name="countryCode"
noStyle
rules={[
{
required: true,
message: i18next.t("signup:Please select your country code!"),
},
]}
>
<CountryCodeSelect
style={{width: "35%"}}
countryCodes={this.getApplicationObj().organizationObj.countryCodes}
/>
</Form.Item>
<Form.Item
name="username"
dependencies={["countryCode"]}
noStyle
rules={[
{
required: true,
message: i18next.t("signup:Please input your phone number!"),
},
({getFieldValue}) => ({
validator: (_, value) => {
if (!value) {
return Promise.resolve();
}
if (value && !Setting.isValidPhone(value, getFieldValue("countryCode"))) {
this.setState({validEmailOrPhone: false});
return Promise.reject(i18next.t("signup:The input is not valid Phone!"));
}
this.setState({validEmailOrPhone: true});
return Promise.resolve();
},
}),
]}
>
<Input
className="signup-phone-input"
placeholder={signinItem.placeholder}
style={{width: "65%", textAlign: "left"}}
onChange={e => this.setState({username: e.target.value})}
/>
</Form.Item>
</Input.Group>
</Form.Item>;
}
return (
<div key={resultItemKey}>
<div dangerouslySetInnerHTML={{__html: ("<style>" + signinItem.customCss?.replaceAll("<style>", "").replaceAll("</style>", "") + "</style>")}} />