🐛 fix(codeAreaModal/index.tsx): update condition in useEffect to check if nodeClass.template has more than 2 fields instead of 1

✨ feat(codeAreaModal/index.tsx): refactor handleClick function to call processCode function instead of directly calling postValidateCode function
✨ feat(codeAreaModal/index.tsx): add support for processing non-dynamic fields by calling postValidateCode function and updating success and error data accordingly
✨ feat(codeAreaModal/index.tsx): add support for processing dynamic fields by calling postCustomComponent function and updating nodeClass and error data accordingly
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-18 15:39:43 -03:00
commit 5d4aae9ba3

View file

@ -41,14 +41,13 @@ export default function CodeAreaModal({
useEffect(() => {
// if nodeClass.template has more fields other than code and dynamic is true
// do not run handleClick
if (dynamic && Object.keys(nodeClass.template).length > 1) {
if (dynamic && Object.keys(nodeClass.template).length > 2) {
return;
}
handleClick();
processCode();
}, []);
function handleClick() {
if (!dynamic) {
function processNonDynamicField() {
postValidateCode(code)
.then((apiReturn) => {
if (apiReturn.data) {
@ -84,7 +83,9 @@ export default function CodeAreaModal({
title: "There is something wrong with this code, please review it",
});
});
} else {
}
function processDynamicField() {
postCustomComponent(code, nodeClass)
.then((apiReturn) => {
const { data } = apiReturn;
@ -97,6 +98,17 @@ export default function CodeAreaModal({
setError(err.response.data);
});
}
function processCode() {
if (!dynamic) {
processNonDynamicField();
} else {
processDynamicField();
}
}
function handleClick() {
processCode();
}
useEffect(() => {