From 0d05aa18daf62b86cffafc0d0700ced1c56b6053 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Mon, 18 Sep 2023 12:32:23 -0400 Subject: [PATCH] wire up create assessment on confirm --- .../dynamic-assessment-actions-row.tsx | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx b/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx index 572dfda2f5..d8713c4a52 100644 --- a/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx +++ b/client/src/app/pages/assessment/components/assessment-actions/components/dynamic-assessment-actions-row.tsx @@ -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 @@ -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( @@ -288,6 +294,7 @@ const DynamicAssessmentActionsRow: FunctionComponent< }) ); setArchetypeRefToOverride(null); + createAssessment(); }} />