From fec102b6e7ef1f030badd05d8a0b8cd78de34445 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 13 Nov 2023 19:33:06 -0300 Subject: [PATCH] fix(storeContext.tsx): add console.log statement to log the response from checkHasApiKey() function fix(StoreApiKeyModal/index.tsx): initialize apiKeyValue state with a fake API key if hasApiKey is true --- src/frontend/src/contexts/storeContext.tsx | 1 + src/frontend/src/modals/StoreApiKeyModal/index.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/contexts/storeContext.tsx b/src/frontend/src/contexts/storeContext.tsx index 58e66450e..e8d3e4b64 100644 --- a/src/frontend/src/contexts/storeContext.tsx +++ b/src/frontend/src/contexts/storeContext.tsx @@ -75,6 +75,7 @@ export function StoreProvider({ children }) { try { if (storeChecked) return; const res = await checkHasApiKey(); + console.log(res); setHasApiKey(res?.has_api_key ?? false); } catch (e) { console.log(e); diff --git a/src/frontend/src/modals/StoreApiKeyModal/index.tsx b/src/frontend/src/modals/StoreApiKeyModal/index.tsx index 915d6e310..42b4db08e 100644 --- a/src/frontend/src/modals/StoreApiKeyModal/index.tsx +++ b/src/frontend/src/modals/StoreApiKeyModal/index.tsx @@ -20,13 +20,15 @@ export default function StoreApiKeyModal({ onCloseModal, }: StoreApiKeyType) { const [open, setOpen] = useState(false); - const [apiKeyValue, setApiKeyValue] = useState(""); const [inputState, setInputState] = useState(CONTROL_NEW_API_KEY); const { setSuccessData, setErrorData } = useContext(alertContext); const inputRef = useRef(null); const { storeApiKey } = useContext(AuthContext); const { hasApiKey } = useContext(StoreContext); + const [apiKeyValue, setApiKeyValue] = useState( + hasApiKey ? "this is not a real api key :)" : "" + ); function handleInput({ target: { name, value }, @@ -36,7 +38,7 @@ export default function StoreApiKeyModal({ useEffect(() => { if (open) { - resetForm(); + // resetForm(); } else { onCloseModal(); } @@ -89,10 +91,11 @@ export default function StoreApiKeyModal({ { handleInput({ target: { name: "apikey", value } }); + setApiKeyValue(value); }} placeholder="Insert your API Key" />