diff --git a/src/components/ApiMenu/ApiMenu.tsx b/src/components/ApiMenu/ApiMenu.tsx index c5e3f17..1c23720 100644 --- a/src/components/ApiMenu/ApiMenu.tsx +++ b/src/components/ApiMenu/ApiMenu.tsx @@ -16,17 +16,19 @@ const ApiMenu = ({ const apiFree = useStore((state) => state.apiFree); const setApiFree = useStore((state) => state.setApiFree); + const [_apiFree, _setApiFree] = useState(apiFree); const [_apiKey, _setApiKey] = useState(apiKey || ''); const [error, setError] = useState(false); const handleSave = async () => { - if (apiFree === true) { + if (_apiFree === true) { + setApiFree(true); setIsModalOpen(false); } else { const valid = await validateApiKey(_apiKey); - if (valid) { setApiKey(_apiKey); + setApiFree(false); setError(false); setIsModalOpen(false); } else { @@ -40,9 +42,10 @@ const ApiMenu = ({ useEffect(() => { if (apiKey) { - setApiFree(false); - _setApiKey(apiKey); - } + setApiFree(false); + _setApiFree(false); + _setApiKey(apiKey); + } }, []); return isModalOpen ? ( @@ -55,9 +58,9 @@ const ApiMenu = ({
setApiFree(true)} + onChange={() => _setApiFree(true)} />
-
setApiFree(false)} + onChange={() => _setApiFree(false)} />
- {apiFree === false && ( + {_apiFree === false && ( <>
@@ -91,7 +93,7 @@ const ApiMenu = ({
{ _setApiKey(e.target.value); @@ -100,7 +102,8 @@ const ApiMenu = ({
{error && (
- Error: Invalid API key or network blocked. Please check your API key and network settings for OpenAI API. + Error: Invalid API key or network blocked. Please check your API + key and network settings for OpenAI API.
)}