Refactor registerGlobalVariable function signature

This commit is contained in:
anovazzi1 2024-02-08 15:36:18 -03:00
commit c724d1131a
2 changed files with 15 additions and 6 deletions

View file

@ -864,11 +864,15 @@ export async function getGlobalVariables(): Promise<{
return globalVariables;
}
export async function registerGlobalVariable(
name: string,
value: string,
provider?: string
) {
export async function registerGlobalVariable({
name,
value,
provider,
}: {
name: string;
value: string;
provider?: string;
}) {
return await api.post(`${BASE_URL_API}credentials/`, {
name,
value,

View file

@ -19,7 +19,12 @@ export default function AddNewVariableButton(): JSX.Element {
(state) => state.addGlobalVariable
);
function handleSaveVariable() {
registerGlobalVariable(key, value, provider).then((_) => {
let data: { name: string; value: string; provider?: string } = {
name: key,
value,
};
if (provider) data = { ...data, provider };
registerGlobalVariable(data).then((_) => {
addGlobalVariable(key, value, provider);
setKey("");
setValue("");