add config app

This commit is contained in:
AmirHossein Mahmoodi
2024-01-20 14:40:18 +03:30
parent a45fbddc8d
commit b3b30ee619
8 changed files with 108 additions and 5 deletions

View File

@@ -0,0 +1,28 @@
import {useEffect, useState} from "react";
import axios from "axios";
import {GET_CONFIG} from "@/core/data/apiRoutes";
import {ConfigProvider} from "@/lib/app/contexts/config";
const ConfigApp = ({children}) => {
const [error, setError] = useState(false)
const [config, setConfig] = useState()
useEffect(() => {
const fetchConfig = async () => {
try {
const response = await axios(GET_CONFIG)
setConfig(response.data)
} catch (error) {
setError(true)
}
}
fetchConfig()
}, []);
return (
<ConfigProvider config={config || {}}>{error ? <>Error request config</> : config && children}</ConfigProvider>)
}
export default ConfigApp