change structure config app
This commit is contained in:
28
src/core/components/Config.jsx
Normal file
28
src/core/components/Config.jsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import axios from "axios";
|
||||
import {GET_CONFIG} from "@/core/data/apiRoutes";
|
||||
import {ConfigProvider} from "@witel/webapp-builder";
|
||||
|
||||
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
|
||||
@@ -1,5 +1,7 @@
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL + "/api";
|
||||
|
||||
export const GET_CONFIG = process.env.NEXT_PUBLIC_CONFIG_APP_URL;
|
||||
|
||||
// export const LOGIN_SEND_OTP_TOKEN = BASE_URL + "/login/send_otp";
|
||||
export const LOGIN = BASE_URL + "/login";
|
||||
// export const REGISTER_SEND_OTP_TOKEN = BASE_URL + "/register/send_otp";
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import {parse} from "next-useragent";
|
||||
import process from "next/dist/build/webpack/loaders/resolve-url-loader/lib/postcss";
|
||||
|
||||
export const globalServerProps = async ({req, locale}) => {
|
||||
const {isBot} = parse(req.headers["user-agent"]);
|
||||
|
||||
const responseConfig = await fetch(`${process.env.NEXT_PUBLIC_CONFIG_APP_URL}?_=${Math.random()}`);
|
||||
|
||||
return {
|
||||
config: await responseConfig.json(),
|
||||
messages: (await import(`&/locales/${locale}/app.json`)).default,
|
||||
isBot,
|
||||
locale,
|
||||
|
||||
@@ -2,7 +2,6 @@ import "&/global.scss";
|
||||
import "moment/locale/fa";
|
||||
import {
|
||||
AppLayout,
|
||||
ConfigProvider,
|
||||
LanguageProvider,
|
||||
LoadingProvider,
|
||||
MuiLayout,
|
||||
@@ -18,10 +17,11 @@ import themeRtl from "@/core/utils/theme-rtl";
|
||||
import TitlePage from "@/core/components/TitlePage";
|
||||
import GlobalHead from "@/core/components/GlobalHead";
|
||||
import Layout from "@/layouts";
|
||||
import ConfigApp from "@/core/components/Config";
|
||||
|
||||
const App = ({Component, pageProps}) => {
|
||||
return (<>
|
||||
<ConfigProvider config={pageProps.config || {}}>
|
||||
<ConfigApp>
|
||||
<UserProvider urlGetUser={GET_USER} schemaGetUser={(data) => data}>
|
||||
<LanguageProvider defaultLanguage={process.env.NEXT_PUBLIC_DEFAULT_LANGUAGE}
|
||||
languageList={languageList}>
|
||||
@@ -45,7 +45,7 @@ const App = ({Component, pageProps}) => {
|
||||
</NextIntlProvider>
|
||||
</LanguageProvider>
|
||||
</UserProvider>
|
||||
</ConfigProvider>
|
||||
</ConfigApp>
|
||||
</>);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user