Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions frontend/src/components/console/settings/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ import { Spinner } from "@/components/ui/spinner"
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia } from "@/components/ui/empty"
import { WechatMpBindDialog } from "@/components/console/wechat-mp-bind-dialog"
import { useCommonData } from "@/components/console/data-provider"
import { useAppRuntime } from "@/components/app-runtime-provider"
import { IS_ONLINE_EDITION } from "@/utils/edition"
import { shouldShowWechatMp } from "@/utils/wechat-mp"
import { useTranslation } from "react-i18next"

/** Receiver type used by the UI; wechat_work maps to the API wecom kind. */
Expand Down Expand Up @@ -103,6 +105,8 @@ function getReceiverTypeIcon(type: ReceiverType): React.ReactNode {
export default function Notifications() {
const { t } = useTranslation()
const { user, reloadUser } = useCommonData()
const { serverConfig } = useAppRuntime()
const showWechatMp = shouldShowWechatMp(IS_ONLINE_EDITION, serverConfig?.region)
const [channels, setChannels] = useState<DomainNotifyChannel[]>([])
const [eventTypes, setEventTypes] = useState<ConstsNotifyEventTypeInfo[]>([])
const [loadingChannels, setLoadingChannels] = useState(true)
Expand Down Expand Up @@ -456,7 +460,7 @@ export default function Notifications() {
</Button>
</div>
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain">
{IS_ONLINE_EDITION && wechatMpStatusCard}
{showWechatMp && wechatMpStatusCard}
{loadingChannels ? (
loadingContent
) : channels.length > 0 ? (
Expand Down Expand Up @@ -605,7 +609,7 @@ export default function Notifications() {
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
{IS_ONLINE_EDITION && (
{showWechatMp && (
<>
<WechatMpBindDialog
open={wechatMpBindDialogOpen}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/wechat-mp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function shouldShowWechatMp(
isOnlineEdition: boolean,
region?: string,
): boolean {
return isOnlineEdition && region === "cn";
}
22 changes: 22 additions & 0 deletions frontend/test/console-settings-notifications-i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import test from "node:test";

import cn from "../src/i18n/resources/cn.ts";
import en from "../src/i18n/resources/en.ts";
import { shouldShowWechatMp } from "../src/utils/wechat-mp.ts";

const source = readFileSync(
new URL("../src/components/console/settings/notifications.tsx", import.meta.url),
Expand All @@ -25,3 +26,24 @@ test("设置通知页面提供中英文资源", () => {
assert.equal(cn.consoleSettings.notifications.remove.description, "确定要移除接收端 \"{{name}}\" 吗?此操作不可撤销。");
assert.equal(en.consoleSettings.notifications.remove.description, "Remove receiver \"{{name}}\"? This action cannot be undone.");
});

test("海外 SaaS 隐藏微信公众号绑定并保留企业微信机器人", () => {
assert.match(source, /useAppRuntime/);
assert.match(
source,
/const showWechatMp = shouldShowWechatMp\(IS_ONLINE_EDITION, serverConfig\?\.region\)/,
);
assert.match(source, /\{showWechatMp && wechatMpStatusCard\}/);
assert.match(
source,
/\{showWechatMp && \([\s\S]*<WechatMpBindDialog[\s\S]*open=\{wechatMpUnbindDialogOpen\}[\s\S]*\n\s{6}\)\}/,
);
assert.match(source, /value: "wechat_work"/);
});

test("微信公众号绑定仅在国内在线版显示", () => {
assert.equal(shouldShowWechatMp(true, "cn"), true);
assert.equal(shouldShowWechatMp(true, "global"), false);
assert.equal(shouldShowWechatMp(true, undefined), false);
assert.equal(shouldShowWechatMp(false, "cn"), false);
});
Loading