🔧 fix(storeContext.tsx): add missing import for checkHasApiKey function in API controller
🔧 fix(API/index.ts): add checkHasApiKey function to check if store has an API key
This commit is contained in:
parent
09ddf22d74
commit
5affcdf987
2 changed files with 27 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { createContext, useEffect, useState } from "react";
|
||||
import { checkHasStore } from "../controllers/API";
|
||||
import { checkHasApiKey, checkHasStore } from "../controllers/API";
|
||||
import { storeContextType } from "../types/contexts/store";
|
||||
|
||||
//store context to share user components and update them
|
||||
|
|
@ -27,7 +27,6 @@ export function StoreProvider({ children }) {
|
|||
if (storeChecked) return;
|
||||
const res = await checkHasStore();
|
||||
setHasStore(res?.enabled ?? false);
|
||||
setHasApiKey(res?.has_api_key ?? false);
|
||||
setStoreChecked(true);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
|
@ -37,6 +36,20 @@ export function StoreProvider({ children }) {
|
|||
fetchStoreData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStoreData = async () => {
|
||||
try {
|
||||
if (storeChecked) return;
|
||||
const res = await checkHasApiKey();
|
||||
setHasApiKey(res?.has_api_key ?? false);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
||||
fetchStoreData();
|
||||
}, [storeChecked]);
|
||||
|
||||
return (
|
||||
<StoreContext.Provider
|
||||
value={{
|
||||
|
|
|
|||
|
|
@ -729,6 +729,18 @@ export async function searchComponent(
|
|||
}
|
||||
}
|
||||
|
||||
export async function checkHasApiKey() {
|
||||
try {
|
||||
const res = await api.get(`${BASE_URL_API}/store/check/api_key`);
|
||||
if (res?.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkHasStore() {
|
||||
try {
|
||||
const res = await api.get(`${BASE_URL_API}store/check/`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue