Skip to content

Commit

Permalink
wire up create assessment on confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Sep 18, 2023
1 parent 39f625f commit 0d05aa1
Showing 1 changed file with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,8 @@ const DynamicAssessmentActionsRow: FunctionComponent<
return "retake-button";
}
};
const createAssessment = async () => {
if (!isArchetype && application?.archetypes?.length) {
for (const archetypeRef of application.archetypes) {
try {
const assessments = await getAssessmentsByItemId(
true,
archetypeRef.id
);

if (assessments && assessments.length > 0) {
setArchetypeRefToOverride(archetypeRef);
return;
}
} catch (error) {
console.error(
`Error fetching archetype with ID ${archetypeRef.id}:`,
error
);
pushNotification({
title: t("terms.error"),
variant: "danger",
});
}
}
}

const createAssessment = async () => {
const newAssessment: InitialAssessment = {
questionnaire: { name: questionnaire.name, id: questionnaire.id },
...(isArchetype
Expand Down Expand Up @@ -166,11 +142,41 @@ const DynamicAssessmentActionsRow: FunctionComponent<
});
}
};

const takeAssessment = async () => {
if (!isArchetype && application?.archetypes?.length) {
for (const archetypeRef of application.archetypes) {
try {
const assessments = await getAssessmentsByItemId(
true,
archetypeRef.id
);

if (assessments && assessments.length > 0) {
setArchetypeRefToOverride(archetypeRef);
return;
}
} catch (error) {
console.error(
`Error fetching archetype with ID ${archetypeRef.id}:`,
error
);
pushNotification({
title: t("terms.error"),
variant: "danger",
});
}
}
} else {
createAssessment();
}
};

const onHandleAssessmentAction = async () => {
const action = determineAction();

if (action === AssessmentAction.Take) {
createAssessment();
takeAssessment();
} else if (action === AssessmentAction.Continue) {
history.push(
formatPath(
Expand Down Expand Up @@ -288,6 +294,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
})
);
setArchetypeRefToOverride(null);
createAssessment();
}}
/>
</>
Expand Down

0 comments on commit 0d05aa1

Please sign in to comment.