Refactor addNewVariableButtonComponent and API registerGlobalVariable

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-21 14:01:05 -03:00
commit 69735b070f
2 changed files with 7 additions and 6 deletions

View file

@ -1,13 +1,13 @@
import { useState } from "react"; import { useState } from "react";
import { registerGlobalVariable } from "../../controllers/API";
import BaseModal from "../../modals/baseModal";
import { useGlobalVariablesStore } from "../../stores/globalVariables";
import ForwardedIconComponent from "../genericIconComponent"; import ForwardedIconComponent from "../genericIconComponent";
import InputComponent from "../inputComponent"; import InputComponent from "../inputComponent";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { Input } from "../ui/input"; import { Input } from "../ui/input";
import { Label } from "../ui/label"; import { Label } from "../ui/label";
import { Textarea } from "../ui/textarea"; import { Textarea } from "../ui/textarea";
import { registerGlobalVariable } from "../../controllers/API";
import BaseModal from "../../modals/baseModal";
import { useGlobalVariablesStore } from "../../stores/globalVariables";
//TODO IMPLEMENT FORM LOGIC //TODO IMPLEMENT FORM LOGIC
@ -25,8 +25,9 @@ export default function AddNewVariableButton({ children }): JSX.Element {
value, value,
}; };
if (provider) data = { ...data, provider }; if (provider) data = { ...data, provider };
registerGlobalVariable(data).then((_) => { registerGlobalVariable(data).then((res) => {
addGlobalVariable(key, value, provider); const { name, id, provider } = res.data;
addGlobalVariable(name, id, provider);
setKey(""); setKey("");
setValue(""); setValue("");
setProvider(""); setProvider("");

View file

@ -880,7 +880,7 @@ export async function registerGlobalVariable({
name: string; name: string;
value: string; value: string;
provider?: string; provider?: string;
}) { }): Promise<AxiosResponse<{ name: string; id: string; provider: string }>> {
return await api.post(`${BASE_URL_API}credentials/`, { return await api.post(`${BASE_URL_API}credentials/`, {
name, name,
value, value,