fix: add country/region selectbox in prompt page (#1022)

This commit is contained in:
Resulte Lee 2022-08-21 11:12:23 +08:00 committed by GitHub
parent f3b3376a3c
commit 0bc5b90218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 2 deletions

View File

@ -208,10 +208,18 @@ export function isProviderPrompted(providerItem) {
return isProviderVisible(providerItem) && providerItem.prompted;
}
export function isSignupItemPrompted(signupItem) {
return signupItem.visible && signupItem.prompted;
}
export function getAllPromptedProviderItems(application) {
return application.providers.filter(providerItem => isProviderPrompted(providerItem));
}
export function getAllPromptedSignupItems(application) {
return application.signupItems.filter(signupItem => isSignupItemPrompted(signupItem));
}
export function getSignupItem(application, itemName) {
const signupItems = application.signupItems?.filter(signupItem => signupItem.name === itemName);
if (signupItems.length === 0) {
@ -283,6 +291,11 @@ export function hasPromptPage(application) {
return true;
}
const signupItems = getAllPromptedSignupItems(application);
if (signupItems.length !== 0) {
return true;
}
return isAffiliationPrompted(application);
}

View File

@ -152,7 +152,7 @@ class SignupTable extends React.Component {
return null;
}
if (record.visible) {
if (record.visible && record.name !== "Country/Region") {
return null;
}

View File

@ -21,6 +21,7 @@ import * as Setting from "../Setting";
import i18next from "i18next";
import AffiliationSelect from "../common/AffiliationSelect";
import OAuthWidget from "../common/OAuthWidget";
import SelectRegionBox from "../SelectRegionBox";
class PromptPage extends React.Component {
constructor(props) {
@ -90,6 +91,16 @@ class PromptPage extends React.Component {
this.submitUserEdit(false);
}
updateUserFieldWithoutSubmit(key, value) {
value = this.parseUserField(key, value);
const user = this.state.user;
user[key] = value;
this.setState({
user: user,
});
}
renderAffiliation(application) {
if (!Setting.isAffiliationPrompted(application)) {
return null;
@ -120,6 +131,31 @@ class PromptPage extends React.Component {
application?.providers.filter(providerItem => Setting.isProviderPrompted(providerItem)).map((providerItem, index) => <OAuthWidget key={providerItem.name} labelSpan={6} user={this.state.user} application={application} providerItem={providerItem} account={this.props.account} onUnlinked={() => {return this.unlinked();}} />)
)
}
{
(application === null || this.state.user === null) ? null : (
application?.signupItems.filter(signupItem => Setting.isSignupItemPrompted(signupItem)).map((signupItem, index) => {
if (signupItem.name !== "Country/Region") {
return null;
}
return (
<Row key={signupItem.name} style={{marginTop: "20px", justifyContent: "space-between"}} >
<Col style={{marginTop: "5px"}} >
<span style={{marginLeft: "5px"}}>
{
i18next.t("user:Country/Region")
}:
</span>
</Col>
<Col >
<SelectRegionBox defaultValue={this.state.user.region} onChange={(value) => {
this.updateUserFieldWithoutSubmit("region", value);
}} />
</Col>
</Row>
);
})
)
}
</div>
</div>
);
@ -151,7 +187,7 @@ class PromptPage extends React.Component {
if (redirectUrl === "") {
redirectUrl = res.data2;
}
if (redirectUrl !== "") {
if (redirectUrl !== "" && redirectUrl !== null) {
Setting.goToLink(redirectUrl);
} else {
Setting.goToLogin(this, this.getApplicationObj());