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,
|
||||
|
||||
Reference in New Issue
Block a user