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
This commit is contained in:
anovazzi1 2023-11-13 19:33:06 -03:00
commit fec102b6e7
2 changed files with 7 additions and 3 deletions

View file

@ -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);

View file

@ -20,13 +20,15 @@ export default function StoreApiKeyModal({
onCloseModal,
}: StoreApiKeyType) {
const [open, setOpen] = useState(false);
const [apiKeyValue, setApiKeyValue] = useState("");
const [inputState, setInputState] =
useState<ApiKeyInputType>(CONTROL_NEW_API_KEY);
const { setSuccessData, setErrorData } = useContext(alertContext);
const inputRef = useRef<HTMLInputElement | null>(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({
<Form.Control asChild>
<Input
//fake api key
value={hasApiKey ? "this is not a real api key :)" : ""}
value={apiKeyValue}
type="password"
onChange={({ target: { value } }) => {
handleInput({ target: { name: "apikey", value } });
setApiKeyValue(value);
}}
placeholder="Insert your API Key"
/>