Files
community-rule/lib/create/finalReviewChipWarnings.ts

91 lines
2.3 KiB
TypeScript

import type {
CommunicationMethodDetailEntry,
ConflictManagementDetailEntry,
CreateFlowState,
DecisionApproachDetailEntry,
MembershipMethodDetailEntry,
} from "../../app/(app)/create/types";
import type { TemplateFacetGroupKey } from "./templateReviewMapping";
function missingText(...values: readonly (string | undefined)[]): boolean {
return values.some((value) => (value ?? "").trim().length === 0);
}
function communicationMissingWords(
saved: CommunicationMethodDetailEntry | undefined,
): boolean {
if (!saved) return true;
return missingText(
saved.corePrinciple,
saved.logisticsAdmin,
saved.codeOfConduct,
);
}
function membershipMissingWords(
saved: MembershipMethodDetailEntry | undefined,
): boolean {
if (!saved) return true;
return missingText(
saved.eligibility,
saved.joiningProcess,
saved.expectations,
);
}
function decisionMissingWords(
saved: DecisionApproachDetailEntry | undefined,
): boolean {
if (!saved) return true;
return missingText(
saved.corePrinciple,
saved.stepByStepInstructions,
saved.objectionsDeadlocks,
);
}
function conflictMissingWords(
saved: ConflictManagementDetailEntry | undefined,
): boolean {
if (!saved) return true;
return missingText(
saved.corePrinciple,
saved.processProtocol,
saved.restorationFallbacks,
);
}
/**
* A review chip shows a warning when its value is missing meaning or signals,
* or a card is missing its words.
*/
export function finalReviewChipHasWarning(
state: CreateFlowState,
groupKey: TemplateFacetGroupKey | null,
overrideKey: string | null,
): boolean {
if (!groupKey || !overrideKey) return true;
switch (groupKey) {
case "coreValues": {
const saved = state.coreValueDetailsByChipId?.[overrideKey];
return missingText(saved?.meaning, saved?.signals);
}
case "communication":
return communicationMissingWords(
state.communicationMethodDetailsById?.[overrideKey],
);
case "membership":
return membershipMissingWords(
state.membershipMethodDetailsById?.[overrideKey],
);
case "decisionApproaches":
return decisionMissingWords(
state.decisionApproachDetailsById?.[overrideKey],
);
case "conflictManagement":
return conflictMissingWords(
state.conflictManagementDetailsById?.[overrideKey],
);
}
}