fix: set initial value in CountryCodeSelect (#1890)

This commit is contained in:
Yaodong Yu
2023-05-24 23:27:04 +08:00
committed by GitHub
parent c57c6e37dd
commit 225e9cf70a
2 changed files with 7 additions and 4 deletions

View File

@ -78,6 +78,7 @@ function CheckPasswordForm({user, onSuccess, onFail}) {
export function MfaVerifyForm({mfaProps, application, user, onSuccess, onFail}) { export function MfaVerifyForm({mfaProps, application, user, onSuccess, onFail}) {
const [form] = Form.useForm(); const [form] = Form.useForm();
mfaProps = mfaProps ?? {type: ""};
const onFinish = ({passcode}) => { const onFinish = ({passcode}) => {
const data = {passcode, type: mfaProps.type, ...user}; const data = {passcode, type: mfaProps.type, ...user};
@ -97,9 +98,9 @@ export function MfaVerifyForm({mfaProps, application, user, onSuccess, onFail})
}); });
}; };
if (mfaProps?.type === SmsMfaType) { if (mfaProps.type === SmsMfaType) {
return <MfaSmsVerifyForm onFinish={onFinish} application={application} />; return <MfaSmsVerifyForm onFinish={onFinish} application={application} />;
} else if (mfaProps?.type === TotpMfaType) { } else if (mfaProps.type === TotpMfaType) {
return <MfaTotpVerifyForm onFinish={onFinish} mfaProps={mfaProps} />; return <MfaTotpVerifyForm onFinish={onFinish} mfaProps={mfaProps} />;
} else { } else {
return <div></div>; return <div></div>;
@ -160,7 +161,7 @@ class MfaSetupPage extends React.Component {
} }
componentDidUpdate(prevProps, prevState, snapshot) { componentDidUpdate(prevProps, prevState, snapshot) {
if (prevState.isAuthenticated === true && this.state.mfaProps === null) { if (this.state.isAuthenticated === true && this.state.mfaProps === null) {
MfaBackend.MfaSetupInitiate({ MfaBackend.MfaSetupInitiate({
type: this.state.type, type: this.state.type,
...this.getUser(), ...this.getUser(),

View File

@ -17,10 +17,12 @@ import * as Setting from "../../Setting";
import React from "react"; import React from "react";
export const CountryCodeSelect = (props) => { export const CountryCodeSelect = (props) => {
const {onChange, style, disabled, value} = props; const {onChange, style, disabled} = props;
const countryCodes = props.countryCodes ?? []; const countryCodes = props.countryCodes ?? [];
const [value, setValue] = React.useState(countryCodes.length > 0 ? countryCodes[0] : "");
const handleOnChange = (value) => { const handleOnChange = (value) => {
setValue(value);
onChange?.(value); onChange?.(value);
}; };