Implement core value modals

This commit is contained in:
adilallo
2026-04-15 23:13:28 -06:00
parent beae150f02
commit eedb70f9f3
15 changed files with 806 additions and 101 deletions
+34 -3
View File
@@ -1,4 +1,4 @@
import type { CreateFlowState } from "../../app/create/types";
import type { CoreValueDetailEntry, CreateFlowState } from "../../app/create/types";
import type { CommunityRuleDocumentSection } from "../../app/components/sections/CommunityRuleDocument/CommunityRuleDocument.types";
function isDocumentEntry(x: unknown): x is { title: string; body: string } {
@@ -28,6 +28,30 @@ export function parseSectionsFromCreateFlowState(
return out;
}
/** Core values selected in the flow with labels and detail text for the published document. */
export function buildCoreValuesForDocument(state: CreateFlowState): Array<{
chipId: string;
label: string;
meaning: string;
signals: string;
}> {
const snap = state.coreValuesChipsSnapshot;
const selected = new Set(state.selectedCoreValueIds ?? []);
const details = state.coreValueDetailsByChipId ?? {};
if (!snap?.length) return [];
return snap
.filter((r) => selected.has(r.id))
.map((r) => {
const d: CoreValueDetailEntry | undefined = details[r.id];
return {
chipId: r.id,
label: r.label,
meaning: d?.meaning ?? "",
signals: d?.signals ?? "",
};
});
}
export type BuildPublishPayloadResult =
| {
ok: true;
@@ -72,10 +96,17 @@ export function buildPublishPayload(
];
}
const coreValues = buildCoreValuesForDocument(state);
if (summary !== undefined) {
return { ok: true, title, summary, document: { sections } };
return {
ok: true,
title,
summary,
document: { sections, coreValues },
};
}
return { ok: true, title, document: { sections } };
return { ok: true, title, document: { sections, coreValues } };
}
/** Read `document.sections` from a stored published payload for display. */