Changed provider to type and hid field

This commit is contained in:
Lucas Oliveira 2024-03-26 21:50:44 +02:00
commit 5db74fbf5a

View file

@ -16,25 +16,25 @@ import { Textarea } from "../ui/textarea";
export default function AddNewVariableButton({ children }): JSX.Element { export default function AddNewVariableButton({ children }): JSX.Element {
const [key, setKey] = useState(""); const [key, setKey] = useState("");
const [value, setValue] = useState(""); const [value, setValue] = useState("");
const [provider, setProvider] = useState(""); const [type, setType] = useState("");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);
const addGlobalVariable = useGlobalVariablesStore( const addGlobalVariable = useGlobalVariablesStore(
(state) => state.addGlobalVariable (state) => state.addGlobalVariable
); );
function handleSaveVariable() { function handleSaveVariable() {
let data: { name: string; value: string; provider?: string } = { let data: { name: string; value: string; type?: string } = {
name: key, name: key,
value, value,
}; };
if (provider) data = { ...data, provider }; if (type) data = { ...data, type };
registerGlobalVariable(data) registerGlobalVariable(data)
.then((res) => { .then((res) => {
const { name, id, provider } = res.data; const { name, id, type } = res.data;
addGlobalVariable(name, id, provider); addGlobalVariable(name, id, type);
setKey(""); setKey("");
setValue(""); setValue("");
setProvider(""); setType("");
setOpen(false); setOpen(false);
}) })
.catch((error) => { .catch((error) => {
@ -62,7 +62,7 @@ export default function AddNewVariableButton({ children }): JSX.Element {
<BaseModal.Trigger>{children}</BaseModal.Trigger> <BaseModal.Trigger>{children}</BaseModal.Trigger>
<BaseModal.Content> <BaseModal.Content>
<div className="flex h-full w-full flex-col gap-4 align-middle"> <div className="flex h-full w-full flex-col gap-4 align-middle">
<Label>Variable name </Label> <Label>Variable Name</Label>
<Input <Input
value={key} value={key}
onChange={(e) => { onChange={(e) => {
@ -70,17 +70,17 @@ export default function AddNewVariableButton({ children }): JSX.Element {
}} }}
placeholder="Insert a name for the variable..." placeholder="Insert a name for the variable..."
></Input> ></Input>
<Label>Provider (optional) </Label> {/* <Label>Type (optional) </Label>
<InputComponent <InputComponent
setSelectedOption={(e) => { setSelectedOption={(e) => {
setProvider(e); setType(e);
}} }}
selectedOption={provider} selectedOption={type}
password={false} password={false}
options={["OPENAI_API_KEY", "ANTHROPIC_API_KEY"]} options={["OPENAI_API_KEY", "ANTHROPIC_API_KEY"]}
placeholder="Choose a provider between the environment variables..." placeholder="Choose a type between the environment variables..."
></InputComponent> ></InputComponent> */}
<Label>Variable Value </Label> <Label>Value</Label>
<Textarea <Textarea
value={value} value={value}
onChange={(e) => { onChange={(e) => {