Skip to content

Commit 747c2bc

Browse files
chore: clean up ValidationResult for NumericalInput problems (#2849)
1 parent 27e7099 commit 747c2bc

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/AnswerOption.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const AnswerOption = ({
7373

7474
if (problemType !== ProblemTypeKeys.NUMERIC || !answer.isAnswerRange) {
7575
return (
76-
<Form.Group isInvalid={!data?.isValid ?? true}>
76+
<Form.Group isInvalid={!data?.isValid}>
7777
<Form.Control
7878
as="textarea"
7979
className="answer-option-textarea text-gray-500 small"
@@ -89,7 +89,7 @@ const AnswerOption = ({
8989
placeholder={intl.formatMessage(messages.answerTextboxPlaceholder)}
9090

9191
/>
92-
{(!data?.isValid ?? true) && (
92+
{(!data?.isValid) && (
9393
<Form.Control.Feedback type="invalid">
9494
<FormattedMessage {...messages.answerNumericErrorText} />
9595
</Form.Control.Feedback>

src/editors/containers/ProblemEditor/data/apiHooks.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ import api from '@src/editors/data/services/cms/api';
44

55
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL;
66

7+
interface ValidationResult {
8+
isValid: boolean;
9+
error?: string;
10+
preview?: string;
11+
}
12+
713
export const useValidateInputBlock = () => useMutation({
8-
mutationFn: async (title : string) => {
14+
mutationFn: async (title : string): Promise<ValidationResult> => {
915
try {
1016
const res = await api.validateBlockNumericInput({ studioEndpointUrl: `${getApiBaseUrl()}`, data: { formula: title } });
1117
return camelCaseObject(res.data);

0 commit comments

Comments
 (0)