diff --git a/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx b/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx index c47806ab2..f170adc19 100644 --- a/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx +++ b/client/src/app/pages/assessment/components/assessment-wizard/assessment-wizard.tsx @@ -1,5 +1,5 @@ import * as yup from "yup"; -import React, { useEffect, useMemo, useState } from "react"; +import React, { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useHistory } from "react-router-dom"; import { FieldErrors, FormProvider, useForm } from "react-hook-form"; @@ -131,18 +131,6 @@ export const AssessmentWizard: React.FC = ({ return questions; }, [assessment]); - useEffect(() => { - console.log("asssessment.stakeholders", assessment?.stakeholders); - methods.reset({ - stakeholders: assessment?.stakeholders?.map((sh) => sh.name).sort() ?? [], - stakeholderGroups: - assessment?.stakeholderGroups?.map((sg) => sg.name).sort() ?? [], - // comments: initialComments, - questions: initialQuestions, - [SAVE_ACTION_KEY]: SAVE_ACTION_VALUE.SAVE_AS_DRAFT, - }); - }, [initialQuestions, assessment]); - const validationSchema = yup.object().shape({ stakeholders: yup.array().of(yup.string()), stakeholderGroups: yup.array().of(yup.string()), @@ -169,7 +157,6 @@ export const AssessmentWizard: React.FC = ({ const isValid = methods.formState.isValid; const isSubmitting = methods.formState.isSubmitting; const isValidating = methods.formState.isValidating; - const watchAllFields = methods.watch(); const disableNavigation = !isValid || isSubmitting; @@ -204,17 +191,32 @@ export const AssessmentWizard: React.FC = ({ // return value !== null && value !== undefined && value.length > 0; // }; - const shouldNextBtnBeEnabled = (section: Section): boolean => { - const allQuestionsValid = section?.questions.every((question) => - isQuestionValid(question) + const areAllQuestionsAnswered = (section: Section): boolean => { + return ( + section?.questions.every((question) => { + return questionHasValue(question); + }) ?? false ); - const allQuestionsAnswered = section?.questions.every((question) => { + }; + + const hasPartialAnswers = (section: Section): boolean => { + const someQuestionsAnswered = section?.questions.some((question) => { return questionHasValue(question); }); - return ( - allQuestionsAnswered && allQuestionsValid - // && isCommentValid(category) + + const allQuestionsAnswered = areAllQuestionsAnswered(section); + + return someQuestionsAnswered && !allQuestionsAnswered; + }; + + const shouldNextBtnBeEnabled = (section: Section): boolean => { + const allQuestionsValid = section?.questions.every((question) => + isQuestionValid(question) ); + + const allQuestionsAnswered = areAllQuestionsAnswered(section); + + return allQuestionsAnswered && allQuestionsValid; }; const maxCategoryWithData = [...sortedSections].reverse().find((section) => { @@ -541,6 +543,7 @@ export const AssessmentWizard: React.FC = ({ (currentStep === sortedSections.length && !shouldNextBtnBeEnabled(sortedSections[currentStep - 1])) } + hasAnswers={hasPartialAnswers(sortedSections[currentStep - 1])} isFormInvalid={!isValid} onSave={(review) => { const saveActionValue = review diff --git a/client/src/app/pages/assessment/components/custom-wizard-footer/custom-wizard-footer.tsx b/client/src/app/pages/assessment/components/custom-wizard-footer/custom-wizard-footer.tsx index 737e83f0c..069a7f5c9 100644 --- a/client/src/app/pages/assessment/components/custom-wizard-footer/custom-wizard-footer.tsx +++ b/client/src/app/pages/assessment/components/custom-wizard-footer/custom-wizard-footer.tsx @@ -13,6 +13,7 @@ export interface CustomWizardFooterProps { isDisabled: boolean; isFormInvalid: boolean; isArchetype?: boolean; + hasAnswers?: boolean; onSave: (review: boolean) => void; onSaveAsDraft: () => void; } @@ -23,6 +24,7 @@ export const CustomWizardFooter: React.FC = ({ isDisabled, isFormInvalid, isArchetype, + hasAnswers, onSave, onSaveAsDraft, }) => { @@ -84,7 +86,7 @@ export const CustomWizardFooter: React.FC = ({