's'
This commit is contained in:
@@ -5,12 +5,7 @@ import Link from "next/link";
|
||||
import ThemeToggle from "../components/ThemeToggle";
|
||||
|
||||
const ageRangeOptions = ["18-22", "23-27", "28-32", "33-37", "38+"];
|
||||
|
||||
function getDisplayCount(text?: string, value?: number | string, suffix = ""): string | null {
|
||||
if (typeof text === "string" && text.trim()) return `${text}${suffix}`;
|
||||
if (typeof value === "number" || typeof value === "string") return `${value}${suffix}`;
|
||||
return null;
|
||||
}
|
||||
const WECHAT_REGEX = /^[a-zA-Z0-9_-]*$/;
|
||||
|
||||
export default function VolunteerPage() {
|
||||
const [xiaohongshuUrl, setXiaohongshuUrl] = useState("");
|
||||
@@ -92,6 +87,10 @@ export default function VolunteerPage() {
|
||||
setError("请填写微信号");
|
||||
return;
|
||||
}
|
||||
if (!WECHAT_REGEX.test(wechat)) {
|
||||
setError("微信号仅允许英文字母、数字、下划线和连字符");
|
||||
return;
|
||||
}
|
||||
if (!gender) {
|
||||
setError("请选择性别");
|
||||
return;
|
||||
@@ -107,15 +106,7 @@ export default function VolunteerPage() {
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const genderLabel = gender === "女" ? "女" : gender === "男" ? "男" : "无";
|
||||
const postCountLabel = getDisplayCount(profile?.postCountText, profile?.postCount) ?? "0";
|
||||
const submitXiaohongshuUrl = profile?.resolvedUrl || xiaohongshuUrl.trim() || "";
|
||||
const submitReasonParts = [
|
||||
`[志愿者]`,
|
||||
`职业:${profession.trim()}`,
|
||||
`性别:${genderLabel}`,
|
||||
`年龄:${ageRange}`,
|
||||
profile && `发帖:${postCountLabel}`,
|
||||
].filter(Boolean);
|
||||
|
||||
const res = await fetch("/api/join", {
|
||||
method: "POST",
|
||||
@@ -128,7 +119,7 @@ export default function VolunteerPage() {
|
||||
xiaohongshu_url: submitXiaohongshuUrl,
|
||||
xiaohongshu_avatar_url: profile?.avatarUrl || "",
|
||||
gender: genderLabel,
|
||||
intro: submitReasonParts.join(" | "),
|
||||
intro: "",
|
||||
age_range: ageRange,
|
||||
city: "深圳",
|
||||
session: "volunteer",
|
||||
@@ -227,7 +218,7 @@ export default function VolunteerPage() {
|
||||
{urlError && !validating && <p className="mt-1.5 text-xs text-red-600 dark:text-red-400">⚠️ {urlError}</p>}
|
||||
{profile && !urlError && (
|
||||
<p className="mt-1.5 text-xs text-emerald-600 dark:text-emerald-400">
|
||||
✅ 已获取:{profile.nickname}
|
||||
已验证
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
@@ -256,7 +247,7 @@ export default function VolunteerPage() {
|
||||
maxLength={140}
|
||||
placeholder="用于联系"
|
||||
value={wechat}
|
||||
onChange={(e) => setWechat(e.target.value)}
|
||||
onChange={(e) => setWechat(e.target.value.replace(/[^a-zA-Z0-9_-]/g, ""))}
|
||||
required
|
||||
className="form-input"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user