nomadro/src/modules/social/lib/joinFlow.ts
Eric b06a14b6aa Ship social admin nested menus with list/detail CRUD, soft-archive UGC, and PocketBase-ready stores.
admin.nomadro.com gets sidebar L1/L2 social ops (paginated lists + entity detail); API adds soft-delete archives/stats and shared nomadro_pb for social/coffee/notify/work.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 16:41:43 +08:00

178 lines
6.0 KiB
TypeScript

/** Social join: pay first, then complete profile. */
export const JOIN_PENDING_PROFILE_KEY = "social-join-pending-profile";
export const JOIN_PAID_KEY = "social-join-paid";
export const JOIN_PROFILE_DONE_KEY = "social-join-profile-done";
export const JOIN_PROFILE_RETURN = "/social/join?step=profile";
export type JoinProfileDraft = {
name: string;
avatar: string;
gender: string;
phone: string;
wechat: string;
city: string;
title: string;
skills: string;
education: string;
graduation: string;
relationship: string;
/** who-to-meet / why join — required for cold-start matching */
intents: string[];
/** e.g. 本周可 coffeechat / 欧洲晚间可视频 */
availability: string;
/** online | away | offline — discovery “在线优先” */
status: string;
linktree: string;
bio: string;
};
export type JoinOption = { value: string; labelZh: string; labelEn: string };
export const JOIN_GENDER_OPTIONS: JoinOption[] = [
{ value: "", labelZh: "不方便说", labelEn: "Prefer not to say" },
{ value: "f", labelZh: "女", labelEn: "Woman" },
{ value: "m", labelZh: "男", labelEn: "Man" },
{ value: "nb", labelZh: "非二元 / 其他", labelEn: "Non-binary / other" },
];
export const JOIN_RELATIONSHIP_OPTIONS: JoinOption[] = [
{ value: "", labelZh: "不方便说", labelEn: "Prefer not to say" },
{ value: "single", labelZh: "单身", labelEn: "Single" },
{ value: "dating", labelZh: "恋爱中", labelEn: "Dating" },
{ value: "taken", labelZh: "有伴", labelEn: "In a relationship" },
{ value: "married", labelZh: "已婚", labelEn: "Married" },
{ value: "open", labelZh: "开放式关系", labelEn: "Open relationship" },
{ value: "complicated", labelZh: "说不清", labelEn: "It's complicated" },
];
export const JOIN_EDUCATION_OPTIONS: JoinOption[] = [
{ value: "", labelZh: "不方便说", labelEn: "Prefer not to say" },
{ value: "highschool", labelZh: "高中及以下", labelEn: "High school or below" },
{ value: "college", labelZh: "大专", labelEn: "Associate / college" },
{ value: "bachelor", labelZh: "本科", labelEn: "Bachelor's" },
{ value: "master", labelZh: "硕士", labelEn: "Master's" },
{ value: "phd", labelZh: "博士", labelEn: "PhD" },
{ value: "other", labelZh: "其他", labelEn: "Other" },
];
/** Multi-select: why you're joining / what you want. */
export const JOIN_INTENT_OPTIONS: JoinOption[] = [
{ value: "meetup", labelZh: "线下聚会", labelEn: "Meet in person" },
{ value: "online", labelZh: "线上分享", labelEn: "Online hangouts" },
{ value: "cowork", labelZh: "远程 cowork", labelEn: "Remote cowork" },
{ value: "collab", labelZh: "找搭子做事", labelEn: "Find collaborators" },
{ value: "cofounder", labelZh: "找联创", labelEn: "Find a cofounder" },
{ value: "friends", labelZh: "交朋友", labelEn: "Make friends" },
{ value: "date", labelZh: "认识有缘人", labelEn: "Meet someone" },
{ value: "learn", labelZh: "学习成长", labelEn: "Learn & grow" },
{ value: "resource", labelZh: "资源互助", labelEn: "Share resources" },
];
/** Preferred hangout windows for coffeechat / meetup matching. */
export const JOIN_AVAILABILITY_OPTIONS: JoinOption[] = [
{ value: "", labelZh: "先不填", labelEn: "Skip for now" },
{ value: "weekday-eve", labelZh: "工作日晚上", labelEn: "Weekday evenings" },
{ value: "weekend", labelZh: "周末可约", labelEn: "Weekends" },
{ value: "flexible", labelZh: "时间灵活", labelEn: "Flexible" },
{ value: "tz-async", labelZh: "跨时区异步", labelEn: "Async / timezone-friendly" },
];
/** Discovery presence signal (not GPS). */
export const JOIN_STATUS_OPTIONS: JoinOption[] = [
{ value: "online", labelZh: "在线 · 想认识人", labelEn: "Online · open to meet" },
{ value: "here", labelZh: "同城 · 想出来", labelEn: "In city · want to hang" },
{ value: "away", labelZh: "先潜水看看", labelEn: "Lurking for now" },
{ value: "offline", labelZh: "暂时隐身", labelEn: "Appear offline" },
];
export function markJoinPayIntent(): void {
try {
localStorage.setItem(JOIN_PENDING_PROFILE_KEY, "1");
} catch {
/* ignore */
}
}
export function markJoinPaid(): void {
try {
localStorage.setItem(JOIN_PAID_KEY, "1");
localStorage.setItem("paidType", "vip");
} catch {
/* ignore */
}
}
export function clearJoinPayIntent(): void {
try {
localStorage.removeItem(JOIN_PENDING_PROFILE_KEY);
} catch {
/* ignore */
}
}
export function isJoinPaid(): boolean {
try {
// Only the join-flow flag — do not treat generic VIP paidType as join-paid
return localStorage.getItem(JOIN_PAID_KEY) === "1";
} catch {
return false;
}
}
export function isJoinProfileDone(): boolean {
try {
return localStorage.getItem(JOIN_PROFILE_DONE_KEY) === "1";
} catch {
return false;
}
}
export function markJoinProfileDone(): void {
try {
localStorage.setItem(JOIN_PROFILE_DONE_KEY, "1");
clearJoinPayIntent();
} catch {
/* ignore */
}
}
/** Re-open profile form (e.g. ?step=profile after wipe / localhost QA). */
export function clearJoinProfileDone(): void {
try {
localStorage.removeItem(JOIN_PROFILE_DONE_KEY);
} catch {
/* ignore */
}
}
/** After /paid confirms success — send joiners to profile step. */
export function resolvePostPayHref(): string {
try {
if (localStorage.getItem(JOIN_PENDING_PROFILE_KEY) === "1") {
markJoinPaid();
return JOIN_PROFILE_RETURN;
}
} catch {
/* ignore */
}
return "/";
}
/** Localhost / NODE_DEV only — skip real checkout while debugging join profile. */
export function isJoinPaySkipAllowed(): boolean {
if (typeof window === "undefined") return false;
if (process.env.NODE_ENV === "development") return true;
const host = window.location.hostname;
return host === "localhost" || host === "127.0.0.1" || host === "[::1]";
}
/** Dev helper: pretend pay succeeded and open the profile step. */
export function skipJoinPayToProfile(): void {
markJoinPayIntent();
markJoinPaid();
clearJoinPayIntent();
window.location.assign(JOIN_PROFILE_RETURN);
}