refactor(representations): extract journey step-resolution helpers (Slice R3, behaviour-preserving) Related work items: #22441
74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
export const resolveJourneyStageFlags = ({
|
|
representationSubmit,
|
|
representationSubmitConfirmation
|
|
}) => {
|
|
const showCheckStage =
|
|
representationSubmit === true || representationSubmit === "true";
|
|
const showCompletionStage =
|
|
representationSubmitConfirmation === true ||
|
|
representationSubmitConfirmation === "true";
|
|
|
|
return {
|
|
showFormStage: !showCheckStage,
|
|
showCheckStage,
|
|
showCompletionStage
|
|
};
|
|
};
|
|
|
|
export const resolveRepresentationControlKey = ({
|
|
isLPA,
|
|
representationCapacity,
|
|
repDetailsCapacity,
|
|
appealType,
|
|
normalizeCapacity
|
|
}) => {
|
|
if (isLPA && (!representationCapacity || representationCapacity === "")) {
|
|
return {
|
|
controlKey: "lpa-capacity-selection",
|
|
normalizedCapacity: ""
|
|
};
|
|
}
|
|
|
|
const rawCapacity = representationCapacity || repDetailsCapacity || "false";
|
|
const normalizedCapacity = normalizeCapacity(rawCapacity.toLowerCase());
|
|
|
|
return {
|
|
controlKey: `capacity-${normalizedCapacity}`,
|
|
normalizedCapacity
|
|
};
|
|
};
|
|
|
|
export const resolveSubmitTransition = ({
|
|
representationType,
|
|
showQuestionnaireSection,
|
|
questionnaireCount
|
|
}) => {
|
|
if (representationType !== "Questionnaire") {
|
|
return "goToCheck";
|
|
}
|
|
|
|
if (
|
|
questionnaireCount !== 0 &&
|
|
showQuestionnaireSection < questionnaireCount
|
|
) {
|
|
return "advanceQuestionnaire";
|
|
}
|
|
|
|
return "goToCheck";
|
|
};
|
|
|
|
export const getQuestionnaireNextSection = (
|
|
currentSection,
|
|
questionnaireCount
|
|
) => {
|
|
if (questionnaireCount !== 0 && currentSection < questionnaireCount) {
|
|
return currentSection + 1;
|
|
}
|
|
|
|
return currentSection;
|
|
};
|
|
|
|
export const getQuestionnairePreviousSection = (currentSection) => {
|
|
return currentSection > 1 ? currentSection - 1 : currentSection;
|
|
};
|