44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import type { CreateFlowState } from "../../app/(app)/create/types";
|
|
import { RULE_SECTION_CATEGORY } from "./ruleSectionsFromMethodSelections";
|
|
import {
|
|
membershipPresetFor,
|
|
publishedMethodDisplayLabel,
|
|
} from "./finalReviewChipPresets";
|
|
|
|
export type MembershipInvitePreview = {
|
|
categoryName: string;
|
|
title: string;
|
|
eligibility: string;
|
|
joiningProcess: string;
|
|
};
|
|
|
|
/** First selected membership method, for the Invite your members card. */
|
|
export function membershipInvitePreview(
|
|
state: CreateFlowState,
|
|
): MembershipInvitePreview | null {
|
|
const ids = state.selectedMembershipMethodIds ?? [];
|
|
const firstId = ids.find((id) => typeof id === "string" && id.trim() !== "");
|
|
if (!firstId) return null;
|
|
|
|
const saved = state.membershipMethodDetailsById?.[firstId];
|
|
const preset = membershipPresetFor(firstId);
|
|
const eligibility = (saved?.eligibility ?? "").trim() || preset.eligibility;
|
|
const joiningProcess =
|
|
(saved?.joiningProcess ?? "").trim() || preset.joiningProcess;
|
|
const title =
|
|
publishedMethodDisplayLabel(
|
|
"membership",
|
|
firstId,
|
|
state.customMethodCardMetaById,
|
|
) || firstId;
|
|
|
|
if (!title && !eligibility && !joiningProcess) return null;
|
|
|
|
return {
|
|
categoryName: RULE_SECTION_CATEGORY.membership,
|
|
title,
|
|
eligibility,
|
|
joiningProcess,
|
|
};
|
|
}
|