From ace8e9da065f2e7823ddac9c9ad1a350ee9e9135 Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Wed, 22 Feb 2023 12:10:55 +0800 Subject: [PATCH] Refactor getAppIdRow() --- web/src/ProviderEditPage.js | 78 +++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index d6365802..71e86a5b 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -128,40 +128,52 @@ class ProviderEditPage extends React.Component { } } - getAppIdRow() { - let text, tooltip; - if (this.state.provider.category === "SMS" && this.state.provider.type === "Tencent Cloud SMS") { - text = i18next.t("provider:App ID"); - tooltip = i18next.t("provider:App ID - Tooltip"); - } else if (this.state.provider.type === "WeCom" && this.state.provider.subType === "Internal") { - text = i18next.t("provider:Agent ID"); - tooltip = i18next.t("provider:Agent ID - Tooltip"); - } else if (this.state.provider.type === "Infoflow") { - text = i18next.t("provider:Agent ID"); - tooltip = i18next.t("provider:Agent ID - Tooltip"); - } else if (this.state.provider.category === "SMS" && this.state.provider.type === "Volc Engine SMS") { - text = i18next.t("provider:SMS account"); - tooltip = i18next.t("provider:SMS account - Tooltip"); - } else if (this.state.provider.category === "SMS" && this.state.provider.type === "Huawei Cloud SMS") { - text = i18next.t("provider:Channel No."); - tooltip = i18next.t("provider:Channel No. - Tooltip"); - } else if (this.state.provider.category === "Email" && this.state.provider.type === "SUBMAIL") { - text = i18next.t("provider:App ID"); - tooltip = i18next.t("provider:App ID - Tooltip"); - } else { - return null; + getAppIdRow(provider) { + let text = ""; + let tooltip = ""; + + if (provider.category === "OAuth") { + if (provider.type === "WeCom" && provider.subType === "Internal") { + text = i18next.t("provider:Agent ID"); + tooltip = i18next.t("provider:Agent ID - Tooltip"); + } else if (provider.type === "Infoflow") { + text = i18next.t("provider:Agent ID"); + tooltip = i18next.t("provider:Agent ID - Tooltip"); + } + } else if (provider.category === "SMS") { + if (provider.type === "Tencent Cloud SMS") { + text = i18next.t("provider:App ID"); + tooltip = i18next.t("provider:App ID - Tooltip"); + } else if (provider.type === "Volc Engine SMS") { + text = i18next.t("provider:SMS account"); + tooltip = i18next.t("provider:SMS account - Tooltip"); + } else if (provider.type === "Huawei Cloud SMS") { + text = i18next.t("provider:Channel No."); + tooltip = i18next.t("provider:Channel No. - Tooltip"); + } + } else if (provider.category === "Email") { + if (provider.type === "SUBMAIL") { + text = i18next.t("provider:App ID"); + tooltip = i18next.t("provider:App ID - Tooltip"); + } } - return - - {Setting.getLabel(text, tooltip)} : - - - { - this.updateProviderField("appId", e.target.value); - }} /> - - ; + if (text === "" && tooltip === "") { + return null; + } else { + return ( + + + {Setting.getLabel(text, tooltip)} : + + + { + this.updateProviderField("appId", e.target.value); + }} /> + + + ); + } } loadSamlConfiguration() { @@ -750,7 +762,7 @@ class ProviderEditPage extends React.Component { ) : null } - {this.getAppIdRow()} + {this.getAppIdRow(this.state.provider)} {Setting.getLabel(i18next.t("provider:Provider URL"), i18next.t("provider:Provider URL - Tooltip"))} :