Skip to content

Commit

Permalink
🐛 Add useEffect for action state sync
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Dec 7, 2023
1 parent cc14acb commit 521fe79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,21 @@ const DynamicAssessmentActionsRow: FunctionComponent<
onDeleteError
);

const determineAction = () => {
const determineAction = React.useCallback(() => {
if (!assessment) {
return AssessmentAction.Take;
} else if (assessment.status === "started") {
return AssessmentAction.Continue;
} else {
return AssessmentAction.Retake;
}
};
}, [assessment]);

const [action, setAction] = React.useState(determineAction());

React.useEffect(() => {
setAction(determineAction());
}, [determineAction, assessment]);

const determineButtonClassName = () => {
const action = determineAction();
Expand Down Expand Up @@ -213,7 +219,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
onHandleAssessmentAction();
}}
>
{determineAction()}
{action}
</Button>
) : (
<Spinner role="status" size="md">
Expand Down
1 change: 0 additions & 1 deletion client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export const useFetchAssessmentsByItemId = (
};
const assessmentsWithOrder: AssessmentWithSectionOrder[] =
data?.map(addSectionOrderToQuestions) || [];

return {
assessments: assessmentsWithOrder,
isFetching: isLoading,
Expand Down

0 comments on commit 521fe79

Please sign in to comment.