Refactor API functions and update global variables types
This commit is contained in:
parent
a91668b5f2
commit
b76eb655b2
2 changed files with 30 additions and 40 deletions
|
|
@ -851,47 +851,35 @@ export async function requestLogout() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGlobalVariables(): Promise<{ [key: string]: string }> {
|
export async function getGlobalVariables(): Promise<{
|
||||||
// mocked for now but will eventually be a real API call
|
[key: string]: { id: string; provider: string };
|
||||||
const globalVariables = window.sessionStorage.getItem("globalVariables");
|
}> {
|
||||||
return globalVariables ? JSON.parse(globalVariables) : {};
|
return (await api.get(`${BASE_URL_API}credentials/`)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registerGlobalVariable(name: string, value: string) {
|
export async function registerGlobalVariable(
|
||||||
// mocked for now but will eventually be a real API call
|
name: string,
|
||||||
const globalVariables = window.sessionStorage.getItem("globalVariables");
|
value: string,
|
||||||
const parsedGlobalVariables = globalVariables
|
provider?: string
|
||||||
? JSON.parse(globalVariables)
|
) {
|
||||||
: {};
|
return await api.post(`${BASE_URL_API}credentials/`, {
|
||||||
parsedGlobalVariables[name] = value;
|
name,
|
||||||
window.sessionStorage.setItem(
|
value,
|
||||||
"globalVariables",
|
provider,
|
||||||
JSON.stringify(parsedGlobalVariables)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteGlobalVariable(name: string) {
|
export async function deleteGlobalVariable(id: string) {
|
||||||
// mocked for now but will eventually be a real API call
|
api.delete(`${BASE_URL_API}credentials/${id}`);
|
||||||
const globalVariables = window.sessionStorage.getItem("globalVariables");
|
|
||||||
const parsedGlobalVariables = globalVariables
|
|
||||||
? JSON.parse(globalVariables)
|
|
||||||
: {};
|
|
||||||
delete parsedGlobalVariables[name];
|
|
||||||
window.sessionStorage.setItem(
|
|
||||||
"globalVariables",
|
|
||||||
JSON.stringify(parsedGlobalVariables)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateGlobalVariable(name: string, value: string) {
|
export async function updateGlobalVariable(
|
||||||
// mocked for now but will eventually be a real API call
|
name: string,
|
||||||
const globalVariables = window.sessionStorage.getItem("globalVariables");
|
value: string,
|
||||||
const parsedGlobalVariables = globalVariables
|
id: string
|
||||||
? JSON.parse(globalVariables)
|
) {
|
||||||
: {};
|
api.patch(`${BASE_URL_API}credentials/${id}`, {
|
||||||
parsedGlobalVariables[name] = value;
|
name,
|
||||||
window.sessionStorage.setItem(
|
value,
|
||||||
"globalVariables",
|
});
|
||||||
JSON.stringify(parsedGlobalVariables)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
export type GlobalVariablesStore = {
|
export type GlobalVariablesStore = {
|
||||||
globalVariablesEntries: Array<string>;
|
globalVariablesEntries: Array<string>;
|
||||||
globalVariables: { [key: string]: string };
|
globalVariables: { [key: string]: { id: string; provider: string } };
|
||||||
setGlobalVariables: (variables: { [key: string]: string }) => void;
|
setGlobalVariables: (variables: {
|
||||||
addGlobalVariable: (key: string, value: string) => void;
|
[key: string]: { id: string; provider: string };
|
||||||
|
}) => void;
|
||||||
|
addGlobalVariable: (key: string, value: string, provider?: string) => void;
|
||||||
removeGlobalVariable: (key: string) => void;
|
removeGlobalVariable: (key: string) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue