diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index 8139209f7..4b725afa6 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -50,7 +50,7 @@ export default function CodeAreaModal({ const { setErrorData, setSuccessData } = useContext(alertContext); const { closePopUp } = useContext(PopUpContext); const [activeTab, setActiveTab] = useState("0"); - const [error, setError] = useState<{detail:string,traceback:string}>(null) + const [error, setError] = useState<{ detail: { error: string, traceback: string } }>(null) const ref = useRef(); function setModalOpen(x: boolean) { setOpen(x); @@ -64,54 +64,56 @@ export default function CodeAreaModal({ function handleClick() { setLoading(true); - if(!dynamic){ + if (!dynamic) { postValidateCode(code) - .then((apiReturn) => { - setLoading(false); - if (apiReturn.data) { - let importsErrors = apiReturn.data.imports.errors; - let funcErrors = apiReturn.data.function.errors; - if (funcErrors.length === 0 && importsErrors.length === 0) { - setSuccessData({ - title: "Code is ready to run", - }); - // setValue(code); + .then((apiReturn) => { + setLoading(false); + if (apiReturn.data) { + let importsErrors = apiReturn.data.imports.errors; + let funcErrors = apiReturn.data.function.errors; + if (funcErrors.length === 0 && importsErrors.length === 0) { + setSuccessData({ + title: "Code is ready to run", + }); + // setValue(code); + } else { + if (funcErrors.length !== 0) { + setErrorData({ + title: "There is an error in your function", + list: funcErrors, + }); + } + if (importsErrors.length !== 0) { + setErrorData({ + title: "There is an error in your imports", + list: importsErrors, + }); + } + } } else { - if (funcErrors.length !== 0) { - setErrorData({ - title: "There is an error in your function", - list: funcErrors, - }); - } - if (importsErrors.length !== 0) { - setErrorData({ - title: "There is an error in your imports", - list: importsErrors, - }); - } + setErrorData({ + title: "Something went wrong, please try again", + }); } - } else { + }) + .catch((_) => { + setLoading(false); setErrorData({ - title: "Something went wrong, please try again", + title: "There is something wrong with this code, please review it", }); - } - }) - .catch((_) => { - setLoading(false); - setErrorData({ - title: "There is something wrong with this code, please review it", }); - }); } - else - { + else { postCustomComponent(code, nodeClass).then((apiReturn) => { - const {data} = apiReturn; + const { data } = apiReturn; if (data) { setNodeClass(data); setModalOpen(false); } }).catch((err) => { + setErrorData({ + title: "There is something wrong with this code, please see the error on the errors tab", + }); console.log(err.response.data); setError(err.response.data); }); @@ -145,7 +147,8 @@ export default function CodeAreaModal({