diff --git a/src/features/games/api.ts b/src/features/games/api.ts index 1ff9519..2003562 100644 --- a/src/features/games/api.ts +++ b/src/features/games/api.ts @@ -367,11 +367,12 @@ export function listGameWhitelistUsers( ).then((result) => ({ ...result, items: (result.items || []).map(normalizeGameWhitelistUser) })); } -export function addGameWhitelistUser(gameId: string, userId: string): Promise { +export function addGameWhitelistUser(gameId: string, userIdentifier: string): Promise { const endpoint = API_ENDPOINTS.addGameWhitelistUser; return apiRequest( apiEndpointPath(API_OPERATIONS.addGameWhitelistUser, { game_id: gameId }), - { body: { userId }, method: endpoint.method }, + // 兼容已发布契约字段 userId;服务端会把内部 ID、默认短号或当前靓号统一解析成 owner user_id。 + { body: { userId: userIdentifier }, method: endpoint.method }, ).then(normalizeGameWhitelistUser); } diff --git a/src/features/games/components/GameWhitelistDialog.jsx b/src/features/games/components/GameWhitelistDialog.jsx index 3ee0b63..b0994ae 100644 --- a/src/features/games/components/GameWhitelistDialog.jsx +++ b/src/features/games/components/GameWhitelistDialog.jsx @@ -47,9 +47,8 @@ export function GameWhitelistDialog({ open, page, onClose }) {
page.setWhitelistUserId(event.target.value)} /> @@ -68,7 +67,7 @@ export function GameWhitelistDialog({ open, page, onClose }) {
用户 - 用户 ID + 内部 ID / 当前短号 状态 加入时间 操作 diff --git a/src/features/games/components/GameWhitelistDialog.test.jsx b/src/features/games/components/GameWhitelistDialog.test.jsx index 2e1a9aa..b6a2032 100644 --- a/src/features/games/components/GameWhitelistDialog.test.jsx +++ b/src/features/games/components/GameWhitelistDialog.test.jsx @@ -24,7 +24,7 @@ test("renders current members and exposes whitelist toggle, add and remove actio }, ], whitelistLoading: false, - whitelistUserId: "42", + whitelistUserId: "VIP2026", }; render( @@ -36,6 +36,7 @@ test("renders current members and exposes whitelist toggle, add and remove actio expect(screen.getByText("游戏白名单 · Private Slot")).toBeInTheDocument(); expect(screen.getByText("Alice")).toBeInTheDocument(); expect(screen.getByText("90001")).toBeInTheDocument(); + expect(screen.getByRole("textbox", { name: "搜索用户 ID / 短号 / 靓号" })).toHaveValue("VIP2026"); await user.click(screen.getByRole("switch", { name: "游戏白名单状态" })); expect(page.changeWhitelistEnabled).toHaveBeenCalledWith(false); diff --git a/src/features/games/hooks/useGamesPage.js b/src/features/games/hooks/useGamesPage.js index 2b827c6..1082bfc 100644 --- a/src/features/games/hooks/useGamesPage.js +++ b/src/features/games/hooks/useGamesPage.js @@ -440,17 +440,17 @@ export function useGamesPage() { const addWhitelistUser = async (event) => { event.preventDefault(); - const userId = whitelistUserId.trim(); - if (!whitelistGame || !/^\d+$/.test(userId) || userId === "0") { - showToast("请输入正确的用户 ID", "error"); + const userIdentifier = whitelistUserId.trim(); + if (!whitelistGame || !userIdentifier) { + showToast("请输入用户 ID、短号或靓号", "error"); return; } setLoadingAction(`whitelist-add-${whitelistGame.gameId}`); try { - await addGameWhitelistUser(whitelistGame.gameId, userId); + const matchedUser = await addGameWhitelistUser(whitelistGame.gameId, userIdentifier); setWhitelistUserId(""); await loadWhitelist(whitelistGame); - showToast("用户已加入白名单", "success"); + showToast(`已匹配用户 ${matchedUser.displayUserId || matchedUser.userId} 并加入白名单`, "success"); } catch (err) { showToast(err.message || "添加白名单用户失败", "error"); } finally {