Update storeContext and API controller
This commit is contained in:
parent
0c882cec44
commit
761a2f04e3
3 changed files with 22 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { createContext, useState } from "react";
|
||||
import { createContext, useEffect, useState } from "react";
|
||||
import { checkHasStore } from "../controllers/API";
|
||||
import { storeContextType } from "../types/contexts/store";
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ const initialValue = {
|
|||
setSavedFlows: () => {},
|
||||
hasStore: true,
|
||||
setHasStore: () => {},
|
||||
hasApiKey: true,
|
||||
hasApiKey: false,
|
||||
setHasApiKey: () => {},
|
||||
};
|
||||
|
||||
|
|
@ -18,12 +18,24 @@ export function StoreProvider({ children }) {
|
|||
const [savedFlows, setSavedFlows] = useState<Set<string>>(new Set());
|
||||
|
||||
const [hasStore, setHasStore] = useState(true);
|
||||
const [hasApiKey, setHasApiKey] = useState(true);
|
||||
const [hasApiKey, setHasApiKey] = useState(false);
|
||||
const [storeChecked, setStoreChecked] = useState(false);
|
||||
|
||||
checkHasStore().then((res) => {
|
||||
setHasStore(res["enabled"]);
|
||||
setHasApiKey(res["has_api_key"]);
|
||||
});
|
||||
useEffect(() => {
|
||||
const fetchStoreData = async () => {
|
||||
try {
|
||||
if (storeChecked) return;
|
||||
const res = await checkHasStore();
|
||||
setHasStore(res?.enabled ?? false);
|
||||
setHasApiKey(res?.has_api_key ?? false);
|
||||
setStoreChecked(true);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
||||
fetchStoreData();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<StoreContext.Provider
|
||||
|
|
|
|||
|
|
@ -732,7 +732,7 @@ export async function searchComponent(
|
|||
export async function checkHasStore() {
|
||||
try {
|
||||
const res = await api.get(`${BASE_URL_API}store/check/`);
|
||||
if (res.status === 200) {
|
||||
if (res?.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ export default function StorePage(): JSX.Element {
|
|||
let results = data?.results ?? [];
|
||||
results.forEach((flow) => {
|
||||
savedIds.add(flow.id);
|
||||
}); /*
|
||||
setSavedFlows(savedIds); */
|
||||
});
|
||||
setSavedFlows(savedIds);
|
||||
setErrorApiKey(false);
|
||||
setLoading(false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue