Skip to content

Commit

Permalink
Merge branch 'main' into fix/j1315-existing-autocomplete-tags-not-sho…
Browse files Browse the repository at this point in the history
…wing
  • Loading branch information
gitdallas authored Sep 26, 2023
2 parents 7c2fa1b + 9cf7840 commit 40bd22a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -131,18 +131,6 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
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()),
Expand All @@ -169,7 +157,6 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
const isValid = methods.formState.isValid;
const isSubmitting = methods.formState.isSubmitting;
const isValidating = methods.formState.isValidating;

const watchAllFields = methods.watch();

const disableNavigation = !isValid || isSubmitting;
Expand Down Expand Up @@ -204,17 +191,32 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
// 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) => {
Expand Down Expand Up @@ -541,6 +543,7 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
(currentStep === sortedSections.length &&
!shouldNextBtnBeEnabled(sortedSections[currentStep - 1]))
}
hasAnswers={hasPartialAnswers(sortedSections[currentStep - 1])}
isFormInvalid={!isValid}
onSave={(review) => {
const saveActionValue = review
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CustomWizardFooterProps {
isDisabled: boolean;
isFormInvalid: boolean;
isArchetype?: boolean;
hasAnswers?: boolean;
onSave: (review: boolean) => void;
onSaveAsDraft: () => void;
}
Expand All @@ -23,6 +24,7 @@ export const CustomWizardFooter: React.FC<CustomWizardFooterProps> = ({
isDisabled,
isFormInvalid,
isArchetype,
hasAnswers,
onSave,
onSaveAsDraft,
}) => {
Expand Down Expand Up @@ -84,7 +86,7 @@ export const CustomWizardFooter: React.FC<CustomWizardFooterProps> = ({
<Button
variant="link"
onClick={onSaveAsDraft}
isDisabled={isFormInvalid}
isDisabled={isFormInvalid || isFirstStep || !hasAnswers}
cy-data="save-as-draft"
>
{t("actions.saveAsDraft")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe("AppPlaceholder", () => {
isLastStep={false}
isDisabled={false}
isFormInvalid={false}
hasAnswers={true}
onSave={jest.fn()}
onSaveAsDraft={onSaveAsDraftSpy}
/>
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ export const useDeleteAssessmentMutation = (
};

export const useFetchAssessmentById = (id?: number | string) => {
const { data, isLoading, error } = useQuery({
const { data, isLoading, error, isFetching } = useQuery({
queryKey: [assessmentQueryKey, id],
queryFn: () => (id ? getAssessmentById(id) : undefined),
onError: (error: AxiosError) => console.log("error, ", error),
enabled: !!id,
});
return {
assessment: data,
isFetching: isLoading,
isFetching: isLoading || isFetching,
fetchError: error,
};
};
Expand Down

0 comments on commit 40bd22a

Please sign in to comment.