From 46813e5c3f7be3d39e0fe07fbad96034e653a2c3 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Sun, 28 May 2023 20:37:07 -0300 Subject: [PATCH] Fixing modal trattative error when is Prompt/Text --- .../src/components/promptComponent/index.tsx | 3 + .../components/textAreaComponent/index.tsx | 3 + .../src/modals/genericModal/index.tsx | 68 +++++++++++-------- src/frontend/src/utils.ts | 5 ++ 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/frontend/src/components/promptComponent/index.tsx b/src/frontend/src/components/promptComponent/index.tsx index 10ac41281..f31c37f51 100644 --- a/src/frontend/src/components/promptComponent/index.tsx +++ b/src/frontend/src/components/promptComponent/index.tsx @@ -5,6 +5,7 @@ import CodeAreaModal from "../../modals/codeAreaModal"; import TextAreaModal from "../../modals/textAreaModal"; import { TextAreaComponentType } from "../../types/components"; import GenericModal from "../../modals/genericModal"; +import { TypeModal } from "../../utils"; export default function PromptAreaComponent({ value, @@ -30,6 +31,7 @@ export default function PromptAreaComponent({ onClick={() => { openPopUp( { openPopUp( { openPopUp( { openPopUp( void; value: string; buttonText: string; modalTitle: string; + type: number; }) { - const [myButtonText, setmyButtonText] = useState(buttonText); - const [myModalTitle, setMyModalTitle] = useState(modalTitle); + const [myButtonText] = useState(buttonText); + const [myModalTitle] = useState(modalTitle); + const [myModalType] = useState(type); const [open, setOpen] = useState(true); const [myValue, setMyValue] = useState(value); const { dark } = useContext(darkContext); @@ -114,36 +118,46 @@ export default function PromptAreaModal({ type="button" className="inline-flex w-full justify-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm" onClick={() => { - checkPrompt(myValue) - .then((apiReturn) => { - if (apiReturn.data) { - let inputVariables = - apiReturn.data.input_variables; - if (inputVariables.length === 0) { - setErrorData({ - title: - "The template you are attempting to use does not contain any variables for data entry.", - }); + switch (myModalType) { + case 1: + setModalOpen(false); + break; + case 2: + checkPrompt(myValue) + .then((apiReturn) => { + if (apiReturn.data) { + let inputVariables = + apiReturn.data.input_variables; + if (inputVariables.length === 0) { + setErrorData({ + title: + "The template you are attempting to use does not contain any variables for data entry.", + }); + } else { + setSuccessData({ + title: "Prompt is ready", + }); + setModalOpen(false); + setValue(myValue); + } } else { - setSuccessData({ - title: "Prompt is ready", + setErrorData({ + title: "Something went wrong, please try again", }); - setModalOpen(false); - setValue(myValue); } - } else { - setErrorData({ - title: "Something went wrong, please try again", + }) + .catch((error) => { + return setErrorData({ + title: + "There is something wrong with this prompt, please review it", + list: [error.response.data.detail], }); - } - }) - .catch((error) => { - return setErrorData({ - title: - "There is something wrong with this prompt, please review it", - list: [error.response.data.detail], }); - }); + break; + + default: + break; + } }} > {myButtonText} diff --git a/src/frontend/src/utils.ts b/src/frontend/src/utils.ts index d464290e1..c88fded26 100644 --- a/src/frontend/src/utils.ts +++ b/src/frontend/src/utils.ts @@ -25,6 +25,11 @@ export function classNames(...classes: Array) { return classes.filter(Boolean).join(" "); } +export enum TypeModal { + TEXT = 1, + PROMPT = 2 +} + export const textColors = { white: "text-white", red: "text-red-700",