Skip to content

Commit

Permalink
Fix for displayResult showing undefined.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjames111 committed Oct 23, 2024
1 parent a722e46 commit c4d6631
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react';
import { Autocomplete, Grid, TextField } from '@mui/material';
import { useTranslation } from 'react-i18next';
import {
Expand Down Expand Up @@ -29,13 +30,24 @@ export const ResultAutocomplete: React.FC<ResultAutocompleteProps> = ({
}) => {
const { t } = useTranslation();

useEffect(() => {
if (availableResults.length === 1) {
handleResultChange({
result: availableResults[0],
setFieldValue,
setResultSelected,
phaseData,
});
}
}, [availableResults]);

return !!availableResults.length ? (
<Grid item>
<Autocomplete
openOnFocus
autoHighlight
autoSelect
value={availableResults.length === 1 ? availableResults[0] : result}
value={result}
options={availableResults}
getOptionLabel={(result) => getLocalizedResultString(t, result)}
renderInput={(params) => <TextField {...params} label={t('Result')} />}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Task/Modal/Form/TaskModalHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const handleTaskPhaseChange = ({
setFieldValue('taskPhase', phase);
setFieldValue('activityType', '');
setFieldValue('subject', '');
setFieldValue('displayResult', undefined);
setFieldValue('displayResult', '');
setFieldValue('result', undefined);
setFieldValue('nextAction', undefined);
setResultSelected(null);
Expand Down

0 comments on commit c4d6631

Please sign in to comment.