fix(modals): update state variables after saving API key to reflect the correct values
fix(pages): update state variables after fetching API data to reflect the correct values
This commit is contained in:
parent
c032a9c003
commit
1284329c16
2 changed files with 19 additions and 9 deletions
|
|
@ -22,6 +22,9 @@ export default function StoreApiKeyModal({
|
|||
|
||||
const validApiKey = useStoreStore((state) => state.validApiKey);
|
||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||
const setHasApiKey = useStoreStore((state) => state.updateHasApiKey);
|
||||
const setValidApiKey = useStoreStore((state) => state.updateValidApiKey);
|
||||
const setLoadingApiKey = useStoreStore((state) => state.updateLoadingApiKey);
|
||||
|
||||
const handleSaveKey = () => {
|
||||
if (apiKeyValue) {
|
||||
|
|
@ -32,12 +35,18 @@ export default function StoreApiKeyModal({
|
|||
});
|
||||
storeApiKey(apiKeyValue);
|
||||
setOpen(false);
|
||||
setHasApiKey(true);
|
||||
setValidApiKey(true);
|
||||
setLoadingApiKey(false);
|
||||
},
|
||||
(error) => {
|
||||
setErrorData({
|
||||
title: "There was an error saving the API Key, please try again.",
|
||||
list: [error["response"]["data"]["detail"]],
|
||||
});
|
||||
setHasApiKey(false);
|
||||
setValidApiKey(false);
|
||||
setLoadingApiKey(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,14 @@ import { cn } from "../../utils/utils";
|
|||
export default function StorePage(): JSX.Element {
|
||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||
const validApiKey = useStoreStore((state) => state.validApiKey);
|
||||
const setValidApiKey = useStoreStore((state) => state.updateValidApiKey);
|
||||
const loadingApiKey = useStoreStore((state) => state.loadingApiKey);
|
||||
|
||||
const setValidApiKey = useStoreStore((state) => state.updateValidApiKey);
|
||||
const setLoadingApiKey = useStoreStore((state) => state.updateLoadingApiKey);
|
||||
const setHasApiKey = useStoreStore((state) => state.updateHasApiKey);
|
||||
|
||||
const { apiKey } = useContext(AuthContext);
|
||||
|
||||
const { setErrorData } = useContext(alertContext);
|
||||
const { setTabId } = useContext(FlowsContext);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
|
@ -171,17 +175,14 @@ export default function StorePage(): JSX.Element {
|
|||
}
|
||||
|
||||
const fetchApiData = async () => {
|
||||
useStoreStore.setState({ loadingApiKey: true });
|
||||
setLoadingApiKey(true);
|
||||
try {
|
||||
const res = await checkHasApiKey();
|
||||
|
||||
useStoreStore.setState({
|
||||
loadingApiKey: false,
|
||||
validApiKey: res?.is_valid ?? false,
|
||||
hasApiKey: res?.has_api_key ?? false,
|
||||
});
|
||||
setHasApiKey(res?.has_api_key ?? false);
|
||||
setValidApiKey(res?.is_valid ?? false);
|
||||
setLoadingApiKey(false);
|
||||
} catch (e) {
|
||||
useStoreStore.setState({ loadingApiKey: false });
|
||||
setLoadingApiKey(false);
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue