방: 나가기 버튼을 막대로 빼고 ← 홈도 나가기로, 이름 눌러 기록 카드, 게스트 경고, 관리자 계정별 기록

- 방 막대에 [🚪 나가기]를 두고 메뉴에서는 뺀다. [← 홈]도 같은 동작. 한 번 누르면 바로 나가고,
  게임 중에 자리에 앉아 있을 때만 기권 확인을 묻는다. 휴대폰은 방 링크 복사를 메뉴로 옮겨 한 줄에 맞춘다.
- 자리·관전자·결과 화면의 이름을 누르면 기록 카드(이 게임 판·승·패·무·승률, 이 방 전적, 전체 합계).
  GET /api/users/:id/stats (로그인 필요).
- 게스트 경고: 이름 정하기, 로그인 페이지, /me, 게스트가 있는 대기실.
- 관리자 사용자 상세: 전체 기록, 게임별 기록 표, 최근 게임(GET /api/admin/users/:id/games). 목록에 전적 열(PC).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-08 11:34:08 +09:00
parent f93ff4f656
commit 43156a9f63
17 changed files with 462 additions and 39 deletions

View File

@@ -1,12 +1,15 @@
/** 관리자 사이트 (docs/14-admin.md). Downloaded only when /admin is opened. */
import { useCallback, useEffect, useState, type ReactNode } from 'react';
import { NavLink, Route, Routes, useNavigate, useParams } from 'react-router';
import { formatRoomCode } from '@bg/shared/lite';
import { formatRoomCode, type MyGameSummary } from '@bg/shared/lite';
import { ConfirmSheet, Sheet } from '../../components/ui';
import { apiCall, discordLoginUrl, type Role } from '../../net/api';
import { useSession } from '../../store/session';
import { toast } from '../../store/toast';
import { SchemaForm, type JsonSchema } from './SchemaForm';
import { gameName } from '../../components/GameNotice';
import { RecordCell, record, recordText, resultLabel, sumStats } from '../../components/PlayerCard';
import type { GameStat } from '../../net/api';
const a = {
get: <T,>(p: string) => apiCall<T>('GET', `/api/admin${p}`),
@@ -448,6 +451,7 @@ function Users() {
<th>닉네임</th>
<th className="wide-only">로그인</th>
<th>권한</th>
<th className="wide-only">전적</th>
<th className="wide-only">마지막 접속</th>
<th>상태</th>
</tr>
@@ -461,6 +465,7 @@ function Users() {
</td>
<td className="wide-only small">{u.kind === 'member' ? `디스코드 ${u.discordName ?? ''} (${u.discordId})` : '게스트'}</td>
<td>{u.role === 'superadmin' ? '슈퍼어드민' : u.role === 'admin' ? '어드민' : '-'}</td>
<td className="wide-only small">{u.played ? `${u.played}판 ${u.wins}승` : '-'}</td>
<td className="wide-only small">{time(u.lastSeenAt)}</td>
<td>{u.banned ? <span className="badge warning">제한</span> : <span className="badge success">정상</span>}</td>
</tr>
@@ -474,7 +479,7 @@ function Users() {
}
function UserSheet({ id, onClose }: { id: string; onClose: () => void }) {
const [d, reload] = useLoad<{ user: any; stats: any[] }>(`/users/${id}`);
const [d, reload] = useLoad<{ user: any; stats: GameStat[] }>(`/users/${id}`);
const [nick, setNick] = useState('');
const [reason, setReason] = useState('');
const [ask, setAsk] = useState<null | 'delete' | 'logout'>(null);
@@ -504,7 +509,8 @@ function UserSheet({ id, onClose }: { id: string; onClose: () => void }) {
{d.user.activeRoom && <> · 지금 방 {formatRoomCode(d.user.activeRoom)}</>}
{guestDeletion(d.user) && <> · {guestDeletion(d.user)}</>}
</p>
<p className="small">{d.stats.length ? d.stats.map((s) => `${s.gameId} ${s.played}판 ${s.wins}승`).join(' · ') : '기록 없음'}</p>
<UserRecord stats={d.stats} />
<UserGames id={id} />
<div className="row">
<input className="input" style={{ flex: 1 }} value={nick} onChange={(e) => setNick(e.target.value)} maxLength={20} aria-label="닉네임" />
<button className="btn btn-secondary" onClick={() => run(a.patch(`/users/${id}`, { nickname: nick }), '닉네임을 바꿨어요.')}>
@@ -557,6 +563,120 @@ function UserSheet({ id, onClose }: { id: string; onClose: () => void }) {
);
}
/** 전체 기록 + 게임별 기록 (연습 게임·무효 판은 빠져요). */
function UserRecord({ stats }: { stats: GameStat[] }) {
const total = record(sumStats(stats));
return (
<section className="stack" style={{ gap: 10 }} aria-label="기록">
<h3>전체 기록</h3>
{total.played === 0 ? (
<p className="muted small">끝까지 한 게임이 없어요.</p>
) : (
<>
<div className="record-grid">
<RecordCell label="판" value={total.played} />
<RecordCell label="승" value={total.wins} />
<RecordCell label="패" value={total.losses} />
<RecordCell label="무" value={total.draws} />
<RecordCell label="승률" value={`${total.rate}%`} />
</div>
<h3>게임별 기록</h3>
<table className="data-table compact">
<thead>
<tr>
<th>게임</th>
<th>판</th>
<th>승</th>
<th>패</th>
<th>무</th>
<th>승률</th>
</tr>
</thead>
<tbody>
{stats.map((s) => {
const r = record(s);
return (
<tr key={s.gameId}>
<td>{gameName(s.gameId)}</td>
<td>{r.played}</td>
<td>{r.wins}</td>
<td>{r.losses}</td>
<td>{r.draws}</td>
<td>{r.rate}%</td>
</tr>
);
})}
</tbody>
</table>
</>
)}
<p className="muted small">컴퓨터와 한 연습 게임과 무효 처리된 판은 기록에 넣지 않아요.</p>
</section>
);
}
/** 최근 게임: 끝난 판, 최신순 (내 게임 기록과 같은 목록). */
function UserGames({ id }: { id: string }) {
const [games, setGames] = useState<MyGameSummary[] | null>(null);
const [next, setNext] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const load = useCallback(
(before: string | null) => {
setLoading(true);
a.get<{ games: MyGameSummary[]; next: string | null }>(`/users/${id}/games${before ? `?before=${before}` : ''}`)
.then((r) => {
setGames((prev) => [...(before ? (prev ?? []) : []), ...r.games]);
setNext(r.next);
})
.catch((e) => toast((e as Error).message, 'error'))
.finally(() => setLoading(false));
},
[id],
);
useEffect(() => load(null), [load]);
return (
<section className="stack" style={{ gap: 10 }} aria-label="최근 게임">
<h3>최근 게임</h3>
{games === null ? (
<p className="muted small">불러오는 중…</p>
) : games.length === 0 ? (
<p className="muted small">끝난 게임이 없어요.</p>
) : (
<table className="data-table compact">
<thead>
<tr>
<th>날짜</th>
<th>게임</th>
<th>결과</th>
<th className="wide-only">함께 한 사람</th>
</tr>
</thead>
<tbody>
{games.map((g) => (
<tr key={g.gamePk}>
<td className="small">{time(g.startedAt)}</td>
<td>{gameName(g.gameId)}</td>
<td>{resultLabel(g)}</td>
<td className="wide-only small">
{g.players
.filter((p) => !p.me)
.map((p) => p.nickname)
.join(', ') || '-'}
</td>
</tr>
))}
</tbody>
</table>
)}
{next && (
<button className="btn btn-secondary btn-block" disabled={loading} onClick={() => load(next)}>
{loading ? '불러오는 중…' : '더 보기'}
</button>
)}
</section>
);
}
// ------------------------------------------------------------------ admins (superadmin)
function Admins() {