Added fields to request for creating new variable

This commit is contained in:
Lucas Oliveira 2024-04-30 16:49:26 +02:00
commit e773227e4a
3 changed files with 8 additions and 7 deletions

View file

@ -26,15 +26,16 @@ export default function AddNewVariableButton({ children }): JSX.Element {
(state) => state.addGlobalVariable
);
function handleSaveVariable() {
let data: { name: string; value: string; type?: string } = {
let data: { name: string; value: string; type?: string; default_fields?: string[] } = {
name: key,
type,
value,
default_fields: fields
};
registerGlobalVariable(data)
.then((res) => {
const { name, id, type } = res.data;
addGlobalVariable(name, id, type);
addGlobalVariable(name, id, type, fields);
setKey("");
setValue("");
setType("");

View file

@ -21,8 +21,8 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
globalVariablesEntries: Object.keys(variables),
});
},
addGlobalVariable: (name, id, type) => {
const data = { id, type };
addGlobalVariable: (name, id, type, default_fields) => {
const data = { id, type, default_fields };
const newVariables = { ...get().globalVariables, [name]: data };
set({
globalVariables: newVariables,

View file

@ -1,10 +1,10 @@
export type GlobalVariablesStore = {
globalVariablesEntries: Array<string>;
globalVariables: { [name: string]: { id: string; type?: string } };
globalVariables: { [name: string]: { id: string; type?: string, default_fields?: string[] } };
setGlobalVariables: (variables: {
[name: string]: { id: string; type?: string };
[name: string]: { id: string; type?: string, default_fields?: string[]};
}) => void;
addGlobalVariable: (name: string, id: string, type?: string) => void;
addGlobalVariable: (name: string, id: string, type?: string, default_fields?: string[]) => void;
removeGlobalVariable: (name: string) => void;
getVariableId: (name: string) => string | undefined;
unavaliableFields: Set<string>;