diff --git a/components/settings-content.tsx b/components/settings-content.tsx
index 223c2fc..913c794 100644
--- a/components/settings-content.tsx
+++ b/components/settings-content.tsx
@@ -14,7 +14,15 @@ import {
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
-import { logoutAdmin, getMe, changeAdminPassword, LoginFailedError, NetworkError } from "@/lib/api/admin"
+import {
+ logoutAdmin,
+ getMe,
+ changeAdminPassword,
+ LoginFailedError,
+ NetworkError,
+ resolveAdminDisplayNameFromMe,
+ resolveAdminNumberFromMe,
+} from "@/lib/api/admin"
import { useToast } from "@/hooks/use-toast"
import { Lock } from "lucide-react"
@@ -47,12 +55,10 @@ export function SettingsContent() {
setIsLoading(true);
try {
const response = await getMe();
- // ADMIN의 경우: participant.name = adminNumber, participant.phone = email
- // 이름은 백엔드에서 제공하지 않으므로 더미 데이터 사용
setAdminProfile({
- name: "Admin", // 더미 데이터 (백엔드에서 제공되지 않음)
- email: response.participant.phone || "", // email
- adminNumber: response.participant.name || "", // adminNumber
+ name: resolveAdminDisplayNameFromMe(response),
+ email: response.participant.phone || "",
+ adminNumber: resolveAdminNumberFromMe(response),
});
} catch (error) {
if (error instanceof LoginFailedError) {
@@ -237,7 +243,7 @@ export function SettingsContent() {
{isLoading ? (
diff --git a/components/users-content.tsx b/components/users-content.tsx
index 9e4c6b9..cc3218b 100644
--- a/components/users-content.tsx
+++ b/components/users-content.tsx
@@ -1,228 +1,346 @@
"use client"
-import { useState } from "react"
-import { ChevronLeft, ChevronRight } from "lucide-react"
-
-type ConnectionStatus = "연결됨" | "대기 중"
-type SubmissionStatus = "시작 전" | "진행 중" | "제출 완료"
+import { useCallback, useEffect, useMemo, useState } from "react"
+import { ChevronDown, ChevronLeft, ChevronRight, Search } from "lucide-react"
+import {
+ getBoard,
+ getExams,
+ type Exam,
+ type ExamineeBoardEntry,
+} from "@/lib/api/admin"
+import {
+ isAdminUsersSubmissionCountedComplete,
+ resolveAdminUsersConnectionStatus,
+ resolveAdminUsersSubmissionStatus,
+ type AdminUsersConnectionStatus,
+ type AdminUsersSubmissionStatus,
+} from "@/lib/admin-users-participant-status"
interface Participant {
id: string
name: string
+ examLabel: string
phone: string
- connectionStatus: ConnectionStatus
- submissionStatus: SubmissionStatus
+ connectionStatus: AdminUsersConnectionStatus
+ submissionStatus: AdminUsersSubmissionStatus
tokenUsage: number
}
-const initialParticipants: Participant[] = [
- {
- id: "1",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "제출 완료",
- tokenUsage: 1250,
- },
- {
- id: "2",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "진행 중",
- tokenUsage: 890,
- },
- {
- id: "3",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "대기 중",
- submissionStatus: "시작 전",
- tokenUsage: 0,
- },
- {
- id: "4",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "진행 중",
- tokenUsage: 1450,
- },
- {
- id: "5",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "시작 전",
- tokenUsage: 0,
- },
- {
- id: "6",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "대기 중",
- submissionStatus: "시작 전",
- tokenUsage: 0,
- },
- {
- id: "7",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "제출 완료",
- tokenUsage: 1120,
- },
- {
- id: "8",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "진행 중",
- tokenUsage: 760,
- },
- {
- id: "9",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "대기 중",
- submissionStatus: "시작 전",
- tokenUsage: 0,
- },
- {
- id: "10",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "제출 완료",
- tokenUsage: 1340,
- },
- {
- id: "11",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "대기 중",
- submissionStatus: "시작 전",
- tokenUsage: 0,
- },
- {
- id: "12",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "진행 중",
- tokenUsage: 815,
- },
- {
- id: "13",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "제출 완료",
- tokenUsage: 980,
- },
- {
- id: "14",
- name: "Rajesh Kumar",
- phone: "+91 98765 43210",
- connectionStatus: "연결됨",
- submissionStatus: "제출 완료",
- tokenUsage: 1025,
- },
-]
-
-function ConnectionBadge({ status }: { status: ConnectionStatus }) {
- const isConnected = status === "연결됨"
+function resolveExamDisplayLabel(exam: Exam): string {
+ const code = exam.entryCode?.trim()
+ if (code) return code
+ return exam.title?.trim() || String(exam.id)
+}
+
+function mapBoardEntry(entry: ExamineeBoardEntry, exam: Exam): Participant {
+ const connectionStatus = resolveAdminUsersConnectionStatus(entry, exam)
+ return {
+ id: `${exam.id}-${entry.examParticipantId}`,
+ name: entry.name || "–",
+ examLabel: resolveExamDisplayLabel(exam),
+ phone: entry.phoneMasked || "–",
+ connectionStatus,
+ submissionStatus: resolveAdminUsersSubmissionStatus(entry, exam, connectionStatus),
+ tokenUsage: entry.tokenUsed ?? 0,
+ }
+}
+
+function ConnectionBadge({ status }: { status: AdminUsersConnectionStatus }) {
+ const styles: Record
= {
+ "응시 완료": "border-[#16A34A] bg-[#DCFCE7] text-[#16A34A]",
+ "응시 중": "border-[#3B82F6] bg-white text-[#3B82F6]",
+ "대기 중": "border-[#6B7280] bg-white text-[#6B7280]",
+ "종료됨": "border-[#9CA3AF] bg-[#F3F4F6] text-[#6B7280]",
+ }
return (
-
+
{status}
)
}
-function SubmissionBadge({ status }: { status: SubmissionStatus }) {
- const styles = {
+function SubmissionBadge({ status }: { status: AdminUsersSubmissionStatus }) {
+ const styles: Record = {
"시작 전": "bg-[#F3F4F6] text-[#6B7280]",
"진행 중": "bg-[#E0EDFF] text-[#3B82F6]",
+ "채점 중": "bg-[#FEF3C7] text-[#D97706]",
"제출 완료": "bg-[#DCFCE7] text-[#16A34A]",
+ "채점 완료": "bg-[#DCFCE7] text-[#16A34A]",
+ "미제출": "bg-[#F3F4F6] text-[#6B7280]",
+ "제출 실패": "bg-[#FEE2E2] text-[#DC2626]",
}
return {status}
}
+/** 참가자 목록 그리드: 좌측(이름·시험) / 중앙(전화·상태) / 우측(토큰) */
+const PARTICIPANT_LIST_GRID_COLS =
+ "grid-cols-[1.2fr_1fr_1fr_minmax(5.5rem,1fr)_minmax(5.5rem,1fr)_minmax(4.5rem,0.95fr)]"
+
export function UsersContent() {
- const [participants] = useState(initialParticipants)
+ const [exams, setExams] = useState([])
+ const [participants, setParticipants] = useState([])
+ const [isLoadingExams, setIsLoadingExams] = useState(true)
+ const [isLoadingBoard, setIsLoadingBoard] = useState(false)
+ const [error, setError] = useState(null)
+ const [selectedExamId, setSelectedExamId] = useState("all")
+ const [searchQuery, setSearchQuery] = useState("")
const [currentPage, setCurrentPage] = useState(1)
const pageSize = 12
- const totalPages = Math.ceil(participants.length / pageSize)
+ useEffect(() => {
+ let cancelled = false
+ async function loadExams() {
+ setIsLoadingExams(true)
+ try {
+ const data = await getExams()
+ if (!cancelled) setExams(data)
+ } catch (e) {
+ console.error("[Users] Failed to load exams", e)
+ if (!cancelled) {
+ setExams([])
+ setError("시험 세션 목록을 불러오는 데 실패했습니다.")
+ }
+ } finally {
+ if (!cancelled) setIsLoadingExams(false)
+ }
+ }
+ loadExams()
+ return () => {
+ cancelled = true
+ }
+ }, [])
+
+ const loadParticipants = useCallback(async () => {
+ if (isLoadingExams) return
+
+ setIsLoadingBoard(true)
+ setError(null)
+ try {
+ if (exams.length === 0) {
+ setParticipants([])
+ setCurrentPage(1)
+ return
+ }
+
+ let mapped: Participant[] = []
+
+ if (selectedExamId === "all") {
+ const boards = await Promise.all(
+ exams.map(async (exam) => {
+ try {
+ const entries = await getBoard(exam.id)
+ return entries.map((entry) => mapBoardEntry(entry, exam))
+ } catch (e) {
+ console.error(`[Users] getBoard failed for examId=${exam.id}`, e)
+ return [] as Participant[]
+ }
+ })
+ )
+ mapped = boards.flat()
+ } else {
+ const examId = Number.parseInt(selectedExamId, 10)
+ const exam = exams.find((e) => e.id === examId)
+ if (!exam || Number.isNaN(examId)) {
+ setParticipants([])
+ setCurrentPage(1)
+ return
+ }
+ const board = await getBoard(examId)
+ mapped = board.map((entry) => mapBoardEntry(entry, exam))
+ }
+
+ setParticipants(mapped)
+ setCurrentPage(1)
+ } catch (e) {
+ console.error("[Users] Failed to load participants", e)
+ setParticipants([])
+ setError("참가자 목록을 불러오는 데 실패했습니다.")
+ } finally {
+ setIsLoadingBoard(false)
+ }
+ }, [exams, isLoadingExams, selectedExamId])
+
+ useEffect(() => {
+ void loadParticipants()
+ }, [loadParticipants])
+
+ const filteredParticipants = useMemo(() => {
+ const q = searchQuery.trim().toLowerCase()
+ if (!q) return participants
+ return participants.filter((p) => {
+ const name = p.name.toLowerCase()
+ const exam = p.examLabel.toLowerCase()
+ return name.includes(q) || exam.includes(q)
+ })
+ }, [participants, searchQuery])
+
+ const totalPages = Math.max(1, Math.ceil(filteredParticipants.length / pageSize))
const startIndex = (currentPage - 1) * pageSize
const endIndex = currentPage * pageSize
- const visibleParticipants = participants.slice(startIndex, endIndex)
+ const visibleParticipants = filteredParticipants.slice(startIndex, endIndex)
- const displayStart = participants.length === 0 ? 0 : startIndex + 1
- const displayEnd = Math.min(endIndex, participants.length)
+ const displayStart = filteredParticipants.length === 0 ? 0 : startIndex + 1
+ const displayEnd = Math.min(endIndex, filteredParticipants.length)
+
+ const completedCount = useMemo(
+ () =>
+ filteredParticipants.filter((p) =>
+ isAdminUsersSubmissionCountedComplete(p.submissionStatus)
+ ).length,
+ [filteredParticipants]
+ )
+
+ const isLoading = isLoadingExams || isLoadingBoard
+
+ useEffect(() => {
+ setCurrentPage(1)
+ }, [searchQuery, selectedExamId])
return (
- {/* Top Header Bar */}
- {/* Main Content Panel */}
- {/* Table Container */}
+
+
+
+
+
+
+
+
+ setSearchQuery(e.target.value)}
+ className="w-full rounded-lg border border-[#E5E5E5] bg-white py-2 pl-10 pr-4 text-sm text-[#1A1A1A] placeholder-[#9CA3AF] outline-none transition-colors focus:border-[#3B82F6] focus:ring-1 focus:ring-[#3B82F6]"
+ />
+
+
+
+ {error && (
+
+ )}
+
- {/* Table Header */}
-
-
이름
-
전화번호
-
연결 상태
-
제출 상태
-
토큰 사용량
+
+
+ 이름
+
+
+ 시험
+
+
+
+ 전화번호
+
+
+
+
+ 응시 상태
+
+
+
+
+ 제출 상태
+
+
+
+
+ 토큰 사용량
+
+
- {/* Table Body */}
- {visibleParticipants.map((participant, index) => (
-
-
{participant.name}
-
{participant.phone}
-
-
-
-
-
-
-
- {participant.tokenUsage.toLocaleString()}
-
+ {isLoading ? (
+
+ ) : visibleParticipants.length === 0 ? (
+
+
표시할 참가자가 없습니다.
+ {!error && filteredParticipants.length === 0 && participants.length > 0 && (
+
검색 조건에 맞는 참가자가 없습니다.
+ )}
+ {!error && participants.length === 0 && (
+
선택한 세션에 참가자가 없습니다.
+ )}
- ))}
+ ) : (
+ visibleParticipants.map((participant, index) => (
+
+
+ {participant.name}
+
+
+ {participant.examLabel}
+
+
+
+ {participant.phone}
+
+
+
+
+
+
+
+
+
+
+ {participant.tokenUsage.toLocaleString()}
+
+
+
+ ))
+ )}
- {/* Pagination */}
- {participants.length > 0 && (
+ {!isLoading && filteredParticipants.length > 0 && (
- 총 {participants.length}명 중 {displayStart}–{displayEnd}명 보여주는 중
+ 총 {filteredParticipants.length}명 중 {displayStart}–{displayEnd}명 표시
+ {completedCount > 0 && ` · 제출 완료 ${completedCount}명`}