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 validApiKey = useStoreStore((state) => state.validApiKey);
|
||||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
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 = () => {
|
const handleSaveKey = () => {
|
||||||
if (apiKeyValue) {
|
if (apiKeyValue) {
|
||||||
|
|
@ -32,12 +35,18 @@ export default function StoreApiKeyModal({
|
||||||
});
|
});
|
||||||
storeApiKey(apiKeyValue);
|
storeApiKey(apiKeyValue);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
setHasApiKey(true);
|
||||||
|
setValidApiKey(true);
|
||||||
|
setLoadingApiKey(false);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "There was an error saving the API Key, please try again.",
|
title: "There was an error saving the API Key, please try again.",
|
||||||
list: [error["response"]["data"]["detail"]],
|
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 {
|
export default function StorePage(): JSX.Element {
|
||||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||||
const validApiKey = useStoreStore((state) => state.validApiKey);
|
const validApiKey = useStoreStore((state) => state.validApiKey);
|
||||||
const setValidApiKey = useStoreStore((state) => state.updateValidApiKey);
|
|
||||||
const loadingApiKey = useStoreStore((state) => state.loadingApiKey);
|
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 { apiKey } = useContext(AuthContext);
|
||||||
|
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData } = useContext(alertContext);
|
||||||
const { setTabId } = useContext(FlowsContext);
|
const { setTabId } = useContext(FlowsContext);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
@ -171,17 +175,14 @@ export default function StorePage(): JSX.Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchApiData = async () => {
|
const fetchApiData = async () => {
|
||||||
useStoreStore.setState({ loadingApiKey: true });
|
setLoadingApiKey(true);
|
||||||
try {
|
try {
|
||||||
const res = await checkHasApiKey();
|
const res = await checkHasApiKey();
|
||||||
|
setHasApiKey(res?.has_api_key ?? false);
|
||||||
useStoreStore.setState({
|
setValidApiKey(res?.is_valid ?? false);
|
||||||
loadingApiKey: false,
|
setLoadingApiKey(false);
|
||||||
validApiKey: res?.is_valid ?? false,
|
|
||||||
hasApiKey: res?.has_api_key ?? false,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
useStoreStore.setState({ loadingApiKey: false });
|
setLoadingApiKey(false);
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue