Skip to content

Commit

Permalink
check assessments fetchError
Browse files Browse the repository at this point in the history
Signed-off-by: Gilles Dubreuil <[email protected]>
  • Loading branch information
gildub committed Sep 20, 2023
1 parent b8d7183 commit 5933009
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions client/src/app/pages/reports/reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ export const Reports: React.FC = () => {
const [selectedQuestionnaire, setSelectedQuestionnaire] =
React.useState<string>("All questionnaires");

const { assessments, isFetching: isAssessmentsFetching } =
useFetchAssessments();
const {
assessments,
isFetching: isAssessmentsFetching,
fetchError: assessmentsFetchError,
} = useFetchAssessments();

// Cards
const [isAdoptionCandidateTable, setIsAdoptionCandidateTable] =
Expand Down Expand Up @@ -83,7 +86,7 @@ export const Reports: React.FC = () => {
);
}

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
const toggleQuestionnaire = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
aria-label="kebab dropdown toggle"
Expand All @@ -104,14 +107,15 @@ export const Reports: React.FC = () => {
setIsQuestionnaireSelectOpen(false);
};

const questionnaires: Ref[] = isAssessmentsFetching
? []
: assessments.reduce((result: Ref[], item) => {
if (!result.some((ref) => ref.id === item.questionnaire.id)) {
result.push(item.questionnaire);
}
return result;
}, []);
const questionnaires: Ref[] =
isAssessmentsFetching || assessmentsFetchError
? []
: assessments.reduce((result: Ref[], item) => {
if (!result.some((ref) => ref.id === item.questionnaire.id)) {
result.push(item.questionnaire);
}
return result;
}, []);

return (
<>
Expand Down Expand Up @@ -142,7 +146,7 @@ export const Reports: React.FC = () => {
onOpenChange={(_isOpen) =>
setIsQuestionnaireSelectOpen(false)
}
toggle={toggle}
toggle={toggleQuestionnaire}
shouldFocusToggleOnSelect
>
<SelectOption key={0} value="All questionnaires">
Expand Down

0 comments on commit 5933009

Please sign in to comment.