Skip to content

Commit 34f6614

Browse files
authored
Merge pull request #1219 from topcoder-platform/PM-1504_edit-create-scorecard
fix scoorecard data fetch
2 parents 4422d9b + 869b21c commit 34f6614

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/apps/review/src/lib/hooks/useFetchScorecard.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { toast } from 'react-toastify'
22
import { sortBy } from 'lodash'
3+
import { useMemo } from 'react'
34
import useSWR, { SWRResponse } from 'swr'
45

56
import { EnvironmentConfig } from '~/config'
@@ -36,10 +37,8 @@ export function useFetchScorecard(id: string | undefined, shouldRetry: boolean):
3637
},
3738
)
3839

39-
return {
40-
error,
41-
isValidating,
42-
scorecard: data ? {
40+
const scorecard = useMemo(() => (
41+
data ? {
4342
...data,
4443
scorecardGroups: sortBy(data.scorecardGroups.map(group => ({
4544
...group,
@@ -48,6 +47,12 @@ export function useFetchScorecard(id: string | undefined, shouldRetry: boolean):
4847
questions: sortBy(section.questions, 'sortOrder'),
4948
})), 'sortOrder'),
5049
})), 'sortOrder'),
51-
} : data,
50+
} : data
51+
), [data])
52+
53+
return {
54+
error,
55+
isValidating,
56+
scorecard,
5257
}
5358
}

src/apps/review/src/pages/scorecards/EditScorecardPage/components/ScorecardQuestionForm.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ const ScorecardQuestionForm: FC<ScorecardQuestionFormProps> = props => {
9393
) => {
9494
const [, type, min, max] = ev.target.value.match(/^([A-Za-z0-9_]+)(?:\((\d+)-(\d+)\))?$/) ?? []
9595

96-
form.setValue(field.name, type.toUpperCase(), { shouldValidate: true })
97-
form.setValue(field.name.replace(/\.type$/, '.scaleMin'), Number(min) || 0, { shouldValidate: true })
98-
form.setValue(field.name.replace(/\.type$/, '.scaleMax'), Number(max) || 0, { shouldValidate: true })
96+
const options = { shouldDirty: true, shouldTouch: true, shouldValidate: true }
97+
form.setValue(field.name, type.toUpperCase(), options)
98+
form.setValue(field.name.replace(/\.type$/, '.scaleMin'), Number(min) || 0, options)
99+
form.setValue(field.name.replace(/\.type$/, '.scaleMax'), Number(max) || 0, options)
99100
}, [form])
100101

101102
return (

0 commit comments

Comments
 (0)