nomadro/src/modules/social/components/CommunityWelcome.tsx
Eric 3e8458581a Require album face photo first, then full-session live video for audit.
Store challenge frames plus MediaRecorder stream for human review, and soft-gate dating/coffee/meetup until liveness passes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 14:53:54 +08:00

1269 lines
42 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useEffect, useRef, useState, type FormEvent } from "react";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import {
ArrowUpRight,
Camera,
Check,
Globe2,
Heart,
LockKeyhole,
MapPin,
MessageCircle,
Radio,
Send,
Users,
} from "lucide-react";
import { WechatOaModal } from "~/components/social-follow";
import SiteShell from "./SiteShell";
import JoinPayModal from "./JoinPayModal";
import AvatarSelfieModal, {
type SelfieCapturePayload,
} from "./AvatarSelfieModal";
import { PageIntro } from "./SocialUI";
import { useSocialConfig } from "./SocialExperience";
import { socialApi } from "@social/lib/api";
import { useCaptureCapability } from "@social/lib/useCaptureCapability";
import {
getLivenessState,
isLivenessVerified,
markFaceOk,
markLivenessVerified,
} from "@social/lib/livenessGate";
import {
JOIN_AVAILABILITY_OPTIONS,
JOIN_EDUCATION_OPTIONS,
JOIN_GENDER_OPTIONS,
JOIN_INTENT_OPTIONS,
JOIN_PROFILE_RETURN,
JOIN_RELATIONSHIP_OPTIONS,
JOIN_STATUS_OPTIONS,
isJoinPaid,
isJoinProfileDone,
markJoinPaid,
markJoinProfileDone,
type JoinOption,
type JoinProfileDraft,
} from "@social/lib/joinFlow";
import { setRosterPublished } from "@social/lib/discoveryRoster";
import { loadJson, saveJson } from "@social/lib/storage";
import { useLocalState } from "@social/lib/useLocalState";
import { socialPath } from "@social/lib/socialPath";
import { resolveSocialLandingCopy } from "@social/lib/landing";
import { useSocialI18n } from "@social/lib/useSocialI18n";
import { socialTx } from "@social/lib/socialTx";
import type { SocialRosterProfile } from "@social/lib/types";
export function CommunityFeedback() {
const [draft, setDraft] = useLocalState<{
kind: "反馈" | "建议";
text: string;
contact: string;
}>("feedback-draft", { kind: "建议", text: "", contact: "" });
const [delivery, setDelivery] = useLocalState("feedback-delivery", "draft");
const [status, setStatus] = useState("");
const [busy, setBusy] = useState(false);
const lock = useRef(false);
const update = (key: keyof typeof draft, value: string) => {
setDraft((current) => ({ ...current, [key]: value }));
setDelivery("draft");
setStatus("");
};
const reset = () => {
setDraft({ kind: "建议", text: "", contact: "" });
setDelivery("draft");
setStatus("");
};
const submit = async (event: FormEvent) => {
event.preventDefault();
if (!draft.text.trim() || lock.current || delivery === "sent") return;
lock.current = true;
setBusy(true);
try {
await socialApi.postFeedback({
...draft,
text: draft.text.trim(),
contact: draft.contact.trim(),
});
setDelivery("sent");
setStatus("已提交,感谢反馈。");
} catch {
setDelivery("local");
setStatus("先留在你这边了,有网后再试一次");
} finally {
lock.current = false;
setBusy(false);
}
};
return (
<SiteShell title={socialTx("说说想法")}>
<PageIntro title={socialTx("意见反馈")} accent="我们在听" />
<section className="social-panel social-feedback-panel reveal">
<div className="social-page-kicker">
<span />
{socialTx("说说你的想法")}
</div>
<h2 className="social-feedback-title">{socialTx("哪里用得不顺手?告诉我们")}</h2>
<p className="social-muted">
{socialTx("发不出去也没关系,会先留在你这边,有网后再试。我们会看,但不保证马上回复。")}
</p>
{delivery === "sent" ? (
<div className="social-join-success">
<p className="social-status" role="status">
{status || "已提交"}
</p>
<div className="social-actions">
<button
type="button"
className="social-btn primary"
onClick={reset}
>
{socialTx("再提一条")}
</button>
<Link className="social-btn" href={socialPath("/")}>
{socialTx("回社区首页")}
</Link>
</div>
</div>
) : (
<form className="social-form" onSubmit={(event) => void submit(event)}>
<fieldset disabled={busy} className="social-fieldset">
<div className="social-filters">
{(["建议", "反馈"] as const).map((kind) => (
<button
type="button"
key={kind}
className={draft.kind === kind ? "active" : ""}
aria-pressed={draft.kind === kind}
onClick={() => update("kind", kind)}
>
{kind}
</button>
))}
</div>
<label>
{socialTx("内容")}
<textarea
rows={6}
required
maxLength={3000}
value={draft.text}
onChange={(event) => update("text", event.target.value)}
placeholder={socialTx("具体页面 / 操作 / 期望…")}
/>
<small>{draft.text.length}/3000</small>
</label>
<label>
{socialTx("联系方式(选填)")}
<input
maxLength={120}
value={draft.contact}
onChange={(event) => update("contact", event.target.value)}
placeholder={socialTx("邮箱 / 微信")}
/>
</label>
</fieldset>
<button
type="submit"
className="social-btn primary"
disabled={busy || !draft.text.trim()}
>
<Send size={15} />
{busy ? "提交中…" : delivery === "local" ? "重试" : "提交"}
</button>
{status && (
<p
role="status"
className={`social-status${delivery === "local" ? " warn" : ""}`}
>
{status}
</p>
)}
</form>
)}
</section>
</SiteShell>
);
}
const EMPTY_JOIN_PROFILE: JoinProfileDraft = {
name: "",
avatar: "",
gender: "",
phone: "",
wechat: "",
city: "",
title: "",
skills: "",
education: "",
graduation: "",
relationship: "",
intents: [],
availability: "",
status: "online",
linktree: "",
bio: "",
};
function JoinSelect({
label,
value,
options,
locale,
onChange,
}: {
label: string;
value: string;
options: JoinOption[];
locale: string;
onChange: (value: string) => void;
}) {
return (
<label>
{label}
<select value={value} onChange={(e) => onChange(e.target.value)}>
{options.map((opt) => (
<option key={opt.value || "na"} value={opt.value}>
{locale === "en" ? opt.labelEn : opt.labelZh}
</option>
))}
</select>
</label>
);
}
type JoinStep = "pay" | "profile" | "done";
/** URL-only — must match SSR; localStorage flags applied after mount. */
function stepFromParam(param: string | null): JoinStep {
if (param === "profile") return "profile";
if (param === "done") return "done";
return "pay";
}
function resolveJoinStep(param: string | null): JoinStep {
if (isJoinProfileDone() || param === "done") return "done";
if (param === "profile" || isJoinPaid()) return "profile";
return "pay";
}
function JoinOnboardingLinks() {
return (
<>
<h3 className="social-onboarding-heading">
{socialTx("加入后可以先去这些地方")}
</h3>
<div className="social-grid social-onboarding-grid">
{[
{
icon: MessageCircle,
title: "群组聊天",
desc: "先进群打个招呼,混个脸熟",
href: socialPath("/chat"),
cta: "进群聊",
},
{
icon: Heart,
title: "认识一下",
desc: "左右滑,慢慢认识新朋友",
href: socialPath("/date"),
cta: "去看看",
},
{
icon: Users,
title: "我的介绍",
desc: "写几句,让别人认识你",
href: socialPath("/roster"),
cta: "去写写",
},
{
icon: Radio,
title: "开视频聊聊",
desc: "群组热身后,开麦或开视频",
href: socialPath("/meetup"),
cta: "去聊聊",
},
].map((item) => (
<article
className="social-card social-onboarding-card"
key={item.title}
>
<div className="social-card-top">
<item.icon size={24} strokeWidth={1.3} />
</div>
<h2>{item.title}</h2>
<p className="social-muted">{item.desc}</p>
<Link className="social-btn primary" href={item.href}>
{item.cta}
<ArrowUpRight size={14} />
</Link>
</article>
))}
</div>
</>
);
}
function JoinStepMark({ active }: { active: 2 | 3 }) {
return (
<p className="social-join-stepmark" aria-label={socialTx("加入步骤")}>
<span>{active === 2 ? "02" : "03"}</span>
<em>/</em>
03
<b>{active === 2 ? socialTx("资料") : socialTx("完成")}</b>
</p>
);
}
function JoinProfileForm({ onDone }: { onDone: () => void }) {
const { locale } = useSocialI18n();
const capture = useCaptureCapability();
const nameRef = useRef<HTMLInputElement>(null);
const avatarInputRef = useRef<HTMLInputElement>(null);
const captureInputRef = useRef<HTMLInputElement>(null);
// Empty seed for SSR — hydrate from localStorage after mount (avoids mismatch).
const [draft, setDraft] = useState<JoinProfileDraft>(EMPTY_JOIN_PROFILE);
const [busy, setBusy] = useState(false);
const [avatarBusy, setAvatarBusy] = useState(false);
const [avatarErr, setAvatarErr] = useState("");
const [selfieOpen, setSelfieOpen] = useState(false);
const [faceOk, setFaceOk] = useState(false);
const [liveOk, setLiveOk] = useState(false);
const [err, setErr] = useState("");
const lock = useRef(false);
useEffect(() => {
const s = getLivenessState();
setFaceOk(s.faceOk);
setLiveOk(s.livenessStatus === "verified");
}, []);
/** Step 1: always prefer album / clear face photo */
const openPrimaryCapture = () => {
avatarInputRef.current?.click();
};
const avatarHint = (() => {
if (avatarBusy) return socialTx("检测人脸并上传中…");
if (!capture.ready) return socialTx("检测设备中…");
if (liveOk) return socialTx("真人核验已通过,头像可用于社区");
if (faceOk) {
return socialTx("已检测到人脸。请继续现场实拍(全程录像)以开放约会等功能");
}
return socialTx("请先上传清晰正脸照片(自拍或相册),通过人脸检测后再实拍核验");
})();
useEffect(() => {
const saved = loadJson<Partial<JoinProfileDraft>>(
"join-profile",
EMPTY_JOIN_PROFILE,
);
const nickLs =
typeof window !== "undefined"
? localStorage.getItem("userName") || ""
: "";
const nick =
(nickLs && !nickLs.includes("@") ? nickLs : "") ||
loadJson<string>("nick", "") ||
saved.name ||
"";
setDraft({
...EMPTY_JOIN_PROFILE,
...saved,
intents: Array.isArray(saved.intents) ? saved.intents : [],
availability:
typeof saved.availability === "string" ? saved.availability : "",
status:
typeof saved.status === "string" && saved.status
? saved.status
: "online",
name: typeof nick === "string" ? nick : "",
avatar:
typeof saved.avatar === "string" && !saved.avatar.startsWith("blob:")
? saved.avatar
: "",
});
nameRef.current?.focus();
}, []);
const update = <K extends keyof JoinProfileDraft>(
key: K,
value: JoinProfileDraft[K],
) => {
setDraft((current) => ({ ...current, [key]: value }));
setErr("");
};
const onAvatarPick = async (file: File | null) => {
if (!file || avatarBusy) return;
const mime = (file.type || "").toLowerCase();
const okMime =
!mime ||
mime.startsWith("image/") ||
/\.(jpe?g|png|webp|gif)$/i.test(file.name);
if (!okMime) {
setAvatarErr(socialTx("请选择图片文件"));
return;
}
if (file.size > 8 * 1024 * 1024) {
setAvatarErr(socialTx("头像不能超过 8MB"));
return;
}
setAvatarBusy(true);
setAvatarErr("");
setErr("");
// Instant local preview while uploading / face-checking
const localUrl = URL.createObjectURL(file);
setDraft((current) => ({ ...current, avatar: localUrl }));
try {
const uploaded = await socialApi.uploadAvatar(file, "avatar");
const url = (uploaded?.url || "").trim();
if (!url) throw new Error(socialTx("头像上传失败"));
setDraft((current) => {
const next = { ...current, avatar: url };
saveJson("join-profile", next);
const roster = loadJson<SocialRosterProfile>("roster", {
name: "",
title: "",
city: "",
phone: "",
linktree: "",
skills: "",
bio: "",
avatar: "",
});
saveJson("roster", { ...roster, avatar: url });
return next;
});
markFaceOk();
setFaceOk(true);
setAvatarErr("");
requestAnimationFrame(() => URL.revokeObjectURL(localUrl));
// After face photo OK → nudge live capture (do not auto-open camera)
if (!isLivenessVerified() && capture.mode === "live-modal") {
setErr("");
}
} catch (e) {
setDraft((current) => ({ ...current, avatar: "" }));
URL.revokeObjectURL(localUrl);
const raw =
e instanceof Error ? e.message.slice(0, 160).trim() : "";
const msg =
raw && !/^upload failed|^no url|^上传失败 HTTP/i.test(raw)
? socialTx(raw)
: socialTx("头像上传失败");
setAvatarErr(msg || socialTx("头像上传失败"));
} finally {
setAvatarBusy(false);
}
};
const onSelfieChallenge = async (payload: SelfieCapturePayload) => {
setAvatarBusy(true);
setAvatarErr("");
setErr("");
const preview = URL.createObjectURL(payload.front);
setDraft((current) => ({ ...current, avatar: preview }));
try {
const uploaded = await socialApi.uploadAvatarChallenge(
payload.front,
payload.turn,
payload.video,
payload.videoMime,
);
const url = (uploaded?.url || "").trim();
if (!url) throw new Error(socialTx("头像上传失败"));
setDraft((current) => {
const next = { ...current, avatar: url };
saveJson("join-profile", next);
const roster = loadJson<SocialRosterProfile>("roster", {
name: "",
title: "",
city: "",
phone: "",
linktree: "",
skills: "",
bio: "",
avatar: "",
});
saveJson("roster", { ...roster, avatar: url });
return next;
});
markFaceOk();
markLivenessVerified({ videoUrl: uploaded.videoUrl || "" });
setFaceOk(true);
setLiveOk(true);
setAvatarErr("");
requestAnimationFrame(() => URL.revokeObjectURL(preview));
} catch (e) {
URL.revokeObjectURL(preview);
const raw =
e instanceof Error ? e.message.slice(0, 160).trim() : "";
setAvatarErr(
raw ? socialTx(raw) || raw : socialTx("真人核验失败,请重试"),
);
throw e instanceof Error ? e : new Error(socialTx("真人核验失败,请重试"));
} finally {
setAvatarBusy(false);
}
};
const toggleIntent = (value: string) => {
setDraft((current) => {
const has = current.intents.includes(value);
return {
...current,
intents: has
? current.intents.filter((item) => item !== value)
: [...current.intents, value],
};
});
};
const submit = async (event: FormEvent) => {
event.preventDefault();
if (lock.current) return;
const name = draft.name.trim();
if (!name) {
setErr(socialTx("请填写怎么称呼你"));
nameRef.current?.focus();
return;
}
if (!draft.city.trim()) {
setErr(socialTx("请填写当前城市,方便同城推荐"));
return;
}
if (!draft.intents.length) {
setErr(socialTx("请至少选一个「想认识 / 想做什么」"));
return;
}
if (!draft.skills.trim()) {
setErr(socialTx("请填写技能或兴趣标签(逗号分隔)"));
return;
}
if (draft.linktree.trim() && !/^https?:\/\//i.test(draft.linktree.trim())) {
setErr(socialTx("作品链接请以 https:// 或 http:// 开头。"));
return;
}
lock.current = true;
setBusy(true);
setErr("");
const intentLabels = draft.intents
.map(
(id) =>
JOIN_INTENT_OPTIONS.find((opt) => opt.value === id)?.[
locale === "en" ? "labelEn" : "labelZh"
] || id,
)
.filter(Boolean);
const availLabel =
JOIN_AVAILABILITY_OPTIONS.find((o) => o.value === draft.availability)?.[
locale === "en" ? "labelEn" : "labelZh"
] || draft.availability;
const lookingFor = intentLabels.join(" · ");
const avatar =
draft.avatar.startsWith("blob:") ? "" : draft.avatar.trim();
const roster: SocialRosterProfile = {
name,
title: draft.title.trim(),
city: draft.city.trim(),
phone: draft.phone.trim(),
linktree: draft.linktree.trim(),
skills: draft.skills.trim(),
bio: draft.bio.trim(),
avatar,
intents: draft.intents.join(","),
availability: availLabel || draft.availability,
status: draft.status || "online",
lookingFor,
gender: draft.gender,
updatedAt: new Date().toISOString(),
};
try {
saveJson("roster", roster);
saveJson("nick", name);
saveJson("join-profile", draft);
setRosterPublished(true);
await socialApi.saveRoster({
name: roster.name,
title: roster.title,
city: roster.city,
phone: roster.phone,
linktree: roster.linktree,
skills: roster.skills,
bio: roster.bio,
avatar: roster.avatar || "",
gender: draft.gender,
relationship: draft.relationship,
education: draft.education,
graduation: draft.graduation.trim(),
wechat: draft.wechat.trim(),
intents: draft.intents.join(","),
availability: roster.availability || "",
status: roster.status || "online",
lookingFor,
discoverable: "1",
updatedAt: roster.updatedAt || "",
});
} catch {
// Offline / API fail: keep local draft; still mark profile done so UX continues
}
markJoinProfileDone();
lock.current = false;
setBusy(false);
onDone();
};
const summaryName = draft.name.trim() || socialTx("你的名字");
const summaryCity = draft.city.trim() || socialTx("城市待写");
const summaryTitle = draft.title.trim() || socialTx("职业待写");
const summaryBio =
draft.bio.trim() || socialTx("自我介绍会出现在这里");
const summaryInitial = (draft.name.trim()[0] || "N").toUpperCase();
const summaryGender =
JOIN_GENDER_OPTIONS.find((opt) => opt.value === draft.gender)?.[
locale === "en" ? "labelEn" : "labelZh"
] || "";
const summaryRel =
JOIN_RELATIONSHIP_OPTIONS.find((opt) => opt.value === draft.relationship)?.[
locale === "en" ? "labelEn" : "labelZh"
] || "";
const summarySkills = draft.skills
.split(/[,,、]/)
.map((s) => s.trim())
.filter(Boolean)
.slice(0, 5);
const summaryIntents = draft.intents
.map(
(id) =>
JOIN_INTENT_OPTIONS.find((opt) => opt.value === id)?.[
locale === "en" ? "labelEn" : "labelZh"
] || id,
)
.slice(0, 6);
const filled = [
draft.name,
draft.avatar && !draft.avatar.startsWith("blob:") ? draft.avatar : "",
draft.city,
draft.title,
draft.bio,
].filter((v) => v.trim()).length;
return (
<section className="social-join-desk">
<aside className="social-join-desk-aside">
<JoinStepMark active={2} />
<header className="social-join-desk-intro">
<h1>{socialTx("完善资料,方便认识你")}</h1>
<p>{socialTx("支付已完成。写得越完整,越容易碰到同频的人。")}</p>
</header>
<article className="social-join-live-card" aria-live="polite">
<div className="social-join-live-glow" aria-hidden />
<div className="social-join-live-pattern" aria-hidden>
<Globe2 size={150} strokeWidth={0.55} />
</div>
<div className="social-join-live-top">
<button
type="button"
className="social-join-live-mono"
data-empty={!draft.avatar && !draft.name.trim()}
data-busy={avatarBusy || undefined}
aria-label={socialTx("上传头像")}
onClick={() => avatarInputRef.current?.click()}
>
{draft.avatar ? (
// eslint-disable-next-line @next/next/no-img-element
<img src={draft.avatar} alt="" />
) : (
summaryInitial
)}
<span className="social-join-live-cam" aria-hidden>
<Camera size={14} />
</span>
</button>
<div className="social-join-live-meter" aria-label={socialTx("名片完整度")}>
<span>
{socialTx("名片完整度")} {filled}/5
</span>
<i>
<b style={{ width: `${(filled / 5) * 100}%` }} />
</i>
</div>
</div>
<p className="social-join-live-kicker">{socialTx("实时预览")}</p>
<h2 className="social-join-live-name">{summaryName}</h2>
<p className="social-join-live-title">{summaryTitle}</p>
<p className="social-join-live-city">
<MapPin size={13} aria-hidden />
{summaryCity}
</p>
{(summaryGender && draft.gender) || (summaryRel && draft.relationship) ? (
<div className="social-join-live-meta">
{draft.gender ? <span>{summaryGender}</span> : null}
{draft.relationship ? <span>{summaryRel}</span> : null}
</div>
) : null}
{summarySkills.length ? (
<div className="social-join-live-tags">
{summarySkills.map((skill) => (
<span key={skill}>{skill}</span>
))}
</div>
) : null}
{summaryIntents.length ? (
<div className="social-join-live-tags is-intent">
{summaryIntents.map((item) => (
<span key={item}>{item}</span>
))}
</div>
) : (
<p className="social-join-live-hint">
{socialTx("勾选你想在社区做的事,会出现在这里")}
</p>
)}
<p className="social-join-live-bio">{summaryBio}</p>
<footer>
<span>{socialTx("游民社区")}</span>
<span aria-hidden>✦</span>
</footer>
</article>
</aside>
<form
className="social-form social-join-desk-form"
onSubmit={(event) => void submit(event)}
aria-busy={busy}
>
<input
ref={avatarInputRef}
type="file"
accept="image/jpeg,image/png,image/webp,image/gif"
className="social-join-file-input"
tabIndex={-1}
onChange={(e) => {
const file = e.target.files?.[0] || null;
e.target.value = "";
void onAvatarPick(file);
}}
/>
{/* Mobile native camera — capture=user opens front camera sheet */}
<input
ref={captureInputRef}
type="file"
accept="image/*"
capture="user"
className="social-join-file-input"
tabIndex={-1}
onChange={(e) => {
const file = e.target.files?.[0] || null;
e.target.value = "";
void onAvatarPick(file);
}}
/>
<fieldset disabled={busy} className="social-fieldset social-join-fields">
<p className="social-join-section">{socialTx("基本信息")}</p>
<div
className="social-join-avatar-row social-join-span-2"
data-capture-mode={capture.mode}
data-capture-ready={capture.ready ? "true" : "false"}
data-device={capture.isMobile ? "mobile" : "pc"}
>
<button
type="button"
className={`social-join-avatar-btn${avatarErr ? " is-error" : ""}${avatarBusy ? " is-busy" : ""}`}
disabled={avatarBusy || !capture.ready}
aria-busy={avatarBusy}
aria-invalid={Boolean(avatarErr) || undefined}
onClick={openPrimaryCapture}
>
{draft.avatar ? (
// eslint-disable-next-line @next/next/no-img-element
<img src={draft.avatar} alt="" />
) : (
<Camera size={22} />
)}
{avatarBusy ? (
<span className="social-join-avatar-spin" aria-hidden />
) : null}
</button>
<div>
<strong>{socialTx("头像")}</strong>
<p>{avatarHint}</p>
{avatarErr ? (
<p className="social-join-avatar-err" role="alert">
{avatarErr}
</p>
) : null}
{faceOk && !liveOk ? (
<div className="social-join-liveness-banner" role="status">
<p>
{socialTx(
"人脸已通过。必须完成现场实拍核验(全程录像,供人工审核),否则约会 / 咖啡聊 / 视频厅等功能无法开放。",
)}
</p>
<button
type="button"
className="social-join-avatar-action"
disabled={avatarBusy || capture.mode !== "live-modal"}
onClick={() => setSelfieOpen(true)}
>
{socialTx("开始实拍核验")}
</button>
</div>
) : null}
{liveOk ? (
<p className="social-join-liveness-ok" role="status">
{socialTx("真人核验已通过")}
</p>
) : null}
<div className="social-join-avatar-actions">
<button
type="button"
className="social-join-avatar-action"
disabled={avatarBusy}
onClick={() => avatarInputRef.current?.click()}
>
{socialTx("上传正脸照片")}
</button>
{capture.isMobile ? (
<button
type="button"
className="social-join-avatar-action is-ghost"
disabled={avatarBusy}
onClick={() => captureInputRef.current?.click()}
>
{socialTx("手机拍照上传")}
</button>
) : null}
{faceOk && !liveOk && capture.mode === "live-modal" ? (
<button
type="button"
className="social-join-avatar-action is-ghost"
disabled={avatarBusy || !capture.ready}
onClick={() => setSelfieOpen(true)}
>
{socialTx("现场实拍核验")}
</button>
) : null}
{draft.avatar && !draft.avatar.startsWith("blob:") ? (
<button
type="button"
className="social-join-avatar-clear"
onClick={() => {
setAvatarErr("");
update("avatar", "");
}}
>
{socialTx("移除头像")}
</button>
) : null}
</div>
</div>
</div>
<label className="social-join-span-2">
{socialTx("怎么称呼你")}
<input
ref={nameRef}
required
maxLength={40}
autoComplete="nickname"
placeholder={socialTx("一个让人记得住的名字")}
value={draft.name}
onChange={(e) => update("name", e.target.value)}
/>
</label>
<JoinSelect
label={socialTx("性别(选填)")}
value={draft.gender}
options={JOIN_GENDER_OPTIONS}
locale={locale}
onChange={(value) => update("gender", value)}
/>
<JoinSelect
label={socialTx("感情状态(选填)")}
value={draft.relationship}
options={JOIN_RELATIONSHIP_OPTIONS}
locale={locale}
onChange={(value) => update("relationship", value)}
/>
<label className="social-join-span-2">
{socialTx("此刻在哪座城市")}
<span className="social-join-req">*</span>
<input
required
maxLength={80}
autoComplete="address-level2"
placeholder={socialTx("清迈、里斯本,或者正在路上")}
value={draft.city}
onChange={(e) => update("city", e.target.value)}
/>
</label>
<JoinSelect
label={socialTx("当前状态")}
value={draft.status || "online"}
options={JOIN_STATUS_OPTIONS}
locale={locale}
onChange={(value) => update("status", value || "online")}
/>
<JoinSelect
label={socialTx("可约时段")}
value={draft.availability}
options={JOIN_AVAILABILITY_OPTIONS}
locale={locale}
onChange={(value) => update("availability", value)}
/>
<p className="social-join-section">{socialTx("工作与背景")}</p>
<label>
{socialTx("你的职业或专业")}
<input
maxLength={80}
placeholder={socialTx("独立开发者 / 设计师 / 自由撰稿人…")}
value={draft.title}
onChange={(e) => update("title", e.target.value)}
/>
</label>
<label>
{socialTx("擅长什么,喜欢什么")}
<span className="social-join-req">*</span>
<input
required
maxLength={200}
placeholder={socialTx("设计, 摄影, 冲浪, 开源项目…")}
value={draft.skills}
onChange={(e) => update("skills", e.target.value)}
/>
</label>
<JoinSelect
label={socialTx("学历(选填)")}
value={draft.education}
options={JOIN_EDUCATION_OPTIONS}
locale={locale}
onChange={(value) => update("education", value)}
/>
<label>
{socialTx("毕业时间(选填)")}
<input
maxLength={20}
placeholder={socialTx("如 2019 或 在读")}
value={draft.graduation}
onChange={(e) => update("graduation", e.target.value)}
/>
</label>
<p className="social-join-section">
{socialTx("你想在社区做什么")}
<span className="social-join-req">*</span>
</p>
<div
className="social-join-intent-grid social-join-span-2"
role="group"
aria-label={socialTx("你想在社区做什么")}
>
{JOIN_INTENT_OPTIONS.map((opt) => {
const on = draft.intents.includes(opt.value);
return (
<button
key={opt.value}
type="button"
className={`social-join-intent${on ? " is-on" : ""}`}
aria-pressed={on}
onClick={() => toggleIntent(opt.value)}
>
{locale === "en" ? opt.labelEn : opt.labelZh}
</button>
);
})}
</div>
<label className="full social-join-span-2">
{socialTx("自我介绍")}
<textarea
rows={4}
maxLength={600}
placeholder={socialTx("分享经历、兴趣或加入原因,越详细越好")}
value={draft.bio}
onChange={(e) => update("bio", e.target.value)}
/>
<small>{draft.bio.length}/600</small>
</label>
<p className="social-join-section">{socialTx("联系方式(选填)")}</p>
<label>
{socialTx("手机号")}
<input
type="tel"
inputMode="tel"
maxLength={20}
autoComplete="tel"
placeholder={socialTx("方便拉群联络")}
value={draft.phone}
onChange={(e) => update("phone", e.target.value)}
/>
</label>
<label>
{socialTx("微信号")}
<input
maxLength={40}
placeholder={socialTx("选填")}
value={draft.wechat}
onChange={(e) => update("wechat", e.target.value)}
/>
</label>
<label className="social-join-span-2">
{socialTx("作品 / 主页链接(选填)")}
<input
type="url"
maxLength={400}
placeholder="https://"
value={draft.linktree}
onChange={(e) => update("linktree", e.target.value)}
/>
</label>
</fieldset>
{err ? (
<p className="social-join-err" role="alert">
{err}
</p>
) : null}
<div className="social-join-desk-foot">
<button
type="submit"
className="social-btn coral social-join-desk-submit"
disabled={busy || !draft.name.trim()}
>
{busy ? socialTx("保存中…") : socialTx("提交资料,进入社区")}
<ArrowUpRight size={15} />
</button>
<p className="social-join-desk-hint">
{socialTx("资料先存在本机,有网再同步。")}
</p>
</div>
</form>
{capture.mode === "live-modal" ? (
<AvatarSelfieModal
open={selfieOpen}
onClose={() => setSelfieOpen(false)}
onCaptured={onSelfieChallenge}
/>
) : null}
</section>
);
}
export function CommunityJoin() {
const config = useSocialConfig();
const { locale } = useSocialI18n();
const copy = resolveSocialLandingCopy(config.copy, locale);
const searchParams = useSearchParams();
const router = useRouter();
const stepParam = searchParams.get("step");
const [step, setStep] = useState<JoinStep>(() => stepFromParam(stepParam));
const [payOpen, setPayOpen] = useState(false);
const [oaOpen, setOaOpen] = useState(false);
useEffect(() => {
const next = resolveJoinStep(stepParam);
setStep(next);
if (next === "profile" && !isJoinPaid()) {
// Arrived via ?step=profile after pay confirm
markJoinPaid();
}
if (next === "profile" && stepParam !== "profile") {
router.replace(JOIN_PROFILE_RETURN);
}
}, [stepParam, router]);
const goDone = () => {
setStep("done");
router.replace(`${socialPath("/join")}?step=done`);
};
const focusMode = step === "profile" || step === "done";
return (
<SiteShell title={socialTx("加入社区")} immersive={focusMode}>
{step === "pay" ? (
<PageIntro
title={socialTx("加入社区")}
accent={socialTx("先支付,再填资料")}
/>
) : null}
{step === "profile" ? (
<JoinProfileForm onDone={goDone} />
) : null}
{step === "done" ? (
<section className="social-join-desk social-join-desk--done">
<aside className="social-join-desk-aside">
<JoinStepMark active={3} />
<header className="social-join-desk-intro">
<h1>{socialTx("欢迎加入")}</h1>
<p>
{socialTx("你可以先去群里打个招呼,或者把介绍写得更完整一点。")}
</p>
</header>
</aside>
<div className="social-join-desk-form social-join-done-panel">
<div className="social-actions">
<Link className="social-btn coral" href={socialPath("/chat")}>
{socialTx("进群聊")}
<ArrowUpRight size={15} />
</Link>
<Link className="social-btn" href={socialPath("/roster")}>
{socialTx("完善介绍")}
<ArrowUpRight size={15} />
</Link>
</div>
</div>
</section>
) : null}
{step === "pay" ? (
<>
<div className="social-join-paths">
<article className="social-panel social-join-path reveal">
<span className="social-page-kicker">
<span />
{socialTx("方式一")}
</span>
<span className="social-join-path-ico" aria-hidden>
<LockKeyhole size={24} strokeWidth={1.4} />
</span>
<h2>{copy.socialPayJoinLabel}</h2>
<p>
{socialTx(
"先填邮箱并完成支付,支付成功后再填写个人资料。电脑、手机浏览器和微信里都会带你走合适的支付方式。",
)}
</p>
{config.flags.payEnabled ? (
<button
type="button"
className="social-btn coral"
onClick={() => setPayOpen(true)}
>
{copy.socialPayJoinLabel}
<ArrowUpRight size={15} />
</button>
) : (
<span className="social-status">
{socialTx("暂时还不能购买")}
</span>
)}
</article>
<article className="social-panel social-join-path reveal">
<span className="social-page-kicker">
<span />
{socialTx("方式二")}
</span>
<span className="social-join-path-ico" aria-hidden>
<MessageCircle size={24} strokeWidth={1.4} />
</span>
<h2>{copy.socialOaJoinLabel}</h2>
<p>
关注
{config.copy.wechatOaName
? `「${config.copy.wechatOaName}」`
: "公众号"}
,先看看社区动态和活动,再决定要不要正式加入。
</p>
<button
type="button"
className="social-btn primary"
onClick={() => setOaOpen(true)}
>
{copy.socialOaJoinLabel}
<ArrowUpRight size={15} />
</button>
</article>
</div>
</>
) : null}
{step !== "profile" ? <JoinOnboardingLinks /> : null}
<JoinPayModal open={payOpen} onClose={() => setPayOpen(false)} />
<WechatOaModal open={oaOpen} onClose={() => setOaOpen(false)} />
</SiteShell>
);
}
export function CommunityMembership() {
const config = useSocialConfig();
const price = ((config.copy.vipPriceFen ?? 8800) / 100).toLocaleString(
"zh-CN",
{ maximumFractionDigits: 2 },
);
const benefits = [
"更好地展示自己的介绍",
"更方便认识想见的人",
"视频见面与同城活动更新提醒",
"找搭子做事时优先沟通",
];
return (
<SiteShell title={socialTx("会员")}>
<PageIntro title={socialTx("会员")} accent={`¥${price}`} />
<section className="social-membership-banner reveal">
<div className="social-page-kicker">
<span />
{socialTx("会员通行证")}
</div>
<h2 className="social-feedback-title">{socialTx("游民会员")}</h2>
<p className="social-muted">
{socialTx("开通后能更方便参与社区。具体权益以支付页说明为准。")}
</p>
<ul className="social-benefit-list">
{benefits.map((item) => (
<li key={item}>
<Check size={15} />
{item}
</li>
))}
</ul>
<div className="social-actions">
{config.flags.payEnabled ? (
<Link className="social-btn coral" href="/vip">
{config.copy.vipCta || "开通会员"}
<ArrowUpRight size={15} />
</Link>
) : (
<span className="social-status">{socialTx("暂时还不能购买")}</span>
)}
<Link className="social-btn" href={socialPath("/join")}>
{socialTx("去加入社区")}
</Link>
</div>
</section>
<div className="social-grid">
{[
{ title: "我的介绍", href: socialPath("/roster") },
{ title: "认识一下", href: socialPath("/date") },
{ title: "城市 / 咖啡馆", href: socialPath("/places") },
{ title: "大家聊天", href: socialPath("/chat") },
].map((item) => (
<Link
className="social-card social-membership-card"
href={item.href}
key={item.href}
>
<Check size={18} />
<h2>{item.title}</h2>
<span>
{socialTx("打开")} <ArrowUpRight size={14} />
</span>
</Link>
))}
</div>
</SiteShell>
);
}