- 전수 순회: IA 전 라우트 412개 기능 인벤토리를 체크리스트 백로그로 관리 (docs/ops/e2e-full-sweep-2026-07-27.md), 신규 full-sweep 스펙 10파일 추가. RED→GREEN으로 결함 12건 수정: 관리자 무한 렌더 프리즈(TanStack autoReset 루프), 복수 코호트 저장 유실, 페르소나 보관 503(SQL 컬럼 모호성), PII 과잉 마스킹, /admin/ai watchdog 오탐 오버레이, 모바일 겹침 2건, 설정 스크롤 스파이, 온보딩 전화번호 무검증, 리뷰 조사·난도 라벨, pending 피드백 등. - 소유자 결정 구현: 설정 아바타 변경, 동의 철회·재동의 전체 흐름, 신규 학습자 기초 우선 추천, 학생 분석 테이블 가상화(@tanstack/react-virtual), 저작 모드 죽은 레일 정리, 감정 밸런스 타임라인 차트(deep turn_valence + 결정론 파생 폴백). - 디자인 감사(142차): 라이트 팔레트 AA 대비, 다크 토큰 별칭 통일, 미정의 CSS 변수 정리, 한글 keep-all 전역화, 탭 타깃 24px, LCP preconnect. - 검증: npm run e2e 병렬 432 수집 GREEN + 직렬 49/49 exit 0, 백엔드 pytest 421, gateway 29, typecheck/build/design-ssot/dead-code/중복 게이트 통과, layout-visual-gate 15/15, session-layout 8/8. 상세는 SSOT 대시보드 142~144차 노트.
352 lines
13 KiB
TypeScript
352 lines
13 KiB
TypeScript
import { useEffect, useMemo, useState } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { Button } from "../components/ui";
|
|
import { surfaceClassName } from "../components/ui/Surface";
|
|
import { AuthShell } from "../components/auth/AuthShell";
|
|
import { roleHomePath, useAuth } from "../lib/auth";
|
|
import { apiUrl, userApi, type LegalDocumentsResponse, type UserProfileResponse } from "../lib/api";
|
|
import "./onboarding.css";
|
|
|
|
interface OnboardingForm {
|
|
legal_name: string;
|
|
affiliation: string;
|
|
department: string;
|
|
grade_level: string;
|
|
phone: string;
|
|
contact_address: string;
|
|
nickname: string;
|
|
self_introduction: string;
|
|
avatar_url: string;
|
|
terms_accepted: boolean;
|
|
privacy_accepted: boolean;
|
|
}
|
|
|
|
const EMPTY_FORM: OnboardingForm = {
|
|
legal_name: "",
|
|
affiliation: "한신대학교",
|
|
department: "",
|
|
grade_level: "",
|
|
phone: "",
|
|
contact_address: "",
|
|
nickname: "",
|
|
self_introduction: "",
|
|
avatar_url: "",
|
|
terms_accepted: false,
|
|
privacy_accepted: false,
|
|
};
|
|
|
|
// 서버 OnboardingRequest 검증과 동일 규칙: 숫자·하이픈·공백·괄호·점, 선행 +, 숫자 9~15자리.
|
|
function isValidPhone(raw: string): boolean {
|
|
const trimmed = raw.trim();
|
|
const digits = trimmed.replace(/\D/g, "");
|
|
return /^\+?[0-9()\-\s.]+$/.test(trimmed) && digits.length >= 9 && digits.length <= 15;
|
|
}
|
|
|
|
function profileToForm(profile: UserProfileResponse | null): OnboardingForm {
|
|
return {
|
|
...EMPTY_FORM,
|
|
legal_name: profile?.legal_name || profile?.display_name || "",
|
|
affiliation: profile?.affiliation || EMPTY_FORM.affiliation,
|
|
department: profile?.department || "",
|
|
grade_level: profile?.grade_level || "",
|
|
phone: profile?.phone || "",
|
|
contact_address: profile?.contact_address || "",
|
|
nickname: profile?.nickname || profile?.display_name || "",
|
|
self_introduction: profile?.self_introduction || "",
|
|
avatar_url: profile?.avatar_url || "",
|
|
};
|
|
}
|
|
|
|
export default function Onboarding() {
|
|
const navigate = useNavigate();
|
|
const { user, refresh } = useAuth();
|
|
const [docs, setDocs] = useState<LegalDocumentsResponse | null>(null);
|
|
const [form, setForm] = useState<OnboardingForm>(EMPTY_FORM);
|
|
const [loading, setLoading] = useState(true);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [uploadingAvatar, setUploadingAvatar] = useState(false);
|
|
const [error, setError] = useState("");
|
|
const [avatarError, setAvatarError] = useState("");
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
(async () => {
|
|
setLoading(true);
|
|
setError("");
|
|
try {
|
|
const [profileResult, docsResult] = await Promise.all([userApi.me(), userApi.legalDocs()]);
|
|
if (!alive) return;
|
|
setDocs(docsResult);
|
|
setForm(profileToForm(profileResult));
|
|
} catch (err) {
|
|
console.warn("[onboarding] failed to load", err);
|
|
if (alive) setError("온보딩 정보를 불러오지 못했습니다.");
|
|
} finally {
|
|
if (alive) setLoading(false);
|
|
}
|
|
})();
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, []);
|
|
|
|
const canSubmit = useMemo(
|
|
() =>
|
|
form.legal_name.trim() &&
|
|
form.affiliation.trim() &&
|
|
form.department.trim() &&
|
|
form.grade_level.trim() &&
|
|
form.phone.trim() &&
|
|
form.contact_address.trim() &&
|
|
form.nickname.trim() &&
|
|
form.self_introduction.trim() &&
|
|
form.terms_accepted &&
|
|
form.privacy_accepted,
|
|
[form],
|
|
);
|
|
|
|
const avatarSrc = form.avatar_url ? apiUrl(form.avatar_url) : "";
|
|
|
|
const update = <K extends keyof OnboardingForm>(key: K, value: OnboardingForm[K]) => {
|
|
setForm((current) => ({ ...current, [key]: value }));
|
|
};
|
|
|
|
const uploadAvatar = async (file: File | null) => {
|
|
if (!file || uploadingAvatar) return;
|
|
setUploadingAvatar(true);
|
|
setAvatarError("");
|
|
try {
|
|
const uploaded = await userApi.uploadAvatar(file);
|
|
update("avatar_url", uploaded.avatar_url);
|
|
} catch (err) {
|
|
console.warn("[onboarding] avatar upload failed", err);
|
|
setAvatarError("아바타 업로드에 실패했습니다. PNG, JPG, WebP 파일을 3MB 이하로 올려 주세요.");
|
|
} finally {
|
|
setUploadingAvatar(false);
|
|
}
|
|
};
|
|
|
|
const submit = async () => {
|
|
if (!canSubmit || submitting) return;
|
|
if (!isValidPhone(form.phone)) {
|
|
setError("연락처는 숫자 9~15자리의 전화번호 형식으로 입력해 주세요 (예: 010-1234-5678).");
|
|
return;
|
|
}
|
|
setSubmitting(true);
|
|
setError("");
|
|
try {
|
|
await userApi.completeOnboarding({
|
|
legal_name: form.legal_name.trim(),
|
|
affiliation: form.affiliation.trim(),
|
|
department: form.department.trim(),
|
|
grade_level: form.grade_level.trim(),
|
|
phone: form.phone.trim(),
|
|
contact_address: form.contact_address.trim(),
|
|
nickname: form.nickname.trim(),
|
|
self_introduction: form.self_introduction.trim(),
|
|
avatar_url: form.avatar_url.trim(),
|
|
terms_accepted: form.terms_accepted,
|
|
privacy_accepted: form.privacy_accepted,
|
|
});
|
|
const nextUser = await refresh();
|
|
navigate(roleHomePath(nextUser?.role ?? user?.role ?? "learner"), { replace: true });
|
|
} catch (err) {
|
|
console.warn("[onboarding] failed to submit", err);
|
|
setError("온보딩 저장에 실패했습니다. 입력값과 서버 상태를 확인해 주세요.");
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<AuthShell className="ob-page">
|
|
<section className={surfaceClassName("ob-shell")} aria-label="가입 정보 입력">
|
|
<header className="ob-head">
|
|
<p>Vignette 가입 설정</p>
|
|
<h1>가입 정보를 입력합니다.</h1>
|
|
</header>
|
|
|
|
<form
|
|
className="ob-form"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
void submit();
|
|
}}
|
|
>
|
|
<section className="ob-section">
|
|
<div className="ob-section__head">
|
|
<h2>프로필</h2>
|
|
</div>
|
|
<div className="ob-avatar">
|
|
<div className="ob-avatar__preview" aria-hidden="true">
|
|
{avatarSrc ? <img src={avatarSrc} alt="" /> : <span>{form.nickname.trim().slice(0, 1) || "V"}</span>}
|
|
</div>
|
|
<div className="ob-avatar__body">
|
|
<span>상징 아바타</span>
|
|
<p>학습 화면과 사용자 표시 영역에 사용할 이미지를 올립니다. 얼굴 사진이 아니어도 됩니다.</p>
|
|
<label className="ob-avatar__button">
|
|
<input
|
|
type="file"
|
|
accept="image/png,image/jpeg,image/webp"
|
|
aria-label="아바타 이미지"
|
|
disabled={loading || uploadingAvatar}
|
|
onChange={(event) => {
|
|
void uploadAvatar(event.currentTarget.files?.[0] ?? null);
|
|
event.currentTarget.value = "";
|
|
}}
|
|
/>
|
|
{uploadingAvatar ? "업로드 중" : avatarSrc ? "다른 이미지 선택" : "이미지 선택"}
|
|
</label>
|
|
{avatarError ? <p className="ob-error" role="alert">{avatarError}</p> : null}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="ob-fields">
|
|
<label>
|
|
<span>닉네임</span>
|
|
<input
|
|
value={form.nickname}
|
|
onChange={(event) => update("nickname", event.target.value)}
|
|
autoComplete="nickname"
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
<label className="ob-field--wide">
|
|
<span>자기소개</span>
|
|
<textarea
|
|
value={form.self_introduction}
|
|
onChange={(event) => update("self_introduction", event.target.value)}
|
|
disabled={loading}
|
|
maxLength={600}
|
|
required
|
|
placeholder="상담 훈련에서 집중하고 싶은 점이나 본인을 소개할 문장을 적어 주세요."
|
|
/>
|
|
</label>
|
|
</div>
|
|
</section>
|
|
|
|
<section className="ob-section">
|
|
<div className="ob-section__head">
|
|
<h2>소속 정보</h2>
|
|
</div>
|
|
<div className="ob-fields">
|
|
<label>
|
|
<span>이름</span>
|
|
<input
|
|
value={form.legal_name}
|
|
onChange={(event) => update("legal_name", event.target.value)}
|
|
autoComplete="name"
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
<label>
|
|
<span>소속</span>
|
|
<input
|
|
value={form.affiliation}
|
|
onChange={(event) => update("affiliation", event.target.value)}
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
<label>
|
|
<span>학과/부서</span>
|
|
<input
|
|
value={form.department}
|
|
onChange={(event) => update("department", event.target.value)}
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
<label>
|
|
<span>학년/직위</span>
|
|
<input
|
|
value={form.grade_level}
|
|
onChange={(event) => update("grade_level", event.target.value)}
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
<label>
|
|
<span>연락처</span>
|
|
<input
|
|
value={form.phone}
|
|
onChange={(event) => update("phone", event.target.value)}
|
|
autoComplete="tel"
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
<label>
|
|
<span>주소/수령지</span>
|
|
<input
|
|
value={form.contact_address}
|
|
onChange={(event) => update("contact_address", event.target.value)}
|
|
autoComplete="street-address"
|
|
disabled={loading}
|
|
required
|
|
/>
|
|
</label>
|
|
</div>
|
|
</section>
|
|
|
|
<section className="ob-section">
|
|
<div className="ob-section__head">
|
|
<h2>동의</h2>
|
|
</div>
|
|
<div className="ob-checks">
|
|
<label>
|
|
<input
|
|
type="checkbox"
|
|
checked={form.terms_accepted}
|
|
onChange={(event) => update("terms_accepted", event.target.checked)}
|
|
disabled={loading}
|
|
/>
|
|
<span>서비스 이용약관에 동의합니다.</span>
|
|
</label>
|
|
<label>
|
|
<input
|
|
type="checkbox"
|
|
checked={form.privacy_accepted}
|
|
onChange={(event) => update("privacy_accepted", event.target.checked)}
|
|
disabled={loading}
|
|
/>
|
|
<span>개인정보 수집 및 이용에 동의합니다.</span>
|
|
</label>
|
|
</div>
|
|
|
|
<div className="ob-legal">
|
|
<details>
|
|
<summary>
|
|
<span>{docs?.terms.title ?? "서비스 이용약관"}</span>
|
|
<b>{docs?.terms.version ?? "확인 중"}</b>
|
|
</summary>
|
|
<div className="ob-doc-text">{docs?.terms.body ?? "문서를 불러오는 중입니다."}</div>
|
|
</details>
|
|
<details>
|
|
<summary>
|
|
<span>{docs?.privacy.title ?? "개인정보 처리방침"}</span>
|
|
<b>{docs?.privacy.version ?? "확인 중"}</b>
|
|
</summary>
|
|
<div className="ob-doc-text">{docs?.privacy.body ?? "문서를 불러오는 중입니다."}</div>
|
|
</details>
|
|
<p className="ob-note">{docs?.source_note ?? "운영 전 초안 문서입니다."}</p>
|
|
</div>
|
|
</section>
|
|
|
|
{error ? <p className="ob-error" role="alert">{error}</p> : null}
|
|
{loading ? <p className="ob-note">온보딩 정보를 확인하고 있습니다.</p> : null}
|
|
|
|
<div className="ob-actions">
|
|
<Button type="submit" size="lg" disabled={!canSubmit || submitting || loading}>
|
|
{submitting ? "저장 중" : "가입 설정 완료"}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</AuthShell>
|
|
</>
|
|
);
|
|
}
|