From 69735b070faa52aa9fcf758c2110c4cdcff8e026 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 21 Mar 2024 14:01:05 -0300 Subject: [PATCH] Refactor addNewVariableButtonComponent and API registerGlobalVariable --- .../addNewVariableButton.tsx | 11 ++++++----- src/frontend/src/controllers/API/index.ts | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/components/addNewVariableButtonComponent/addNewVariableButton.tsx b/src/frontend/src/components/addNewVariableButtonComponent/addNewVariableButton.tsx index 84e7d1c7a..2173903bd 100644 --- a/src/frontend/src/components/addNewVariableButtonComponent/addNewVariableButton.tsx +++ b/src/frontend/src/components/addNewVariableButtonComponent/addNewVariableButton.tsx @@ -1,13 +1,13 @@ import { useState } from "react"; +import { registerGlobalVariable } from "../../controllers/API"; +import BaseModal from "../../modals/baseModal"; +import { useGlobalVariablesStore } from "../../stores/globalVariables"; import ForwardedIconComponent from "../genericIconComponent"; import InputComponent from "../inputComponent"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; import { Textarea } from "../ui/textarea"; -import { registerGlobalVariable } from "../../controllers/API"; -import BaseModal from "../../modals/baseModal"; -import { useGlobalVariablesStore } from "../../stores/globalVariables"; //TODO IMPLEMENT FORM LOGIC @@ -25,8 +25,9 @@ export default function AddNewVariableButton({ children }): JSX.Element { value, }; if (provider) data = { ...data, provider }; - registerGlobalVariable(data).then((_) => { - addGlobalVariable(key, value, provider); + registerGlobalVariable(data).then((res) => { + const { name, id, provider } = res.data; + addGlobalVariable(name, id, provider); setKey(""); setValue(""); setProvider(""); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 0a987272b..93931f086 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -880,7 +880,7 @@ export async function registerGlobalVariable({ name: string; value: string; provider?: string; -}) { +}): Promise> { return await api.post(`${BASE_URL_API}credentials/`, { name, value,