From a8937d3046a934af991c442794a6f16b8428fe16 Mon Sep 17 00:00:00 2001 From: Yaodong Yu <2814461814@qq.com> Date: Sun, 26 Mar 2023 18:44:47 +0800 Subject: [PATCH] feat: refactor agreement modal and create folders to classify components (#1686) * refactor: refactor agreement modal and create folders to classify components * fix: i18 * fix: i18 * fix: i18n --- web/src/AdapterEditPage.js | 2 +- web/src/App.js | 10 +- web/src/ApplicationEditPage.js | 6 +- web/src/OrganizationEditPage.js | 4 +- web/src/ProviderEditPage.js | 33 ++- web/src/Setting.js | 198 +-------------- web/src/SyncerEditPage.js | 95 ++++++- web/src/UserEditPage.js | 22 +- web/src/WebhookEditPage.js | 2 +- web/src/auth/ForgetPage.js | 2 +- web/src/auth/LoginPage.js | 58 +---- web/src/auth/PromptPage.js | 6 +- web/src/auth/SignupPage.js | 48 +--- web/src/common/CaptchaPreview.js | 2 +- web/src/{ => common}/CustomGithubCorner.js | 2 +- web/src/common/SendCodeInput.js | 2 +- web/src/{ => common}/TestEmailWidget.js | 2 +- web/src/{ => common}/TestSmsWidget.js | 2 +- web/src/common/modal/AgreementModal.js | 126 ++++++++++ web/src/common/{ => modal}/CaptchaModal.js | 4 +- .../modal/CropperDivModal.js} | 10 +- web/src/{ => common/modal}/PasswordModal.js | 4 +- web/src/{ => common/modal}/ResetModal.js | 6 +- .../common/{ => select}/AffiliationSelect.js | 238 +++++++++--------- .../common/{ => select}/CountryCodeSelect.js | 2 +- .../select/LanguageSelect.js} | 8 +- .../select/RegionSelect.js} | 6 +- .../select/ThemeSelect.js} | 8 +- web/src/locales/de/data.json | 16 ++ web/src/locales/en/data.json | 16 ++ web/src/locales/es/data.json | 16 ++ web/src/locales/fr/data.json | 16 ++ web/src/locales/id/data.json | 16 ++ web/src/locales/ja/data.json | 16 ++ web/src/locales/ko/data.json | 16 ++ web/src/locales/ru/data.json | 16 ++ web/src/locales/vi/data.json | 16 ++ web/src/locales/zh/data.json | 16 ++ web/src/{ => table}/AccountTable.js | 2 +- web/src/{ => table}/LdapTable.js | 6 +- web/src/{ => table}/ManagedAccountTable.js | 2 +- web/src/{common => table}/PoliciyTable.js | 0 web/src/{ => table}/ProviderTable.js | 4 +- web/src/{ => table}/SignupTable.js | 22 +- web/src/{ => table}/SyncerTableColumnTable.js | 2 +- web/src/{ => table}/UrlTable.js | 2 +- .../{ => table}/WebauthnCredentialTable.js | 4 +- web/src/{ => table}/WebhookHeaderTable.js | 2 +- web/src/{ => table}/propertyTable.js | 2 +- 49 files changed, 628 insertions(+), 488 deletions(-) rename web/src/{ => common}/CustomGithubCorner.js (96%) rename web/src/{ => common}/TestEmailWidget.js (98%) rename web/src/{ => common}/TestSmsWidget.js (97%) create mode 100644 web/src/common/modal/AgreementModal.js rename web/src/common/{ => modal}/CaptchaModal.js (97%) rename web/src/{CropperDiv.js => common/modal/CropperDivModal.js} (96%) rename web/src/{ => common/modal}/PasswordModal.js (97%) rename web/src/{ => common/modal}/ResetModal.js (96%) rename web/src/common/{ => select}/AffiliationSelect.js (94%) rename web/src/common/{ => select}/CountryCodeSelect.js (97%) rename web/src/{SelectLanguageBox.js => common/select/LanguageSelect.js} (93%) rename web/src/{SelectRegionBox.js => common/select/RegionSelect.js} (93%) rename web/src/{SelectThemeBox.js => common/select/ThemeSelect.js} (95%) rename web/src/{ => table}/AccountTable.js (99%) rename web/src/{ => table}/LdapTable.js (97%) rename web/src/{ => table}/ManagedAccountTable.js (99%) rename web/src/{common => table}/PoliciyTable.js (100%) rename web/src/{ => table}/ProviderTable.js (98%) rename web/src/{ => table}/SignupTable.js (90%) rename web/src/{ => table}/SyncerTableColumnTable.js (99%) rename web/src/{ => table}/UrlTable.js (98%) rename web/src/{ => table}/WebauthnCredentialTable.js (95%) rename web/src/{ => table}/WebhookHeaderTable.js (99%) rename web/src/{ => table}/propertyTable.js (98%) diff --git a/web/src/AdapterEditPage.js b/web/src/AdapterEditPage.js index 10fd2e5e..fbba5ae1 100644 --- a/web/src/AdapterEditPage.js +++ b/web/src/AdapterEditPage.js @@ -21,7 +21,7 @@ import i18next from "i18next"; import "codemirror/lib/codemirror.css"; import * as ModelBackend from "./backend/ModelBackend"; -import PolicyTable from "./common/PoliciyTable"; +import PolicyTable from "./table/PoliciyTable"; require("codemirror/theme/material-darker.css"); require("codemirror/mode/javascript/javascript"); diff --git a/web/src/App.js b/web/src/App.js index c2eb6d9d..b79528f7 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -52,7 +52,7 @@ import PaymentEditPage from "./PaymentEditPage"; import PaymentResultPage from "./PaymentResultPage"; import AccountPage from "./account/AccountPage"; import HomePage from "./basic/HomePage"; -import CustomGithubCorner from "./CustomGithubCorner"; +import CustomGithubCorner from "./common/CustomGithubCorner"; import * as Conf from "./Conf"; import * as Auth from "./auth/Auth"; @@ -60,7 +60,7 @@ import EntryPage from "./EntryPage"; import ResultPage from "./auth/ResultPage"; import * as AuthBackend from "./auth/AuthBackend"; import AuthCallback from "./auth/AuthCallback"; -import SelectLanguageBox from "./SelectLanguageBox"; +import LanguageSelect from "./common/select/LanguageSelect"; import i18next from "i18next"; import OdicDiscoveryPage from "./auth/OidcDiscoveryPage"; import SamlCallback from "./auth/SamlCallback"; @@ -70,7 +70,7 @@ import SystemInfo from "./SystemInfo"; import AdapterListPage from "./AdapterListPage"; import AdapterEditPage from "./AdapterEditPage"; import {withTranslation} from "react-i18next"; -import SelectThemeBox from "./SelectThemeBox"; +import ThemeSelect from "./common/select/ThemeSelect"; import SessionListPage from "./SessionListPage"; const {Header, Footer, Content} = Layout; @@ -352,7 +352,7 @@ class App extends Component { return ( {this.renderRightDropdown()} - { this.setState({ @@ -360,7 +360,7 @@ class App extends Component { logo: this.getLogo(nextThemeAlgorithm), }); }} /> - + ); } diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index afcc26a5..ff708685 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -25,9 +25,9 @@ import * as ResourceBackend from "./backend/ResourceBackend"; import SignupPage from "./auth/SignupPage"; import LoginPage from "./auth/LoginPage"; import i18next from "i18next"; -import UrlTable from "./UrlTable"; -import ProviderTable from "./ProviderTable"; -import SignupTable from "./SignupTable"; +import UrlTable from "./table/UrlTable"; +import ProviderTable from "./table/ProviderTable"; +import SignupTable from "./table/SignupTable"; import PromptPage from "./auth/PromptPage"; import copy from "copy-to-clipboard"; diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index ed12fb20..da8c5ba1 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -21,8 +21,8 @@ import * as Setting from "./Setting"; import * as Conf from "./Conf"; import i18next from "i18next"; import {LinkOutlined} from "@ant-design/icons"; -import LdapTable from "./LdapTable"; -import AccountTable from "./AccountTable"; +import LdapTable from "./table/LdapTable"; +import AccountTable from "./table/AccountTable"; import ThemeEditor from "./common/theme/ThemeEditor"; const {Option} = Select; diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index 0b5446fb..043efe50 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -19,12 +19,12 @@ import * as ProviderBackend from "./backend/ProviderBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; import {authConfig} from "./auth/Auth"; -import * as ProviderEditTestEmail from "./TestEmailWidget"; -import * as ProviderEditTestSms from "./TestSmsWidget"; +import * as ProviderEditTestEmail from "./common/TestEmailWidget"; +import * as ProviderEditTestSms from "./common/TestSmsWidget"; import copy from "copy-to-clipboard"; import {CaptchaPreview} from "./common/CaptchaPreview"; import * as OrganizationBackend from "./backend/OrganizationBackend"; -import {CountryCodeSelect} from "./common/CountryCodeSelect"; +import {CountryCodeSelect} from "./common/select/CountryCodeSelect"; const {Option} = Select; const {TextArea} = Input; @@ -110,7 +110,7 @@ class ProviderEditPage extends React.Component { getClientSecretLabel(provider) { switch (provider.category) { case "Email": - return Setting.getLabel(i18next.t("login:Password"), i18next.t("login:Password - Tooltip")); + return Setting.getLabel(i18next.t("general:Password"), i18next.t("general:Password - Tooltip")); case "SMS": if (provider.type === "Volc Engine SMS") { return Setting.getLabel(i18next.t("provider:Secret access key"), i18next.t("provider:Secret access key - Tooltip")); @@ -130,6 +130,24 @@ class ProviderEditPage extends React.Component { } } + getProviderSubTypeOptions(type) { + if (type === "WeCom" || type === "Infoflow") { + return ( + [ + {id: "Internal", name: i18next.t("provider:Internal")}, + {id: "Third-party", name: i18next.t("provider:Third-party")}, + ] + ); + } else if (type === "Aliyun Captcha") { + return [ + {id: "nc", name: i18next.t("provider:Sliding Validation")}, + {id: "ic", name: i18next.t("provider:Intelligent Validation")}, + ]; + } else { + return []; + } + } + getAppIdRow(provider) { let text = ""; let tooltip = ""; @@ -315,7 +333,7 @@ class ProviderEditPage extends React.Component { this.updateProviderField("subType", value); }}> { - Setting.getProviderSubTypeOptions(this.state.provider.type).map((providerSubType, index) => ) + this.getProviderSubTypeOptions(this.state.provider.type).map((providerSubType, index) => ) } @@ -331,7 +349,10 @@ class ProviderEditPage extends React.Component { this.updateProviderField("method", value); }}> { - [{name: "Normal"}, {name: "Silent"}].map((method, index) => ) + [ + {id: "Normal", name: i18next.t("provider:Normal")}, + {id: "Silent", name: i18next.t("provider:Silent")}, + ].map((method, index) => ) } diff --git a/web/src/Setting.js b/web/src/Setting.js index 10424134..189bf7a9 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -14,7 +14,7 @@ import React from "react"; import {Link} from "react-router-dom"; -import {Checkbox, Form, Modal, Select, Tag, Tooltip, message, theme} from "antd"; +import {Select, Tag, Tooltip, message, theme} from "antd"; import {QuestionCircleTwoTone} from "@ant-design/icons"; import {isMobile as isMobileDevice} from "react-device-detect"; import "./i18n"; @@ -552,10 +552,6 @@ export function addRow(array, row, position = "end") { return position === "end" ? [...array, row] : [row, ...array]; } -export function prependRow(array, row) { - return [row, ...array]; -} - export function deleteRow(array, i) { // return array = array.slice(0, i).concat(array.slice(i + 1)); return [...array.slice(0, i), ...array.slice(i + 1)]; @@ -585,76 +581,6 @@ export function isMobile() { return isMobileDevice; } -export function getTermsOfUseContent(url, setTermsOfUseContent) { - fetch(url, { - method: "GET", - }).then(r => { - r.text().then(setTermsOfUseContent); - }); -} - -export function isAgreementRequired(application) { - if (application) { - const agreementItem = application.signupItems.find(item => item.name === "Agreement"); - if (!agreementItem || agreementItem.rule === "None" || !agreementItem.rule) { - return false; - } - if (agreementItem.required) { - return true; - } - } - return false; -} - -export function isDefaultTrue(application) { - const agreementItem = application.signupItems.find(item => item.name === "Agreement"); - - return isAgreementRequired(application) && agreementItem.rule === "Signin (Default True)"; -} - -export function renderAgreement(required, onClick, noStyle, layout, initialValue) { - return ( - - - {i18next.t("signup:Accept")}  - - {i18next.t("signup:Terms of Use")} - - - - ); -} - -export function renderModal(isOpen, onOk, onCancel, doc) { - return ( - -