음성 재생과 운영 배포 정리
This commit is contained in:
parent
8ed185ce6c
commit
ac7db95542
1020 changed files with 46863 additions and 2175 deletions
595
apps/web/src/pages/Onboarding.tsx
Normal file
595
apps/web/src/pages/Onboarding.tsx
Normal file
|
|
@ -0,0 +1,595 @@
|
|||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button } from "../components/ui";
|
||||
import { roleHomePath, useAuth } from "../lib/auth";
|
||||
import { apiUrl, userApi, type LegalDocumentsResponse, type UserProfileResponse } from "../lib/api";
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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;
|
||||
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 (
|
||||
<>
|
||||
<style>{ONBOARDING_CSS}</style>
|
||||
<main className="ob-page">
|
||||
<section className="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>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const ONBOARDING_CSS = `
|
||||
.ob-page{
|
||||
min-height:100dvh;
|
||||
width:100%;
|
||||
background:var(--bg-app);
|
||||
color:var(--text-body);
|
||||
padding:clamp(20px,5vw,56px);
|
||||
}
|
||||
.ob-shell{
|
||||
width:100%;
|
||||
max-width:900px;
|
||||
margin:0 auto;
|
||||
display:grid;
|
||||
gap:var(--sp-6);
|
||||
}
|
||||
.ob-head{
|
||||
display:grid;
|
||||
gap:8px;
|
||||
}
|
||||
.ob-head p{
|
||||
margin:0;
|
||||
color:var(--accent-deep);
|
||||
font-size:12px;
|
||||
font-weight:800;
|
||||
}
|
||||
.ob-head h1{
|
||||
margin:0;
|
||||
color:var(--text-strong);
|
||||
font-size:clamp(28px,4vw,44px);
|
||||
line-height:1.18;
|
||||
letter-spacing:0;
|
||||
}
|
||||
.ob-form{
|
||||
min-width:0;
|
||||
display:grid;
|
||||
gap:var(--sp-6);
|
||||
}
|
||||
.ob-section{
|
||||
min-width:0;
|
||||
display:grid;
|
||||
gap:var(--sp-4);
|
||||
padding-bottom:var(--sp-5);
|
||||
border-bottom:1px solid var(--border-subtle);
|
||||
}
|
||||
.ob-section__head h2{
|
||||
margin:0;
|
||||
color:var(--text-strong);
|
||||
font-size:18px;
|
||||
line-height:1.35;
|
||||
letter-spacing:0;
|
||||
}
|
||||
.ob-avatar{
|
||||
display:grid;
|
||||
grid-template-columns:auto minmax(0,1fr);
|
||||
gap:var(--sp-3);
|
||||
align-items:center;
|
||||
}
|
||||
.ob-avatar__preview{
|
||||
width:72px;
|
||||
height:72px;
|
||||
border-radius:50%;
|
||||
display:grid;
|
||||
place-items:center;
|
||||
overflow:hidden;
|
||||
background:var(--accent-tint);
|
||||
color:var(--accent-deep);
|
||||
font-size:28px;
|
||||
font-weight:800;
|
||||
border:1px solid var(--border-subtle);
|
||||
}
|
||||
.ob-avatar__preview img{
|
||||
width:100%;
|
||||
height:100%;
|
||||
display:block;
|
||||
object-fit:cover;
|
||||
}
|
||||
.ob-avatar__body{
|
||||
min-width:0;
|
||||
display:grid;
|
||||
gap:7px;
|
||||
}
|
||||
.ob-avatar__body span{
|
||||
color:var(--text-strong);
|
||||
font-size:13px;
|
||||
font-weight:780;
|
||||
}
|
||||
.ob-avatar__body p{
|
||||
margin:0;
|
||||
color:var(--text-muted);
|
||||
font-size:12.5px;
|
||||
line-height:1.45;
|
||||
}
|
||||
.ob-avatar__button{
|
||||
position:relative;
|
||||
width:max-content;
|
||||
min-height:34px;
|
||||
display:inline-flex;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
padding:0 12px;
|
||||
border:1px solid var(--border-subtle);
|
||||
border-radius:var(--radius-sm);
|
||||
background:var(--bg-surface);
|
||||
color:var(--text-strong);
|
||||
font-size:12px;
|
||||
font-weight:760;
|
||||
cursor:pointer;
|
||||
}
|
||||
.ob-avatar__button input{
|
||||
position:absolute;
|
||||
inline-size:1px;
|
||||
block-size:1px;
|
||||
opacity:0;
|
||||
pointer-events:none;
|
||||
}
|
||||
.ob-field--wide{
|
||||
grid-column:1 / -1;
|
||||
}
|
||||
.ob-fields{
|
||||
display:grid;
|
||||
grid-template-columns:repeat(2,minmax(0,1fr));
|
||||
gap:var(--sp-3);
|
||||
}
|
||||
.ob-form label{
|
||||
min-width:0;
|
||||
display:grid;
|
||||
gap:7px;
|
||||
}
|
||||
.ob-form label span{
|
||||
color:var(--text-muted);
|
||||
font-size:12px;
|
||||
font-weight:730;
|
||||
}
|
||||
.ob-form input[type="text"],
|
||||
.ob-form input:not([type]){
|
||||
min-width:0;
|
||||
}
|
||||
.ob-form input,
|
||||
.ob-form textarea{
|
||||
width:100%;
|
||||
border:1px solid var(--border-subtle);
|
||||
border-radius:var(--radius-sm);
|
||||
background:var(--bg-surface-2);
|
||||
color:var(--text-strong);
|
||||
padding:0 12px;
|
||||
font:500 var(--fs-sm)/1.2 var(--font-sans);
|
||||
}
|
||||
.ob-form input{
|
||||
min-height:42px;
|
||||
}
|
||||
.ob-form textarea{
|
||||
min-height:92px;
|
||||
padding:11px 12px;
|
||||
resize:vertical;
|
||||
line-height:1.45;
|
||||
}
|
||||
.ob-form input:focus,
|
||||
.ob-form textarea:focus{
|
||||
outline:2px solid color-mix(in srgb,var(--accent) 24%,transparent);
|
||||
border-color:var(--accent);
|
||||
}
|
||||
.ob-checks{
|
||||
display:grid;
|
||||
gap:10px;
|
||||
padding:14px;
|
||||
border:1px solid var(--border-subtle);
|
||||
border-radius:var(--radius);
|
||||
background:var(--bg-surface-2);
|
||||
}
|
||||
.ob-checks label{
|
||||
grid-template-columns:auto minmax(0,1fr);
|
||||
align-items:center;
|
||||
gap:10px;
|
||||
}
|
||||
.ob-checks input{
|
||||
width:18px;
|
||||
height:18px;
|
||||
min-height:18px;
|
||||
padding:0;
|
||||
accent-color:var(--accent);
|
||||
}
|
||||
.ob-legal{
|
||||
min-width:0;
|
||||
display:grid;
|
||||
gap:8px;
|
||||
}
|
||||
.ob-legal details{
|
||||
min-width:0;
|
||||
border:1px solid var(--border-subtle);
|
||||
border-radius:var(--radius-sm);
|
||||
background:var(--bg-surface-2);
|
||||
}
|
||||
.ob-legal summary{
|
||||
min-width:0;
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:space-between;
|
||||
gap:10px;
|
||||
min-height:42px;
|
||||
padding:0 12px;
|
||||
cursor:pointer;
|
||||
}
|
||||
.ob-legal summary span{
|
||||
min-width:0;
|
||||
color:var(--text-strong);
|
||||
font-size:13px;
|
||||
font-weight:760;
|
||||
overflow:hidden;
|
||||
text-overflow:ellipsis;
|
||||
white-space:nowrap;
|
||||
}
|
||||
.ob-legal summary b{
|
||||
flex:none;
|
||||
color:var(--text-muted);
|
||||
font-size:11px;
|
||||
font-weight:700;
|
||||
}
|
||||
.ob-note,
|
||||
.ob-error{
|
||||
margin:0;
|
||||
color:var(--text-muted);
|
||||
font-size:12.5px;
|
||||
line-height:1.5;
|
||||
}
|
||||
.ob-doc-text{
|
||||
max-height:260px;
|
||||
overflow:auto;
|
||||
white-space:pre-wrap;
|
||||
color:var(--text-body);
|
||||
font-size:12.5px;
|
||||
line-height:1.55;
|
||||
padding:0 12px 12px;
|
||||
}
|
||||
.ob-error{
|
||||
color:var(--crit-text);
|
||||
}
|
||||
.ob-actions{
|
||||
display:flex;
|
||||
justify-content:flex-start;
|
||||
}
|
||||
@media (max-width:620px){
|
||||
.ob-page{
|
||||
padding:14px;
|
||||
}
|
||||
.ob-fields{
|
||||
grid-template-columns:1fr;
|
||||
}
|
||||
.ob-avatar{
|
||||
grid-template-columns:1fr;
|
||||
}
|
||||
.ob-actions .vg-btn{
|
||||
width:100%;
|
||||
}
|
||||
}
|
||||
`;
|
||||
Loading…
Add table
Add a link
Reference in a new issue