Added message when API key is not valid or is not existent
This commit is contained in:
parent
ffadcf5cf0
commit
0f034b9a2e
3 changed files with 34 additions and 2 deletions
|
|
@ -10,13 +10,15 @@ const initialValue = {
|
||||||
setValidApiKey: () => {},
|
setValidApiKey: () => {},
|
||||||
hasApiKey: false,
|
hasApiKey: false,
|
||||||
setHasApiKey: () => {},
|
setHasApiKey: () => {},
|
||||||
|
loadingApiKey: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const StoreContext = createContext<storeContextType>(initialValue);
|
export const StoreContext = createContext<storeContextType>(initialValue);
|
||||||
|
|
||||||
export function StoreProvider({ children }) {
|
export function StoreProvider({ children }) {
|
||||||
const [hasStore, setHasStore] = useState(true);
|
const [hasStore, setHasStore] = useState(true);
|
||||||
const [hasApiKey, setHasApiKey] = useState(false);
|
const [loadingApiKey, setLoadingApiKey] = useState(true);
|
||||||
|
const [hasApiKey, setHasApiKey] = useState(true);
|
||||||
const [validApiKey, setValidApiKey] = useState(false);
|
const [validApiKey, setValidApiKey] = useState(false);
|
||||||
const [storeChecked, setStoreChecked] = useState(false);
|
const [storeChecked, setStoreChecked] = useState(false);
|
||||||
|
|
||||||
|
|
@ -36,6 +38,7 @@ export function StoreProvider({ children }) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setLoadingApiKey(true);
|
||||||
const fetchStoreData = async () => {
|
const fetchStoreData = async () => {
|
||||||
try {
|
try {
|
||||||
if (storeChecked) return;
|
if (storeChecked) return;
|
||||||
|
|
@ -43,6 +46,7 @@ export function StoreProvider({ children }) {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
setHasApiKey(res?.has_api_key ?? false);
|
setHasApiKey(res?.has_api_key ?? false);
|
||||||
setValidApiKey(res?.is_valid ?? false);
|
setValidApiKey(res?.is_valid ?? false);
|
||||||
|
setLoadingApiKey(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|
@ -60,6 +64,7 @@ export function StoreProvider({ children }) {
|
||||||
setHasApiKey,
|
setHasApiKey,
|
||||||
validApiKey,
|
validApiKey,
|
||||||
setValidApiKey,
|
setValidApiKey,
|
||||||
|
loadingApiKey,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ import { storeComponent } from "../../types/store";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
import { MarketCardComponent } from "./components/market-card";
|
import { MarketCardComponent } from "./components/market-card";
|
||||||
export default function StorePage(): JSX.Element {
|
export default function StorePage(): JSX.Element {
|
||||||
const { validApiKey, setValidApiKey, hasApiKey } = useContext(StoreContext);
|
const { validApiKey, setValidApiKey, hasApiKey, loadingApiKey } =
|
||||||
|
useContext(StoreContext);
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData } = useContext(alertContext);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [loadingTags, setLoadingTags] = useState(true);
|
const [loadingTags, setLoadingTags] = useState(true);
|
||||||
|
|
@ -43,6 +44,26 @@ export default function StorePage(): JSX.Element {
|
||||||
handleGetTags();
|
handleGetTags();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!loadingApiKey) {
|
||||||
|
if (!hasApiKey) {
|
||||||
|
setErrorData({
|
||||||
|
title: "API Key Error",
|
||||||
|
list: [
|
||||||
|
"You don't have an API Key. Please add one to use the Langflow Store.",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else if (!validApiKey) {
|
||||||
|
setErrorData({
|
||||||
|
title: "API Key Error",
|
||||||
|
list: [
|
||||||
|
"Your API Key is not valid. Please add a valid API Key to use the Langflow Store.",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [loadingApiKey, validApiKey, hasApiKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleGetComponents();
|
handleGetComponents();
|
||||||
}, [
|
}, [
|
||||||
|
|
@ -53,6 +74,7 @@ export default function StorePage(): JSX.Element {
|
||||||
filteredCategories,
|
filteredCategories,
|
||||||
selectFilter,
|
selectFilter,
|
||||||
validApiKey,
|
validApiKey,
|
||||||
|
hasApiKey,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function handleGetTags() {
|
function handleGetTags() {
|
||||||
|
|
@ -64,6 +86,7 @@ export default function StorePage(): JSX.Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGetComponents() {
|
function handleGetComponents() {
|
||||||
|
if (!hasApiKey) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
getStoreComponents({
|
getStoreComponents({
|
||||||
page: pageIndex,
|
page: pageIndex,
|
||||||
|
|
@ -81,6 +104,9 @@ export default function StorePage(): JSX.Element {
|
||||||
if (!res?.authorized && validApiKey === true) {
|
if (!res?.authorized && validApiKey === true) {
|
||||||
setValidApiKey(false);
|
setValidApiKey(false);
|
||||||
} else {
|
} else {
|
||||||
|
if (res?.authorized) {
|
||||||
|
setValidApiKey(true);
|
||||||
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setSearchData(res?.results ?? []);
|
setSearchData(res?.results ?? []);
|
||||||
setTotalRowsCount(
|
setTotalRowsCount(
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,5 @@ export type storeContextType = {
|
||||||
hasApiKey: boolean;
|
hasApiKey: boolean;
|
||||||
setValidApiKey: (key: boolean) => void;
|
setValidApiKey: (key: boolean) => void;
|
||||||
validApiKey: boolean;
|
validApiKey: boolean;
|
||||||
|
loadingApiKey: boolean;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue