diff --git a/src/frontend/src/modals/StoreApiKeyModal/index.tsx b/src/frontend/src/modals/StoreApiKeyModal/index.tsx index fc98a011f..beb887095 100644 --- a/src/frontend/src/modals/StoreApiKeyModal/index.tsx +++ b/src/frontend/src/modals/StoreApiKeyModal/index.tsx @@ -5,6 +5,7 @@ import { Button } from "../../components/ui/button"; import { Input } from "../../components/ui/input"; import { CONTROL_NEW_API_KEY } from "../../constants/constants"; import { alertContext } from "../../contexts/alertContext"; +import { addApiKeyStore } from "../../controllers/API"; import { ApiKeyInputType, StoreApiKeyType, @@ -20,7 +21,7 @@ export default function StoreApiKeyModal({ const [apiKeyValue, setApiKeyValue] = useState(""); const [inputState, setInputState] = useState(CONTROL_NEW_API_KEY); - const { setSuccessData } = useContext(alertContext); + const { setSuccessData, setErrorData } = useContext(alertContext); const inputRef = useRef(null); function handleInput({ @@ -41,6 +42,24 @@ export default function StoreApiKeyModal({ setApiKeyValue(""); } + const handleSaveKey = () => { + if (inputState && inputState["apikey"]) { + addApiKeyStore(inputState["apikey"]).then( + () => { + setSuccessData({ + title: "Success! Your API Key has been saved.", + }); + }, + (error) => { + setErrorData({ + title: "There was an error saving the API Key, please try again.", + list: [error["response"]["data"]["detail"]], + }); + } + ); + } + }; + return ( {children} @@ -93,7 +112,14 @@ export default function StoreApiKeyModal({ - +