mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-05 05:50:19 +08:00
fix: empty countryCode of current account causes crash (#1603)
* fix: empty countryCode of current account cause crush * Update UserEditPage.js --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
@ -25,7 +25,7 @@ export const ResetModal = (props) => {
|
|||||||
const [confirmLoading, setConfirmLoading] = React.useState(false);
|
const [confirmLoading, setConfirmLoading] = React.useState(false);
|
||||||
const [dest, setDest] = React.useState("");
|
const [dest, setDest] = React.useState("");
|
||||||
const [code, setCode] = React.useState("");
|
const [code, setCode] = React.useState("");
|
||||||
const {buttonText, destType, application, account} = props;
|
const {buttonText, destType, application, countryCode} = props;
|
||||||
|
|
||||||
const showModal = () => {
|
const showModal = () => {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
@ -87,7 +87,7 @@ export const ResetModal = (props) => {
|
|||||||
<Row style={{width: "100%", marginBottom: "20px"}}>
|
<Row style={{width: "100%", marginBottom: "20px"}}>
|
||||||
<Input
|
<Input
|
||||||
addonBefore={destType === "email" ? i18next.t("user:New Email") : i18next.t("user:New phone")}
|
addonBefore={destType === "email" ? i18next.t("user:New Email") : i18next.t("user:New phone")}
|
||||||
prefix={destType === "email" ? <React.Fragment><MailOutlined /> </React.Fragment> : (<React.Fragment><PhoneOutlined /> {`+${Setting.getCountryCode(account.countryCode)}`} </React.Fragment>)}
|
prefix={destType === "email" ? <React.Fragment><MailOutlined /> </React.Fragment> : (<React.Fragment><PhoneOutlined /> {countryCode !== "" ? "+" : null}{Setting.getCountryCode(countryCode)} </React.Fragment>)}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onChange={e => setDest(e.target.value)}
|
onChange={e => setDest(e.target.value)}
|
||||||
/>
|
/>
|
||||||
|
@ -209,8 +209,11 @@ export function initCountries() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getCountryCode(country) {
|
export function getCountryCode(country) {
|
||||||
|
if (phoneNumber.isSupportedCountry(country)) {
|
||||||
return phoneNumber.getCountryCallingCode(country);
|
return phoneNumber.getCountryCallingCode(country);
|
||||||
}
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
export function getCountryCodeData(countryCodes = phoneNumber.getCountries()) {
|
export function getCountryCodeData(countryCodes = phoneNumber.getCountries()) {
|
||||||
return countryCodes?.map((countryCode) => {
|
return countryCodes?.map((countryCode) => {
|
||||||
|
@ -138,6 +138,10 @@ class UserEditPage extends React.Component {
|
|||||||
return this.isSelf() || Setting.isAdminUser(this.props.account);
|
return this.isSelf() || Setting.isAdminUser(this.props.account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCountryCode() {
|
||||||
|
return this.props.account.countryCode;
|
||||||
|
}
|
||||||
|
|
||||||
renderAccountItem(accountItem) {
|
renderAccountItem(accountItem) {
|
||||||
if (!accountItem.visible) {
|
if (!accountItem.visible) {
|
||||||
return null;
|
return null;
|
||||||
@ -296,7 +300,7 @@ class UserEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={Setting.isMobile() ? 22 : 11} >
|
<Col span={Setting.isMobile() ? 22 : 11} >
|
||||||
{/* backend auto get the current user, so admin can not edit. Just self can reset*/}
|
{/* backend auto get the current user, so admin can not edit. Just self can reset*/}
|
||||||
{this.isSelf() ? <ResetModal application={this.state.application} account={this.props.account} disabled={disabled} buttonText={i18next.t("user:Reset Email...")} destType={"email"} /> : null}
|
{this.isSelf() ? <ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Email...")} destType={"email"} /> : null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
@ -326,7 +330,7 @@ class UserEditPage extends React.Component {
|
|||||||
</Input.Group>
|
</Input.Group>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={Setting.isMobile() ? 24 : 11} >
|
<Col span={Setting.isMobile() ? 24 : 11} >
|
||||||
{this.isSelf() ? (<ResetModal application={this.state.application} account={this.props.account} disabled={disabled} buttonText={i18next.t("user:Reset Phone...")} destType={"phone"} />) : null}
|
{this.isSelf() ? (<ResetModal application={this.state.application} countryCode={this.getCountryCode()} disabled={disabled} buttonText={i18next.t("user:Reset Phone...")} destType={"phone"} />) : null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user