Skip to content

Commit 7ad1f7e

Browse files
feat: returning data in camelcase, improve UI in validation
1 parent f9ce381 commit 7ad1f7e

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Icon,
77
IconButton,
88
Form,
9-
Spinner,
109
} from '@openedx/paragon';
1110
import { FeedbackOutline, DeleteOutline } from '@openedx/paragon/icons';
1211
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
@@ -45,7 +44,7 @@ const AnswerOption = ({
4544
const setSelectedFeedback = hooks.setSelectedFeedback({ answer, hasSingleAnswer, dispatch });
4645
const setUnselectedFeedback = hooks.setUnselectedFeedback({ answer, hasSingleAnswer, dispatch });
4746
const { isFeedbackVisible, toggleFeedback } = hooks.useFeedback(answer);
48-
const { data = { is_valid: true }, mutate, isPending } = useValidateInputBlock();
47+
const { data = { isValid: true }, mutate } = useValidateInputBlock();
4948

5049
const staticRootUrl = isLibrary
5150
? `${getConfig().STUDIO_BASE_URL}/library_assets/blocks/${blockId}/`
@@ -71,9 +70,10 @@ const AnswerOption = ({
7170
/>
7271
);
7372
}
73+
7474
if (problemType !== ProblemTypeKeys.NUMERIC || !answer.isAnswerRange) {
7575
return (
76-
<Form.Group isInvalid={!data?.is_valid ?? true}>
76+
<Form.Group isInvalid={!data?.isValid ?? true}>
7777
<Form.Control
7878
as="textarea"
7979
className="answer-option-textarea text-gray-500 small"
@@ -82,19 +82,18 @@ const AnswerOption = ({
8282
value={answer.title}
8383
onChange={(e) => {
8484
setAnswerTitle(e);
85-
mutate(e.target.value);
85+
if (problemType === ProblemTypeKeys.NUMERIC) {
86+
mutate(e.target.value);
87+
}
8688
}}
8789
placeholder={intl.formatMessage(messages.answerTextboxPlaceholder)}
8890

8991
/>
90-
{(!data?.is_valid ?? true) && (
92+
{(!data?.isValid ?? true) && (
9193
<Form.Control.Feedback type="invalid">
9294
<FormattedMessage {...messages.answerNumericErrorText} />
9395
</Form.Control.Feedback>
9496
)}
95-
{isPending && (
96-
<Spinner animation="border" className="mie-3 mt-3" screenReaderText="loading" />
97-
)}
9897
</Form.Group>
9998
);
10099
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMutation } from '@tanstack/react-query';
2-
import { getConfig } from '@edx/frontend-platform';
2+
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
33
import api from '@src/editors/data/services/cms/api';
44

55
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL;
@@ -8,10 +8,10 @@ export const useValidateInputBlock = () => useMutation({
88
mutationFn: async (title) => {
99
try {
1010
const res = await api.validateBlockNumericInput({ studioEndpointUrl: `${getApiBaseUrl()}`, data: { formula: title } });
11-
return res.data;
11+
return camelCaseObject(res.data);
1212
} catch (err: any) {
1313
return {
14-
is_valid: false,
14+
isValid: false,
1515
error: err.response?.data?.error ?? 'Unknown error',
1616
};
1717
}

0 commit comments

Comments
 (0)