- 지원 티켓 작성 UI 신설(설정)·관리자 해결 노트 입력 신설(Admin): 서버 계약은 있었으나 웹 진입점이 없던 2결함 - a11y: outline 채널 포커스 링(ui/shell css), 세션바 44px 터치 타깃, 청록 하드코딩 그라디언트를 테마 토큰으로 교체, 설정 라벨/헤딩/대비·리뷰 44px·모바일 오버플로 수정 - uc-*.spec.ts 16테마 239 시나리오 신규(수집 1109 tests/61 files), 기존 스펙 5종 계약 드리프트 교정 - breakpoint-sweep: widthsFor 솎아내기가 실기기 대표 폭(360/390/1024)을 탈락시키는 테스트 결함 수정 — keep 시드를 전체 DEVICE_WIDTHS로, 3연폭 예외는 솎아내기 발생 여부 기준으로 - 검증: tsc PASS, 병렬 게이트 1040 passed(데스크톱 밀도 충돌 1건 해소 후 focused 68/68 GREEN), 직렬 게이트 52/5/4 삼각화 — breakpoint(테스트 결함)·kb(낡은 dev API 재기동)·voice(일시적) 해소, 교사 재평가 2건은 엔진 구독 한도(resets 3pm)로 skip 후 재검증 대기 - 문서/SSOT: HANDOFF·TODO·대시보드·testing 가이드 동기화, 증거 usecase-tdd-2026-08-18.json, SSOT 체커 PASS(59)
1562 lines
63 KiB
TypeScript
1562 lines
63 KiB
TypeScript
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
import { AppShell } from "../components/shell/AppShell";
|
|
import {
|
|
Badge,
|
|
Button,
|
|
Field,
|
|
Icon,
|
|
Input,
|
|
Kicker,
|
|
Panel,
|
|
surfaceClassName,
|
|
type IconName,
|
|
} from "../components/ui";
|
|
import { roleLabel, useAuth } from "../lib/auth";
|
|
import {
|
|
adminApi,
|
|
adminEngineApi,
|
|
apiUrl,
|
|
userApi,
|
|
type AdminHealthResponse,
|
|
type AdminEngineConfigResponse,
|
|
type EngineCapabilitiesResponse,
|
|
type NotificationPreferences,
|
|
type UserPreferencesResponse,
|
|
type UserProfileResponse,
|
|
type UserSupportTicketListItem,
|
|
type UserSupportTicketsResponse,
|
|
type VoicePresetResponse,
|
|
} from "../lib/api";
|
|
import { readInitialTheme } from "../lib/theme";
|
|
import { Toggle } from "./settings/Toggle";
|
|
import { useTheme } from "../lib/useTheme";
|
|
import "./settings/settings.css";
|
|
|
|
interface NavItem {
|
|
id: string;
|
|
label: string;
|
|
icon: IconName;
|
|
adminOnly?: boolean;
|
|
}
|
|
|
|
const ENGINE_MODE_LABEL: Record<string, string> = {
|
|
claude_cli: "Claude CLI 게이트웨이",
|
|
messages_api: "클라우드 연결",
|
|
claude_api: "Anthropic API",
|
|
codex_cli: "Codex CLI 게이트웨이",
|
|
agy_cli: "Agy CLI 게이트웨이",
|
|
openai: "OpenAI 호환",
|
|
solar: "Solar",
|
|
};
|
|
const ENGINE_MODES = [
|
|
"claude_cli",
|
|
"claude_api",
|
|
"codex_cli",
|
|
"agy_cli",
|
|
"openai",
|
|
"solar",
|
|
] as const;
|
|
|
|
const TICKET_STATUS_LABEL: Record<UserSupportTicketListItem["status"], string> = {
|
|
open: "접수",
|
|
triaged: "분류됨",
|
|
in_progress: "처리 중",
|
|
resolved: "해결",
|
|
closed: "종료",
|
|
};
|
|
|
|
const TICKET_CATEGORY_LABEL: Record<UserSupportTicketListItem["category"], string> = {
|
|
account_access: "계정",
|
|
session_review: "회기 리뷰",
|
|
voice_browser: "음성·브라우저",
|
|
content_scenario: "콘텐츠",
|
|
safety: "안전",
|
|
other: "기타",
|
|
};
|
|
|
|
const TICKET_PRIORITY_LABEL: Record<UserSupportTicketListItem["priority"], string> = {
|
|
low: "낮음",
|
|
normal: "보통",
|
|
high: "높음",
|
|
urgent: "긴급",
|
|
};
|
|
|
|
function SpeakerIcon({ size = 15 }: { size?: number }) {
|
|
return (
|
|
<svg
|
|
width={size}
|
|
height={size}
|
|
viewBox="0 0 24 24"
|
|
fill="currentColor"
|
|
stroke="none"
|
|
aria-hidden="true"
|
|
>
|
|
<polygon points="6 4 19 12 6 20" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
function healthStatusLabel(status: string | undefined): string {
|
|
if (status === "ok") return "정상";
|
|
if (status === "degraded") return "제한 운영";
|
|
if (status === "down") return "중단";
|
|
return "확인 중";
|
|
}
|
|
|
|
function ticketStatusTone(status: UserSupportTicketListItem["status"]) {
|
|
if (status === "resolved" || status === "closed") return "pos";
|
|
if (status === "in_progress" || status === "triaged") return "info";
|
|
return "warn";
|
|
}
|
|
|
|
function formatTicketDate(value?: number | null): string {
|
|
if (!value) return "-";
|
|
return new Intl.DateTimeFormat("ko-KR", {
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
}).format(new Date(value * 1000));
|
|
}
|
|
|
|
/** 동의 시각 표기 — 감사 추적을 위해 연도까지 포함한다. */
|
|
function formatConsentDate(value?: number | null): string {
|
|
if (!value) return "-";
|
|
return new Intl.DateTimeFormat("ko-KR", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
}).format(new Date(value * 1000));
|
|
}
|
|
|
|
function SettingsLoadingState({
|
|
children,
|
|
testId,
|
|
}: {
|
|
children: string;
|
|
testId: string;
|
|
}) {
|
|
return (
|
|
<div className="vg-set__state" role="status" data-testid={testId}>
|
|
<span className="vg-set__state-dot" aria-hidden="true" />
|
|
<span>{children}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 로딩 스켈레톤 — 회색 박스 반복 대신 섹션 형태(라벨/행 윤곽)를 미리 그려
|
|
* 미완성·오류로 오인되지 않게 한다. 로딩 testId·role 은 그대로 유지한다.
|
|
*/
|
|
function SettingsSkeleton({
|
|
children,
|
|
testId,
|
|
variant = "lines",
|
|
}: {
|
|
children: string;
|
|
testId: string;
|
|
variant?: "lines" | "rows" | "voice";
|
|
}) {
|
|
return (
|
|
<div
|
|
className={`vg-set__skel vg-set__skel--${variant}`}
|
|
role="status"
|
|
aria-live="polite"
|
|
data-testid={testId}
|
|
>
|
|
<span className="vg-set__skel-sr">{children}</span>
|
|
{variant === "rows" ? (
|
|
<>
|
|
<span className="vg-set__skel-row" aria-hidden="true">
|
|
<span className="vg-set__skel-bar" />
|
|
<span className="vg-set__skel-pill" />
|
|
</span>
|
|
<span className="vg-set__skel-row" aria-hidden="true">
|
|
<span className="vg-set__skel-bar" />
|
|
<span className="vg-set__skel-pill" />
|
|
</span>
|
|
</>
|
|
) : variant === "voice" ? (
|
|
<>
|
|
<span className="vg-set__skel-card" aria-hidden="true" />
|
|
<span className="vg-set__skel-card" aria-hidden="true" />
|
|
</>
|
|
) : (
|
|
<>
|
|
<span className="vg-set__skel-line vg-set__skel-line--label" aria-hidden="true" />
|
|
<span className="vg-set__skel-line" aria-hidden="true" />
|
|
<span className="vg-set__skel-line vg-set__skel-line--short" aria-hidden="true" />
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const DEFAULT_NOTIFICATION_PREFERENCES: NotificationPreferences = {
|
|
session_done: true,
|
|
safety_signal: true,
|
|
learner_progress: true,
|
|
account_approval: true,
|
|
product_news: false,
|
|
};
|
|
|
|
function completeNotificationPreferences(
|
|
preferences?: NotificationPreferences | null,
|
|
): NotificationPreferences {
|
|
return {
|
|
...DEFAULT_NOTIFICATION_PREFERENCES,
|
|
...preferences,
|
|
};
|
|
}
|
|
|
|
export default function Settings() {
|
|
const { user, refresh, acceptConsent, withdrawConsent } = useAuth();
|
|
const role = user?.role ?? "learner";
|
|
const isAdmin = role === "admin";
|
|
const [dark, setDark] = useTheme();
|
|
const [activeSection, setActiveSection] = useState("account");
|
|
// goSection의 스무스 스크롤 동안 IntersectionObserver가 활성 섹션을 되돌리지 않게 억제한다.
|
|
const spySuppressUntilRef = useRef(0);
|
|
|
|
const [profile, setProfile] = useState<UserProfileResponse | null>(null);
|
|
const [displayName, setDisplayName] = useState(user?.name ?? "");
|
|
const [affiliation, setAffiliation] = useState("");
|
|
const [preferences, setPreferences] = useState<UserPreferencesResponse | null>(null);
|
|
const [supportTickets, setSupportTickets] = useState<UserSupportTicketsResponse | null>(null);
|
|
const [voicePresets, setVoicePresets] = useState<VoicePresetResponse[]>([]);
|
|
const [engineConfig, setEngineConfig] = useState<AdminEngineConfigResponse | null>(null);
|
|
const [engineCapabilities, setEngineCapabilities] = useState<EngineCapabilitiesResponse | null>(null);
|
|
const [engineCapabilitiesLoading, setEngineCapabilitiesLoading] = useState(false);
|
|
const [engineCapabilitiesError, setEngineCapabilitiesError] = useState<string | null>(null);
|
|
const [adminHealth, setAdminHealth] = useState<AdminHealthResponse | null>(null);
|
|
const [profileReady, setProfileReady] = useState(false);
|
|
const [preferencesReady, setPreferencesReady] = useState(false);
|
|
const [supportTicketsReady, setSupportTicketsReady] = useState(false);
|
|
const [supportTicketsError, setSupportTicketsError] = useState<string | null>(null);
|
|
// 지원 요청 작성 — 접수 목록을 보는 자리에서 새 티켓을 접수한다(POST /users/support-tickets).
|
|
const [supportComposeOpen, setSupportComposeOpen] = useState(false);
|
|
const [supportSubject, setSupportSubject] = useState("");
|
|
const [supportBody, setSupportBody] = useState("");
|
|
const [supportSubmitting, setSupportSubmitting] = useState(false);
|
|
const [supportComposeError, setSupportComposeError] = useState<string | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [savedKey, setSavedKey] = useState<string | null>(null);
|
|
const savedTimer = useRef<number | null>(null);
|
|
const displayNameInputRef = useRef<HTMLInputElement | null>(null);
|
|
const affiliationInputRef = useRef<HTMLInputElement | null>(null);
|
|
const displayNameValueRef = useRef(user?.name ?? "");
|
|
const affiliationValueRef = useRef("");
|
|
const displayNameDirtyRef = useRef(false);
|
|
const affiliationDirtyRef = useRef(false);
|
|
const engineConfigRef = useRef<AdminEngineConfigResponse | null>(null);
|
|
const engineCapabilityRequestRef = useRef(0);
|
|
const loadSettingsRequestRef = useRef(0);
|
|
// 아바타 업로드 — 온보딩과 같은 계약(3MB, PNG/JPEG/WebP)을 설정에서도 쓴다.
|
|
const avatarInputRef = useRef<HTMLInputElement | null>(null);
|
|
const [uploadingAvatar, setUploadingAvatar] = useState(false);
|
|
const [avatarError, setAvatarError] = useState("");
|
|
// 실습 동의 관리 — 철회는 인라인 2단계 확인을 거친다.
|
|
const [consentConfirming, setConsentConfirming] = useState(false);
|
|
const [consentBusy, setConsentBusy] = useState(false);
|
|
const [consentWithdrawn, setConsentWithdrawn] = useState(false);
|
|
const [consentError, setConsentError] = useState("");
|
|
|
|
const flashSaved = (key: string) => {
|
|
setSavedKey(key);
|
|
if (savedTimer.current) window.clearTimeout(savedTimer.current);
|
|
savedTimer.current = window.setTimeout(() => setSavedKey(null), 2400);
|
|
};
|
|
|
|
const submitSupportTicket = async () => {
|
|
const subject = supportSubject.trim();
|
|
const body = supportBody.trim();
|
|
if (!subject || !body || supportSubmitting) return;
|
|
setSupportSubmitting(true);
|
|
setSupportComposeError(null);
|
|
try {
|
|
await userApi.createSupportTicket({
|
|
subject,
|
|
body,
|
|
category: "other",
|
|
priority: "normal",
|
|
source_path: "/settings",
|
|
});
|
|
// 접수 직후 목록을 재조회해 서버 원장의 상태를 그대로 보여준다.
|
|
const nextTickets = await userApi.supportTickets().catch(() => null);
|
|
if (nextTickets) {
|
|
setSupportTickets(nextTickets);
|
|
setSupportTicketsError(null);
|
|
}
|
|
setSupportComposeOpen(false);
|
|
setSupportSubject("");
|
|
setSupportBody("");
|
|
flashSaved("support");
|
|
} catch (err) {
|
|
setSupportComposeError(
|
|
err instanceof Error ? err.message : "지원 요청을 접수하지 못했습니다.",
|
|
);
|
|
} finally {
|
|
setSupportSubmitting(false);
|
|
}
|
|
};
|
|
|
|
const updateEngineConfig = useCallback((patch: Partial<AdminEngineConfigResponse>) => {
|
|
if (!engineConfigRef.current) return;
|
|
engineConfigRef.current = { ...engineConfigRef.current, ...patch };
|
|
setEngineConfig((current) => (current ? { ...current, ...patch } : current));
|
|
}, []);
|
|
|
|
const loadEngineCapabilities = useCallback(
|
|
async (
|
|
engineMode: string,
|
|
engineUrl: string,
|
|
options: { force?: boolean; applyDefault?: boolean } = {},
|
|
) => {
|
|
const requestId = ++engineCapabilityRequestRef.current;
|
|
setEngineCapabilitiesLoading(true);
|
|
setEngineCapabilitiesError(null);
|
|
try {
|
|
const next = await adminEngineApi.capabilities(
|
|
engineMode,
|
|
options.force ?? false,
|
|
engineUrl,
|
|
);
|
|
if (requestId !== engineCapabilityRequestRef.current) return;
|
|
setEngineCapabilities(next);
|
|
if (options.applyDefault && next.available && next.default_model) {
|
|
updateEngineConfig({
|
|
model: next.default_model,
|
|
reasoning_effort: next.default_reasoning_effort,
|
|
});
|
|
}
|
|
} catch (cause) {
|
|
if (requestId !== engineCapabilityRequestRef.current) return;
|
|
setEngineCapabilities(null);
|
|
setEngineCapabilitiesError(
|
|
cause instanceof Error ? cause.message : "모델 목록을 불러오지 못했습니다.",
|
|
);
|
|
} finally {
|
|
if (requestId === engineCapabilityRequestRef.current) {
|
|
setEngineCapabilitiesLoading(false);
|
|
}
|
|
}
|
|
},
|
|
[updateEngineConfig],
|
|
);
|
|
|
|
const loadSettings = useCallback(async () => {
|
|
const requestId = loadSettingsRequestRef.current + 1;
|
|
loadSettingsRequestRef.current = requestId;
|
|
engineCapabilityRequestRef.current += 1;
|
|
setLoading(true);
|
|
setError(null);
|
|
setProfileReady(false);
|
|
setPreferencesReady(false);
|
|
setSupportTicketsReady(false);
|
|
setPreferences(null);
|
|
setSupportTickets(null);
|
|
setSupportTicketsError(null);
|
|
setVoicePresets([]);
|
|
setEngineConfig(null);
|
|
setEngineCapabilities(null);
|
|
setEngineCapabilitiesError(null);
|
|
engineConfigRef.current = null;
|
|
try {
|
|
let nextSupportTicketsError: string | null = null;
|
|
const [nextProfile, nextPrefs, nextTickets, presets, nextEngine] = await Promise.all([
|
|
userApi.me(),
|
|
userApi.preferences(),
|
|
userApi.supportTickets().catch((err) => {
|
|
nextSupportTicketsError =
|
|
err instanceof Error ? err.message : "지원 요청을 불러오지 못했습니다.";
|
|
return null;
|
|
}),
|
|
userApi.voicePresets(),
|
|
isAdmin ? adminEngineApi.get() : Promise.resolve(null),
|
|
]);
|
|
if (loadSettingsRequestRef.current !== requestId) return;
|
|
setProfile(nextProfile);
|
|
setProfileReady(true);
|
|
if (!displayNameDirtyRef.current) {
|
|
setDisplayName(nextProfile.display_name);
|
|
displayNameValueRef.current = nextProfile.display_name;
|
|
}
|
|
if (!affiliationDirtyRef.current) {
|
|
setAffiliation(nextProfile.affiliation);
|
|
affiliationValueRef.current = nextProfile.affiliation;
|
|
}
|
|
setPreferences(nextPrefs);
|
|
setPreferencesReady(true);
|
|
setSupportTickets(nextTickets);
|
|
setSupportTicketsError(nextSupportTicketsError);
|
|
setSupportTicketsReady(true);
|
|
setDark(nextPrefs.theme === "dark" || (nextPrefs.theme !== "light" && readInitialTheme() === "dark"));
|
|
setVoicePresets(presets);
|
|
if (nextEngine) {
|
|
engineConfigRef.current = nextEngine;
|
|
setEngineConfig(nextEngine);
|
|
await loadEngineCapabilities(nextEngine.engine_mode, nextEngine.engine_url);
|
|
}
|
|
if (isAdmin) {
|
|
void adminApi.health()
|
|
.then((health) => {
|
|
if (loadSettingsRequestRef.current === requestId) setAdminHealth(health);
|
|
})
|
|
.catch(() => {
|
|
if (loadSettingsRequestRef.current === requestId) setAdminHealth(null);
|
|
});
|
|
}
|
|
} catch (err) {
|
|
if (loadSettingsRequestRef.current !== requestId) return;
|
|
setError(err instanceof Error ? err.message : "설정을 불러오지 못했습니다.");
|
|
} finally {
|
|
if (loadSettingsRequestRef.current === requestId) setLoading(false);
|
|
}
|
|
}, [isAdmin, loadEngineCapabilities, setDark]);
|
|
|
|
useEffect(() => {
|
|
void loadSettings();
|
|
return () => {
|
|
loadSettingsRequestRef.current += 1;
|
|
};
|
|
}, [loadSettings]);
|
|
|
|
useEffect(() => {
|
|
document.body.dataset.page = "settings";
|
|
return () => {
|
|
delete document.body.dataset.page;
|
|
};
|
|
}, []);
|
|
|
|
const navItems: NavItem[] = useMemo(() => {
|
|
const base: NavItem[] = [
|
|
{ id: "account", label: "계정", icon: "users" },
|
|
{ id: "support", label: "지원 요청", icon: "review" },
|
|
{ id: "consent", label: "동의", icon: "check" },
|
|
{ id: "appearance", label: "테마", icon: "settings" },
|
|
{ id: "notify", label: "알림", icon: "info" },
|
|
{ id: "voice", label: "음성", icon: "mic" },
|
|
];
|
|
if (isAdmin) {
|
|
base.splice(1, 0, { id: "engine", label: "AI 운영", icon: "shield", adminOnly: true });
|
|
}
|
|
return base;
|
|
}, [isAdmin]);
|
|
|
|
useEffect(() => {
|
|
// 활성 규칙: 뷰포트 상단 18~38% 밴드에 걸친 섹션 중 가장 아래(=방금 지나친 헤딩).
|
|
// 비율 우세 방식은 scroll-margin 정렬 지점이 밴드 하단 근처인 모바일에서
|
|
// 직전 섹션이 계속 이겨 마지막 섹션이 활성화되지 않는다(결함 로그 #17).
|
|
const pickActiveSection = () => {
|
|
const bandTop = window.innerHeight * 0.18;
|
|
const bandBottom = window.innerHeight * 0.38;
|
|
let winner: { id: string; top: number } | null = null;
|
|
for (const item of navItems) {
|
|
const section = document.getElementById(`set-${item.id}`);
|
|
if (!section) continue;
|
|
const rect = section.getBoundingClientRect();
|
|
if (rect.top > bandBottom || rect.bottom < bandTop) continue;
|
|
if (!winner || rect.top > winner.top) {
|
|
winner = { id: item.id, top: rect.top };
|
|
}
|
|
}
|
|
if (winner) setActiveSection(winner.id);
|
|
};
|
|
const observer = new IntersectionObserver(
|
|
() => {
|
|
if (Date.now() < spySuppressUntilRef.current) return;
|
|
pickActiveSection();
|
|
},
|
|
{
|
|
rootMargin: "-18% 0px -62% 0px",
|
|
// 0 임계값이 없으면 긴 섹션(모바일)은 밴드 대비 비율이 0.2에 못 미쳐
|
|
// 콜백이 아예 오지 않는다(결함 로그 #17).
|
|
threshold: [0, 0.2, 0.55],
|
|
},
|
|
);
|
|
|
|
for (const item of navItems) {
|
|
const section = document.getElementById(`set-${item.id}`);
|
|
if (section) observer.observe(section);
|
|
}
|
|
|
|
// 마지막 섹션은 짧은 뷰포트에서 활성 밴드(18~38%)에 도달하지 못한다.
|
|
// 스크롤 컨테이너가 바닥에 닿으면 마지막 섹션을 활성으로 처리한다(결함 로그 #17).
|
|
const scroller = document.querySelector(".vg-main");
|
|
const onScroll = () => {
|
|
if (!scroller || Date.now() < spySuppressUntilRef.current) return;
|
|
if (scroller.scrollTop + scroller.clientHeight >= scroller.scrollHeight - 4) {
|
|
const last = navItems[navItems.length - 1];
|
|
if (last) setActiveSection(last.id);
|
|
}
|
|
};
|
|
scroller?.addEventListener("scroll", onScroll, { passive: true });
|
|
|
|
return () => {
|
|
observer.disconnect();
|
|
scroller?.removeEventListener("scroll", onScroll);
|
|
};
|
|
}, [navItems]);
|
|
|
|
const visibleNotifications = useMemo(
|
|
() => [
|
|
{
|
|
id: "session_done",
|
|
label: "세션 완료",
|
|
hint: "학습 회기가 종료되면 알려줍니다.",
|
|
},
|
|
{
|
|
id: "safety_signal",
|
|
label: "안전 신호",
|
|
hint: "위기 신호가 감지되면 우선 알림을 표시합니다.",
|
|
},
|
|
{
|
|
id: "learner_progress",
|
|
label: "담당 학습자 진행",
|
|
hint: "교수자와 관리자에게만 표시됩니다.",
|
|
roles: ["teacher", "admin"],
|
|
},
|
|
{
|
|
id: "account_approval",
|
|
label: "가입 승인",
|
|
hint: "신규 가입 승인 요청이 있으면 알려줍니다.",
|
|
roles: ["admin"],
|
|
},
|
|
{
|
|
id: "product_news",
|
|
label: "제품 소식",
|
|
hint: "기능 변경과 연구 운영 공지를 받습니다.",
|
|
},
|
|
].filter((item) => !item.roles || item.roles.includes(role)),
|
|
[role],
|
|
);
|
|
|
|
const goSection = (id: string) => {
|
|
spySuppressUntilRef.current = Date.now() + 900;
|
|
setActiveSection(id);
|
|
document.getElementById(`set-${id}`)?.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
};
|
|
|
|
const saveProfile = async () => {
|
|
if (!profileReady) return;
|
|
const next = await userApi.updateMe({
|
|
display_name: displayNameValueRef.current,
|
|
affiliation: affiliationValueRef.current,
|
|
});
|
|
setProfile(next);
|
|
setDisplayName(next.display_name);
|
|
setAffiliation(next.affiliation);
|
|
displayNameValueRef.current = next.display_name;
|
|
affiliationValueRef.current = next.affiliation;
|
|
displayNameDirtyRef.current = false;
|
|
affiliationDirtyRef.current = false;
|
|
flashSaved("account");
|
|
};
|
|
|
|
/** 아바타 업로드 → PATCH /users/me 저장 → 톱바·레일 아바타 갱신. */
|
|
const uploadAvatar = async (file: File | null) => {
|
|
if (!file || uploadingAvatar) return;
|
|
setUploadingAvatar(true);
|
|
setAvatarError("");
|
|
try {
|
|
const uploaded = await userApi.uploadAvatar(file);
|
|
const next = await userApi.updateMe({ avatar_url: uploaded.avatar_url });
|
|
setProfile(next);
|
|
await refresh();
|
|
flashSaved("account");
|
|
} catch (err) {
|
|
console.warn("[settings] avatar upload failed", err);
|
|
setAvatarError("아바타 업로드에 실패했습니다. PNG, JPG, WebP 파일을 3MB 이하로 올려 주세요.");
|
|
} finally {
|
|
setUploadingAvatar(false);
|
|
}
|
|
};
|
|
|
|
/** 실습 동의 철회 확정 — DELETE /auth/consent, learner 전용. */
|
|
const confirmWithdrawConsent = async () => {
|
|
if (consentBusy) return;
|
|
setConsentBusy(true);
|
|
setConsentError("");
|
|
try {
|
|
await withdrawConsent();
|
|
setConsentWithdrawn(true);
|
|
setConsentConfirming(false);
|
|
} catch (err) {
|
|
console.warn("[settings] consent withdraw failed", err);
|
|
setConsentError(err instanceof Error ? err.message : "실습 동의 철회에 실패했습니다.");
|
|
} finally {
|
|
setConsentBusy(false);
|
|
}
|
|
};
|
|
|
|
/** 실습 동의 재동의 — POST /auth/consent, 회기 시작 화면과 같은 계약. */
|
|
const reacceptConsent = async () => {
|
|
if (consentBusy) return;
|
|
setConsentBusy(true);
|
|
setConsentError("");
|
|
try {
|
|
await acceptConsent();
|
|
setConsentWithdrawn(false);
|
|
} catch (err) {
|
|
console.warn("[settings] consent accept failed", err);
|
|
setConsentError(err instanceof Error ? err.message : "실습 동의 저장에 실패했습니다.");
|
|
} finally {
|
|
setConsentBusy(false);
|
|
}
|
|
};
|
|
|
|
const savePreferences = async (key: string) => {
|
|
if (!preferencesReady || !preferences) return;
|
|
const notifications = completeNotificationPreferences(preferences.notifications);
|
|
const next = await userApi.updatePreferences({
|
|
theme: dark ? "dark" : "light",
|
|
voice_preset_id: preferences.voice_preset_id,
|
|
voice_rate: preferences.voice_rate,
|
|
notifications,
|
|
});
|
|
setPreferences(next);
|
|
flashSaved(key);
|
|
};
|
|
|
|
const saveEngine = async () => {
|
|
const currentEngine = engineConfigRef.current;
|
|
if (!currentEngine) return;
|
|
const next = await adminEngineApi.update({
|
|
engine_mode: currentEngine.engine_mode,
|
|
engine_url: currentEngine.engine_url,
|
|
model: currentEngine.model,
|
|
reasoning_effort: currentEngine.reasoning_effort,
|
|
});
|
|
engineConfigRef.current = next;
|
|
setEngineConfig(next);
|
|
try {
|
|
setAdminHealth(await adminApi.health());
|
|
} catch {
|
|
setAdminHealth(null);
|
|
}
|
|
flashSaved("engine");
|
|
};
|
|
|
|
const updateNotification = (key: keyof NotificationPreferences, value: boolean) => {
|
|
setPreferences((cur) => cur ? ({
|
|
...cur,
|
|
notifications: {
|
|
...completeNotificationPreferences(cur.notifications),
|
|
[key]: value,
|
|
},
|
|
}) : cur);
|
|
};
|
|
|
|
const accountName = displayName || profile?.email || user?.name || user?.email || "사용자";
|
|
const accountEmail = profile?.email ?? user?.email ?? "";
|
|
const initials = accountName.trim().slice(0, 1).toUpperCase();
|
|
// 프로필이 먼저 도착하면 프로필 값을, 아니면 auth 스토어의 절대화된 URL을 쓴다.
|
|
const avatarSrc = profile?.avatar_url ? apiUrl(profile.avatar_url) : user?.avatarUrl ?? "";
|
|
const isLearner = role === "learner";
|
|
const consentAt = user?.consentAt ?? null;
|
|
const engineModels = engineCapabilities?.models ?? [];
|
|
const selectedEngineModel = engineModels.find((model) => model.id === engineConfig?.model);
|
|
const selectedEngineEfforts = selectedEngineModel?.reasoning_efforts ?? [];
|
|
const engineHasRequiredFields = Boolean(
|
|
engineConfig &&
|
|
engineConfig.engine_url.trim().length > 0 &&
|
|
engineCapabilities?.available &&
|
|
selectedEngineModel &&
|
|
(!engineConfig.reasoning_effort ||
|
|
selectedEngineEfforts.includes(engineConfig.reasoning_effort)),
|
|
);
|
|
const engineStorageLabel = !engineConfig
|
|
? "확인 중"
|
|
: engineConfig.durable
|
|
? "DB 저장"
|
|
: "런타임 적용";
|
|
const engineService = adminHealth?.services.find((service) => service.key === "engine");
|
|
const engineServiceStatus = engineService?.status ?? "degraded";
|
|
const notificationPreferences = completeNotificationPreferences(preferences?.notifications);
|
|
|
|
return (
|
|
<AppShell contextLabel="설정">
|
|
{error ? (
|
|
<div className="vg-set__callout vg-set__callout--warn" role="alert">
|
|
<span className="vg-set__callout-ico">
|
|
<Icon name="alert" size={18} />
|
|
</span>
|
|
<span className="vg-set__callout-text">{error}</span>
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="vg-set" aria-busy={loading}>
|
|
<aside className={surfaceClassName("vg-set__rail")}>
|
|
<div className="vg-set__rail-title">
|
|
<span className="vg-set__rail-mark" aria-hidden="true">
|
|
<Icon name="settings" size={24} strokeWidth={2} />
|
|
</span>
|
|
<div>
|
|
<h1>설정</h1>
|
|
<p>계정과 학습 환경</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__rail-card", { variant: "inset" })} aria-label="계정 요약">
|
|
<div className="vg-set__rail-avatar" aria-hidden="true">
|
|
{avatarSrc ? <img src={avatarSrc} alt="" /> : initials}
|
|
</div>
|
|
<div className="vg-set__rail-copy">
|
|
<div className="vg-set__rail-name">{accountName}</div>
|
|
<div className="vg-set__rail-email">{accountEmail}</div>
|
|
<div className="vg-set__rail-badges">
|
|
<Badge tone="accent">{roleLabel(role)}</Badge>
|
|
{affiliation ? <Badge tone="neutral">{affiliation}</Badge> : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<nav className={surfaceClassName("vg-set__nav", { variant: "inset", flat: true })} aria-label="설정 섹션">
|
|
<div className="vg-set__nav-kicker">SECTIONS</div>
|
|
{navItems.map((item) => (
|
|
<button
|
|
key={item.id}
|
|
type="button"
|
|
className={
|
|
"vg-set__nav-item" + (activeSection === item.id ? " is-active" : "")
|
|
}
|
|
aria-current={activeSection === item.id ? "location" : undefined}
|
|
onClick={() => goSection(item.id)}
|
|
>
|
|
<Icon name={item.icon} size={17} />
|
|
<span>{item.label}</span>
|
|
</button>
|
|
))}
|
|
</nav>
|
|
|
|
<div className="vg-set__rail-status" aria-label="설정 상태">
|
|
<span className="vg-set__pill">{roleLabel(role)}</span>
|
|
{isAdmin ? (
|
|
<span className={`vg-set__pill vg-set__pill--${engineServiceStatus}`}>
|
|
AI {healthStatusLabel(engineService?.status)}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</aside>
|
|
|
|
<div className="vg-set__forms">
|
|
<Panel id="set-account" className="vg-set__group vg-set__group--wide">
|
|
<div className="vg-set__group-head">
|
|
<div>
|
|
<div className="vg-set__group-title">계정</div>
|
|
<div className="vg-set__group-desc">로그인 계정과 표시 정보를 관리합니다.</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__profile", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__avatar" aria-hidden="true">
|
|
{avatarSrc ? <img src={avatarSrc} alt="" /> : initials}
|
|
</div>
|
|
<div className="vg-set__profile-meta">
|
|
<div className="n">{accountName}</div>
|
|
<div className="e">{accountEmail}</div>
|
|
<div className="badges">
|
|
<Badge tone="accent">{roleLabel(role)}</Badge>
|
|
{affiliation ? <Badge tone="neutral">{affiliation}</Badge> : null}
|
|
</div>
|
|
</div>
|
|
<div className="vg-set__avatar-actions">
|
|
<Button
|
|
size="sm"
|
|
variant="secondary"
|
|
onClick={() => avatarInputRef.current?.click()}
|
|
disabled={loading || uploadingAvatar}
|
|
>
|
|
{uploadingAvatar ? "업로드 중" : avatarSrc ? "아바타 변경" : "아바타 올리기"}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{avatarError ? (
|
|
<div className="vg-set__state vg-set__state--warn" role="alert">
|
|
<span className="vg-set__state-dot" aria-hidden="true" />
|
|
<span>{avatarError}</span>
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="vg-set__field-grid vg-set__field-grid--account">
|
|
<div className={surfaceClassName("vg-set__field", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">표시 이름</span>
|
|
<span className="h">교수자와 운영자가 확인하는 이름입니다.</span>
|
|
</div>
|
|
<Field>
|
|
<Input
|
|
ref={displayNameInputRef}
|
|
value={displayName}
|
|
onChange={(event) => {
|
|
displayNameDirtyRef.current = true;
|
|
displayNameValueRef.current = event.target.value;
|
|
setDisplayName(event.target.value);
|
|
}}
|
|
placeholder="표시할 이름을 입력하세요"
|
|
aria-label="표시 이름"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__field", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">이메일</span>
|
|
<span className="h">로그인으로 확인된 주소입니다.</span>
|
|
</div>
|
|
<Field>
|
|
<Input
|
|
value={profile?.email ?? ""}
|
|
disabled
|
|
placeholder="로그인 계정 이메일"
|
|
aria-label="이메일"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__field vg-set__field--wide", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">소속</span>
|
|
<span className="h">강의나 연구 운영에서 표시할 소속입니다.</span>
|
|
</div>
|
|
<Field>
|
|
<Input
|
|
ref={affiliationInputRef}
|
|
value={affiliation}
|
|
onChange={(event) => {
|
|
affiliationDirtyRef.current = true;
|
|
affiliationValueRef.current = event.target.value;
|
|
setAffiliation(event.target.value);
|
|
}}
|
|
placeholder="소속을 입력하세요"
|
|
aria-label="소속"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="vg-set__foot">
|
|
{savedKey === "account" ? (
|
|
<span className="vg-set__saved">
|
|
<Icon name="check" size={15} />
|
|
저장됨
|
|
</span>
|
|
) : null}
|
|
<Button
|
|
size="sm"
|
|
leading={<Icon name="check" size={14} />}
|
|
onClick={() => void saveProfile()}
|
|
disabled={loading || !profileReady}
|
|
>
|
|
저장
|
|
</Button>
|
|
</div>
|
|
|
|
{/* 숨은 아바타 file input — 계정 텍스트 입력들의 DOM 순서(0=표시 이름)를
|
|
흔들지 않도록 섹션 마지막에 둔다. 버튼이 ref 로 클릭을 위임한다. */}
|
|
<input
|
|
ref={avatarInputRef}
|
|
type="file"
|
|
accept="image/png,image/jpeg,image/webp"
|
|
className="vg-set__avatar-input"
|
|
aria-label="아바타 이미지"
|
|
disabled={loading || uploadingAvatar}
|
|
onChange={(event) => {
|
|
void uploadAvatar(event.currentTarget.files?.[0] ?? null);
|
|
event.currentTarget.value = "";
|
|
}}
|
|
/>
|
|
</Panel>
|
|
|
|
<Panel id="set-support" className="vg-set__group vg-set__group--wide">
|
|
<div className="vg-set__group-head">
|
|
<div>
|
|
<div className="vg-set__group-title">지원 요청</div>
|
|
<div className="vg-set__group-desc">
|
|
내가 접수한 운영 티켓의 처리 상태와 해결 메모입니다.
|
|
</div>
|
|
</div>
|
|
<div className="vg-set__support-head-ops">
|
|
{supportTickets ? (
|
|
<Badge tone={supportTickets.durable ? "accent" : "neutral"}>
|
|
{supportTickets.tickets.length}건
|
|
</Badge>
|
|
) : null}
|
|
<Button
|
|
size="sm"
|
|
variant="secondary"
|
|
aria-expanded={supportComposeOpen}
|
|
onClick={() => setSupportComposeOpen((open) => !open)}
|
|
>
|
|
새 요청 작성
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{supportComposeOpen ? (
|
|
<div className={surfaceClassName("vg-set__support-compose", { variant: "inset", flat: true })}>
|
|
<Field>
|
|
<Input
|
|
value={supportSubject}
|
|
aria-label="요청 제목"
|
|
placeholder="어떤 문제인지 한 줄로 요약해 주세요"
|
|
maxLength={200}
|
|
disabled={supportSubmitting}
|
|
onChange={(event) => setSupportSubject(event.target.value)}
|
|
/>
|
|
</Field>
|
|
<Field>
|
|
<textarea
|
|
className="vg-input vg-set__support-textarea"
|
|
rows={4}
|
|
value={supportBody}
|
|
aria-label="요청 내용"
|
|
placeholder="언제, 어떤 화면에서, 무엇이 발생했는지 적어 주세요."
|
|
maxLength={4000}
|
|
disabled={supportSubmitting}
|
|
onChange={(event) => setSupportBody(event.target.value)}
|
|
/>
|
|
</Field>
|
|
{supportComposeError ? (
|
|
<div className="vg-set__state vg-set__state--warn" role="alert">
|
|
<span className="vg-set__state-dot" aria-hidden="true" />
|
|
<span>{supportComposeError}</span>
|
|
</div>
|
|
) : null}
|
|
<div className="vg-set__support-compose-foot">
|
|
<span>접수된 요청은 아래 목록에서 처리 상태를 확인할 수 있습니다.</span>
|
|
<Button
|
|
size="sm"
|
|
disabled={
|
|
supportSubmitting || !supportSubject.trim() || !supportBody.trim()
|
|
}
|
|
onClick={() => void submitSupportTicket()}
|
|
>
|
|
{supportSubmitting ? "접수 중" : "요청 전송"}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{savedKey === "support" ? (
|
|
<div className="vg-set__state" role="status">
|
|
<span className="vg-set__state-dot" aria-hidden="true" />
|
|
<span>지원 요청을 접수했습니다.</span>
|
|
</div>
|
|
) : null}
|
|
|
|
{supportTicketsError ? (
|
|
<div className="vg-set__state vg-set__state--warn" role="alert">
|
|
<span className="vg-set__state-dot" aria-hidden="true" />
|
|
<span>{supportTicketsError}</span>
|
|
</div>
|
|
) : supportTickets ? (
|
|
supportTickets.tickets.length > 0 ? (
|
|
<div className="vg-set__tickets" aria-label="내 지원 요청 목록">
|
|
{supportTickets.tickets.map((ticket) => (
|
|
<article className={surfaceClassName("vg-set__ticket", { variant: "inset" })} key={ticket.ticket_id}>
|
|
<div className="vg-set__ticket-top">
|
|
<Badge tone={ticketStatusTone(ticket.status)}>
|
|
{TICKET_STATUS_LABEL[ticket.status]}
|
|
</Badge>
|
|
<span>{TICKET_CATEGORY_LABEL[ticket.category]}</span>
|
|
<span>{TICKET_PRIORITY_LABEL[ticket.priority]}</span>
|
|
</div>
|
|
<div className="vg-set__ticket-title">{ticket.subject}</div>
|
|
<div className="vg-set__ticket-meta">
|
|
<span>접수 {formatTicketDate(ticket.created_at)}</span>
|
|
<span>갱신 {formatTicketDate(ticket.updated_at)}</span>
|
|
{ticket.assigned_group ? <span>{ticket.assigned_group}</span> : null}
|
|
</div>
|
|
{ticket.resolution_note ? (
|
|
<div className={surfaceClassName("vg-set__ticket-note", { variant: "inset", flat: true })}>
|
|
<b>해결 메모</b>
|
|
<span>{ticket.resolution_note}</span>
|
|
</div>
|
|
) : (
|
|
<div className={surfaceClassName("vg-set__ticket-note vg-set__ticket-note--empty", { variant: "inset", flat: true })}>
|
|
처리 메모가 아직 없습니다.
|
|
</div>
|
|
)}
|
|
</article>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<SettingsLoadingState testId="settings-support-empty">
|
|
접수한 지원 요청이 없습니다.
|
|
</SettingsLoadingState>
|
|
)
|
|
) : supportTicketsReady ? (
|
|
<SettingsLoadingState testId="settings-support-empty">
|
|
지원 요청 저장소에 표시할 항목이 없습니다.
|
|
</SettingsLoadingState>
|
|
) : (
|
|
<SettingsSkeleton testId="settings-support-loading" variant="rows">
|
|
내 지원 요청을 불러오는 중입니다.
|
|
</SettingsSkeleton>
|
|
)}
|
|
</Panel>
|
|
|
|
{isAdmin ? (
|
|
<Panel
|
|
id="set-engine"
|
|
className="vg-set__group vg-set__group--wide vg-set__group--engine"
|
|
>
|
|
<div className="vg-set__group-head vg-set__group-head--split">
|
|
<div>
|
|
{/* 같은 헤더 우측에 실제 상태 dot(응답 생성 정상/주의)이 있다.
|
|
권한 라벨일 뿐인 이 kicker 의 dot 은 그 상태 신호를 희석해서 뺀다(D1). */}
|
|
<Kicker dot={false}>관리자</Kicker>
|
|
<div className="vg-set__group-title vg-set__group-title--kicker">
|
|
AI 운영
|
|
</div>
|
|
<div className="vg-set__group-desc">
|
|
상담 응답 생성에 사용할 운영 연결과 기본 모델을 관리합니다.
|
|
</div>
|
|
</div>
|
|
<div className={`vg-set__ops vg-set__ops--${engineServiceStatus}`} role="status">
|
|
<span className="vg-set__ops-dot" aria-hidden="true" />
|
|
<div>
|
|
<b>응답 생성 {healthStatusLabel(engineService?.status)}</b>
|
|
<span>
|
|
{engineService
|
|
? `${engineService.detail} · ${engineService.metric}`
|
|
: "운영 상태를 확인하는 중입니다."}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{engineConfig ? (
|
|
<>
|
|
<div className="vg-set__engine-grid">
|
|
<div className={surfaceClassName("vg-set__control-block", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">엔진 공급자</span>
|
|
<span className="h">저장 전에 실제 가용 모델을 조회하고 검증합니다.</span>
|
|
</div>
|
|
<select
|
|
className="vg-set__select"
|
|
value={engineConfig.engine_mode}
|
|
aria-label="AI 엔진 공급자"
|
|
onChange={(event) => {
|
|
const engineMode = event.target
|
|
.value as AdminEngineConfigResponse["engine_mode"];
|
|
setEngineCapabilities(null);
|
|
updateEngineConfig({
|
|
engine_mode: engineMode,
|
|
model: "",
|
|
reasoning_effort: null,
|
|
});
|
|
void loadEngineCapabilities(engineMode, engineConfig.engine_url, {
|
|
force: true,
|
|
applyDefault: true,
|
|
});
|
|
}}
|
|
>
|
|
{ENGINE_MODES.map((mode) => (
|
|
<option key={mode} value={mode}>
|
|
{ENGINE_MODE_LABEL[mode] ?? mode}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
|
|
<div className="vg-set__field-grid vg-set__field-grid--engine">
|
|
<div className={surfaceClassName("vg-set__field", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">연결 주소</span>
|
|
<span className="h">응답 생성 서비스의 연결 주소입니다.</span>
|
|
</div>
|
|
<Field>
|
|
<Input
|
|
value={engineConfig.engine_url}
|
|
onChange={(event) => {
|
|
updateEngineConfig({ engine_url: event.target.value });
|
|
setEngineCapabilities(null);
|
|
setEngineCapabilitiesError(
|
|
"연결 주소가 바뀌었습니다. 새 주소의 모델 목록을 확인하세요.",
|
|
);
|
|
}}
|
|
placeholder="운영 연결 주소를 입력하세요"
|
|
aria-label="AI 연결 주소"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__field", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">모델</span>
|
|
<span className="h">현재 계정에서 확인된 모델만 선택할 수 있습니다.</span>
|
|
</div>
|
|
<Field>
|
|
<select
|
|
className="vg-set__select"
|
|
value={engineConfig.model}
|
|
aria-label="AI 기본 모델"
|
|
disabled={engineCapabilitiesLoading || !engineCapabilities?.available}
|
|
onChange={(event) => {
|
|
const model = event.target.value;
|
|
const option = engineModels.find((item) => item.id === model);
|
|
updateEngineConfig({
|
|
model,
|
|
reasoning_effort: option?.default_reasoning_effort ?? null,
|
|
});
|
|
}}
|
|
>
|
|
{!selectedEngineModel && engineConfig.model ? (
|
|
<option value={engineConfig.model} disabled>
|
|
{engineConfig.model} · 현재 목록에서 확인되지 않음
|
|
</option>
|
|
) : null}
|
|
{!engineConfig.model ? <option value="">모델을 선택하세요</option> : null}
|
|
{engineModels.map((model) => (
|
|
<option key={model.id} value={model.id}>
|
|
{model.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<div className="vg-set__meta">
|
|
<span>최근 변경자: {engineConfig.updated_by ?? "-"}</span>
|
|
<span>저장 상태: {engineStorageLabel}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__field", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">추론 강도</span>
|
|
<span className="h">선택한 모델이 지원하는 단계만 표시됩니다.</span>
|
|
</div>
|
|
<Field>
|
|
<select
|
|
className="vg-set__select"
|
|
value={engineConfig.reasoning_effort ?? ""}
|
|
aria-label="AI 추론 강도"
|
|
disabled={engineCapabilitiesLoading || !selectedEngineModel}
|
|
onChange={(event) =>
|
|
updateEngineConfig({
|
|
reasoning_effort: (event.target.value ||
|
|
null) as AdminEngineConfigResponse["reasoning_effort"],
|
|
})
|
|
}
|
|
>
|
|
{selectedEngineEfforts.length ? null : (
|
|
<option value="">공급자 기본값</option>
|
|
)}
|
|
{selectedEngineEfforts.map((effort) => (
|
|
<option key={effort} value={effort}>
|
|
{effort === "low"
|
|
? "Low"
|
|
: effort === "medium"
|
|
? "Medium"
|
|
: effort === "high"
|
|
? "High"
|
|
: effort === "xhigh"
|
|
? "Extra High"
|
|
: effort === "max"
|
|
? "Max"
|
|
: "Ultra"}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
</div>
|
|
|
|
<div
|
|
className={`vg-set__engine-catalog vg-set__field--wide ${engineCapabilities?.available ? "is-ready" : "is-unavailable"}`}
|
|
role={
|
|
engineCapabilitiesError || engineCapabilities?.available === false
|
|
? "alert"
|
|
: "status"
|
|
}
|
|
>
|
|
<div>
|
|
<b>
|
|
{engineCapabilitiesLoading
|
|
? "모델 목록 확인 중"
|
|
: engineCapabilities?.available
|
|
? `${engineModels.length}개 모델 확인됨`
|
|
: "모델 목록을 확인할 수 없음"}
|
|
</b>
|
|
<span>
|
|
{engineCapabilitiesError ??
|
|
engineCapabilities?.detail ??
|
|
"게이트웨이 연결 뒤 모델 목록을 표시합니다."}
|
|
</span>
|
|
</div>
|
|
<Button
|
|
size="sm"
|
|
variant="secondary"
|
|
onClick={() =>
|
|
void loadEngineCapabilities(
|
|
engineConfig.engine_mode,
|
|
engineConfig.engine_url,
|
|
{
|
|
force: true,
|
|
applyDefault: !selectedEngineModel,
|
|
},
|
|
)
|
|
}
|
|
disabled={engineCapabilitiesLoading}
|
|
>
|
|
목록 새로고침
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="vg-set__foot">
|
|
{savedKey === "engine" ? (
|
|
<span className="vg-set__saved">
|
|
<Icon name="check" size={15} />
|
|
저장됨
|
|
</span>
|
|
) : null}
|
|
<Button
|
|
size="sm"
|
|
leading={<Icon name="check" size={14} />}
|
|
onClick={() => void saveEngine()}
|
|
disabled={loading || !engineHasRequiredFields}
|
|
>
|
|
운영 설정 저장
|
|
</Button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<SettingsSkeleton testId="settings-engine-loading" variant="lines">
|
|
서버 AI 운영 설정을 불러오는 중입니다.
|
|
</SettingsSkeleton>
|
|
)}
|
|
</Panel>
|
|
) : null}
|
|
|
|
<Panel id="set-consent" className="vg-set__group vg-set__group--compact">
|
|
<div className="vg-set__group-head">
|
|
<div>
|
|
<div className="vg-set__group-title">동의</div>
|
|
<div className="vg-set__group-desc">실습 동의와 약관 동의 이력을 확인하고 관리합니다.</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="vg-set__opt-grid">
|
|
<div className={surfaceClassName("vg-set__opt", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__opt-text">
|
|
<div className="l">실습 동의</div>
|
|
<div className="h" data-testid="settings-consent-practice">
|
|
{!isLearner
|
|
? "학습자 전용 항목입니다. 실습 동의는 학습자 계정에서만 관리합니다."
|
|
: consentAt != null
|
|
? `동의 시각 ${formatConsentDate(consentAt)}`
|
|
: "미동의 상태입니다."}
|
|
</div>
|
|
</div>
|
|
{!isLearner ? (
|
|
<Badge tone="neutral">학습자 전용</Badge>
|
|
) : consentAt != null && !consentConfirming ? (
|
|
<Button
|
|
size="sm"
|
|
variant="secondary"
|
|
onClick={() => setConsentConfirming(true)}
|
|
disabled={consentBusy}
|
|
>
|
|
실습 동의 철회
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__opt", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__opt-text">
|
|
<div className="l">이용약관</div>
|
|
<div className="h">
|
|
{profileReady && profile
|
|
? `버전 ${profile.terms_version || "-"} · 동의 ${formatConsentDate(profile.terms_agreed_at)}`
|
|
: "동의 이력을 확인하는 중입니다."}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__opt", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__opt-text">
|
|
<div className="l">개인정보 처리방침</div>
|
|
<div className="h">
|
|
{profileReady && profile
|
|
? `버전 ${profile.privacy_version || "-"} · 동의 ${formatConsentDate(profile.privacy_agreed_at)}`
|
|
: "동의 이력을 확인하는 중입니다."}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{consentError ? (
|
|
<div className="vg-set__state vg-set__state--warn" role="alert">
|
|
<span className="vg-set__state-dot" aria-hidden="true" />
|
|
<span>{consentError}</span>
|
|
</div>
|
|
) : null}
|
|
|
|
{isLearner && consentAt != null && consentConfirming ? (
|
|
<div className={surfaceClassName("vg-set__consent-block", { variant: "inset", flat: true })}>
|
|
<span>정말 철회할까요? 철회하면 새 회기 시작과 음성 연습이 즉시 차단됩니다.</span>
|
|
<div className="vg-set__consent-actions">
|
|
<Button
|
|
size="sm"
|
|
variant="danger"
|
|
onClick={() => void confirmWithdrawConsent()}
|
|
disabled={consentBusy}
|
|
>
|
|
{consentBusy ? "철회 중" : "철회 확정"}
|
|
</Button>
|
|
<Button
|
|
size="sm"
|
|
variant="ghost"
|
|
onClick={() => setConsentConfirming(false)}
|
|
disabled={consentBusy}
|
|
>
|
|
취소
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{isLearner && consentAt == null ? (
|
|
<div className={surfaceClassName("vg-set__consent-block", { variant: "inset", flat: true })}>
|
|
{consentWithdrawn ? (
|
|
<span role="status">
|
|
새 회기 시작과 음성 연습이 차단됩니다. 아래 버튼 또는 회기 시작 화면에서
|
|
다시 동의할 수 있습니다.
|
|
</span>
|
|
) : (
|
|
<span>실습 동의가 없어 새 회기 시작과 음성 연습이 차단된 상태입니다.</span>
|
|
)}
|
|
<div className="vg-set__consent-actions">
|
|
<Button
|
|
size="sm"
|
|
leading={<Icon name="check" size={14} />}
|
|
onClick={() => void reacceptConsent()}
|
|
disabled={consentBusy}
|
|
>
|
|
{consentBusy ? "저장 중" : "다시 동의"}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
</Panel>
|
|
|
|
<Panel id="set-appearance" className="vg-set__group vg-set__group--compact">
|
|
<div className="vg-set__group-head">
|
|
<div>
|
|
<div className="vg-set__group-title">테마</div>
|
|
<div className="vg-set__group-desc">화면 밝기를 설정합니다.</div>
|
|
</div>
|
|
</div>
|
|
{preferences ? (
|
|
<>
|
|
<div className={surfaceClassName("vg-set__opt", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__opt-text">
|
|
<div className="l">다크 모드</div>
|
|
<div className="h">현재 기기와 브라우저에 적용됩니다.</div>
|
|
</div>
|
|
<span className="vg-set__toggle-line">
|
|
<Icon name={dark ? "moon" : "sun"} size={16} />
|
|
<Toggle checked={dark} onChange={setDark} label="다크 모드" />
|
|
</span>
|
|
</div>
|
|
<div className="vg-set__foot">
|
|
{savedKey === "appearance" ? (
|
|
<span className="vg-set__saved">
|
|
<Icon name="check" size={15} />
|
|
저장됨
|
|
</span>
|
|
) : null}
|
|
<Button
|
|
size="sm"
|
|
leading={<Icon name="check" size={14} />}
|
|
onClick={() => void savePreferences("appearance")}
|
|
disabled={loading || !preferencesReady}
|
|
>
|
|
저장
|
|
</Button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<SettingsSkeleton testId="settings-preferences-loading" variant="rows">
|
|
서버 환경 설정을 불러오는 중입니다.
|
|
</SettingsSkeleton>
|
|
)}
|
|
</Panel>
|
|
|
|
<Panel id="set-voice" className="vg-set__group vg-set__group--wide">
|
|
<div className="vg-set__group-head">
|
|
<div>
|
|
<div className="vg-set__group-title">음성</div>
|
|
<div className="vg-set__group-desc">상담 연습에 사용할 음성 프리셋을 선택합니다.</div>
|
|
</div>
|
|
</div>
|
|
|
|
{preferences ? (
|
|
voicePresets.length > 0 ? (
|
|
<>
|
|
<div className="vg-set__voicelist" role="radiogroup" aria-label="음성 프리셋">
|
|
{voicePresets.map((preset) => {
|
|
const selected = preferences.voice_preset_id === preset.id;
|
|
return (
|
|
<button
|
|
key={preset.id}
|
|
type="button"
|
|
role="radio"
|
|
aria-checked={selected}
|
|
className={surfaceClassName(
|
|
"vg-set__voice" + (selected ? " is-on" : ""),
|
|
{ variant: "interactive", flat: true },
|
|
)}
|
|
onClick={() =>
|
|
setPreferences((cur) =>
|
|
cur ? { ...cur, voice_preset_id: preset.id } : cur,
|
|
)
|
|
}
|
|
>
|
|
<span className="vg-set__voice-rad" aria-hidden="true" />
|
|
<span className="vg-set__voice-info">
|
|
<span className="vn">
|
|
{preset.name} · {preset.voice_id}
|
|
</span>
|
|
<span className="vd">
|
|
{preset.desc} · {preset.persona_hint}
|
|
</span>
|
|
</span>
|
|
<span
|
|
className="vg-set__voice-play"
|
|
role="presentation"
|
|
aria-hidden="true"
|
|
>
|
|
<SpeakerIcon />
|
|
</span>
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
|
|
<div className={surfaceClassName("vg-set__range-row", { variant: "inset", flat: true })}>
|
|
<div className="vg-set__field-copy">
|
|
<span className="l">말하기 속도</span>
|
|
<span className="h">기본 발화 속도입니다.</span>
|
|
</div>
|
|
<div className="vg-set__range-control">
|
|
<input
|
|
type="range"
|
|
min={0.8}
|
|
max={1.2}
|
|
step={0.02}
|
|
value={preferences.voice_rate}
|
|
onChange={(event) =>
|
|
setPreferences((cur) =>
|
|
cur
|
|
? {
|
|
...cur,
|
|
voice_rate: Number(event.target.value),
|
|
}
|
|
: cur,
|
|
)
|
|
}
|
|
aria-label="말하기 속도"
|
|
/>
|
|
<div className="vg-set__meta vg-set__meta--range">
|
|
<span>0.8x</span>
|
|
<span>{preferences.voice_rate.toFixed(2)}x</span>
|
|
<span>1.2x</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="vg-set__foot">
|
|
{savedKey === "voice" ? (
|
|
<span className="vg-set__saved">
|
|
<Icon name="check" size={15} />
|
|
저장됨
|
|
</span>
|
|
) : null}
|
|
<Button
|
|
size="sm"
|
|
leading={<Icon name="check" size={14} />}
|
|
onClick={() => void savePreferences("voice")}
|
|
disabled={loading || !preferencesReady}
|
|
>
|
|
음성 저장
|
|
</Button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<SettingsLoadingState testId="settings-voice-empty">
|
|
서버에 등록된 음성 프리셋이 없습니다.
|
|
</SettingsLoadingState>
|
|
)
|
|
) : (
|
|
<SettingsSkeleton testId="settings-voice-loading" variant="voice">
|
|
서버 음성 설정을 불러오는 중입니다.
|
|
</SettingsSkeleton>
|
|
)}
|
|
</Panel>
|
|
|
|
<Panel id="set-notify" className="vg-set__group vg-set__group--compact">
|
|
<div className="vg-set__group-head">
|
|
<div>
|
|
<div className="vg-set__group-title">알림</div>
|
|
<div className="vg-set__group-desc">역할에 맞는 알림만 표시됩니다.</div>
|
|
</div>
|
|
</div>
|
|
|
|
{preferences ? (
|
|
<>
|
|
<div className="vg-set__opt-grid">
|
|
{visibleNotifications.map((item) => (
|
|
<div className={surfaceClassName("vg-set__opt", { variant: "inset", flat: true })} key={item.id}>
|
|
<div className="vg-set__opt-text">
|
|
<div className="l">{item.label}</div>
|
|
<div className="h">{item.hint}</div>
|
|
</div>
|
|
<Toggle
|
|
checked={Boolean(
|
|
notificationPreferences[item.id as keyof NotificationPreferences],
|
|
)}
|
|
onChange={(next) =>
|
|
updateNotification(item.id as keyof NotificationPreferences, next)
|
|
}
|
|
label={item.label}
|
|
/>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<div className="vg-set__foot">
|
|
{savedKey === "notify" ? (
|
|
<span className="vg-set__saved">
|
|
<Icon name="check" size={15} />
|
|
저장됨
|
|
</span>
|
|
) : null}
|
|
<Button
|
|
size="sm"
|
|
leading={<Icon name="check" size={14} />}
|
|
onClick={() => void savePreferences("notify")}
|
|
disabled={loading || !preferencesReady}
|
|
>
|
|
알림 저장
|
|
</Button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<SettingsSkeleton testId="settings-notify-loading" variant="rows">
|
|
서버 알림 설정을 불러오는 중입니다.
|
|
</SettingsSkeleton>
|
|
)}
|
|
</Panel>
|
|
</div>
|
|
</div>
|
|
</AppShell>
|
|
);
|
|
}
|