支持游戏白名单按短号添加用户
This commit is contained in:
parent
26f8d0767f
commit
abb5ba9c52
@ -367,11 +367,12 @@ export function listGameWhitelistUsers(
|
||||
).then((result) => ({ ...result, items: (result.items || []).map(normalizeGameWhitelistUser) }));
|
||||
}
|
||||
|
||||
export function addGameWhitelistUser(gameId: string, userId: string): Promise<GameWhitelistUserDto> {
|
||||
export function addGameWhitelistUser(gameId: string, userIdentifier: string): Promise<GameWhitelistUserDto> {
|
||||
const endpoint = API_ENDPOINTS.addGameWhitelistUser;
|
||||
return apiRequest<GameWhitelistUserDto, { userId: string }>(
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -47,9 +47,8 @@ export function GameWhitelistDialog({ open, page, onClose }) {
|
||||
<form className={styles.whitelistSearchRow} onSubmit={page.addWhitelistUser}>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="搜索用户 ID"
|
||||
placeholder="输入内部用户 ID"
|
||||
slotProps={{ htmlInput: { inputMode: "numeric" } }}
|
||||
label="搜索用户 ID / 短号 / 靓号"
|
||||
placeholder="输入任一用户标识,自动匹配真实用户"
|
||||
value={page.whitelistUserId}
|
||||
onChange={(event) => page.setWhitelistUserId(event.target.value)}
|
||||
/>
|
||||
@ -68,7 +67,7 @@ export function GameWhitelistDialog({ open, page, onClose }) {
|
||||
<div className={styles.whitelistTable}>
|
||||
<div className={styles.whitelistTableHeader}>
|
||||
<span>用户</span>
|
||||
<span>用户 ID</span>
|
||||
<span>内部 ID / 当前短号</span>
|
||||
<span>状态</span>
|
||||
<span>加入时间</span>
|
||||
<span>操作</span>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user