/* Trang hồ sơ học viên: Student Center + hồ sơ hỗ trợ. */ function CProfilePage({ go, onLogout }) { const [data, setData] = React.useState(null); const [center, setCenter] = React.useState(null); const [form, setForm] = React.useState({}); const [tab, setTab] = React.useState("overview"); const [busy, setBusy] = React.useState(false); const [msg, setMsg] = React.useState(""); const [credits, setCredits] = React.useState(null); const [centerErr, setCenterErr] = React.useState(""); const [rankInfo, setRankInfo] = React.useState(null); const [curr, setCurr] = React.useState(null); const load = React.useCallback(async () => { try { const r = await (window.AG && AG.profile ? AG.profile() : {}); const sc = await (window.AG && AG.studentCenter ? AG.studentCenter().catch(() => null) : null); const cr = await (window.AG && AG.credits ? AG.credits().catch(() => null) : null); const rank = await (window.AG && AG.myRank ? AG.myRank().catch(() => null) : null); const cu = await (window.AG && AG.curriculum ? AG.curriculum().catch(() => null) : null); const p = Object.assign({}, (r && r.profile) || {}); p.contact_email = p.contact_email || p.login_email || (r && r.learn_email) || ""; p.display_name = p.display_name || p.pronoun || (r && r.name) || ""; setData(r); setCenter(sc && sc.ok ? sc : null); setCenterErr(sc && sc.ok ? "" : "Chưa tải được dữ liệu học tập."); setForm(p); if (cr && cr.ok) setCredits(cr); if (rank && rank.ok) setRankInfo(rank); setCurr(cu); } catch (e) { setData({ ok: false, msg: "Không tải được hồ sơ, thử lại nhé." }); } }, []); React.useEffect(() => { let alive = true; load().then(() => alive && true); return () => { alive = false; }; }, [load]); const set = (k, v) => setForm(Object.assign({}, form, { [k]: v })); const save = async (e) => { e.preventDefault(); setBusy(true); setMsg(""); const r = await (window.AG && AG.saveProfile ? AG.saveProfile(form) : { ok: false }); setBusy(false); if (r && r.ok) { setData(Object.assign({}, data, { profile: r.profile })); setMsg(r.msg || "Đã lưu hồ sơ."); } else setMsg((r && r.msg) || "Chưa lưu được, anh/chị thử lại nhé."); }; if (!data) return

Đang tải hồ sơ...

; if (data.ok === false) return
{data.msg || "Cần đăng nhập để xem hồ sơ."}
; const z = data.zalo || {}; const xp = rankInfo ? rankInfo.xp || 0 : 0; const lvl = getLevelInfo(xp); const hon = profileHonorific(form.gender); const displayName = form.display_name || data.name || `${hon} học viên`; const tabs = [["overview", "Tổng quan"], ["submissions", "Bài đã nộp"], ["artifacts", "Thành phẩm"], ["courses", "Khóa của tôi"], ["profile", "Hồ sơ & Ưu đãi"]]; return

Trung tâm học viên

Chào {hon} {displayName}

Danh hiệu: {lvl.name} {rankInfo && rankInfo.rank ? <> · Hạng #{rankInfo.rank} : null} {xp > 0 ? <> · {xp} XP : null}

Zalo: {z.status === "linked" ? "Đã liên kết" : "Chưa xác nhận group"}
{tabs.map((t) => )}
{centerErr &&
{centerErr}
} {tab === "overview" &&
} {tab === "submissions" && } {tab === "artifacts" && } {tab === "courses" && } {tab === "profile" &&
}
; } Object.assign(window, { CProfilePage });