change structure config app
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
"register": {
|
"register": {
|
||||||
"date": {
|
"date": {
|
||||||
"from": "1402/10/02",
|
"from": "1402/10/02",
|
||||||
"to": "1402/10/15"
|
"to": "1402/11/15"
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"before": "ثبت نام هنوز شروع نشده",
|
"before": "ثبت نام هنوز شروع نشده",
|
||||||
@@ -47,5 +47,6 @@
|
|||||||
"secondary": "فرآیند معرفی ضامن و پرداخت"
|
"secondary": "فرآیند معرفی ضامن و پرداخت"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"banner":"سلام"
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,11 @@ import {useConfig} from "@witel/webapp-builder";
|
|||||||
const Banner = () => {
|
const Banner = () => {
|
||||||
const {config} = useConfig();
|
const {config} = useConfig();
|
||||||
const bannerHTML = config.banner;
|
const bannerHTML = config.banner;
|
||||||
return (
|
return (<Box sx={{backgroundColor: "primary.light"}}>
|
||||||
<Box sx={{backgroundColor: "primary.light"}}>
|
{config.banner && config.banner !== "" && (<Container sx={{py: 0.7}} maxWidth="xl">
|
||||||
<Container sx={{py: 0.7}} maxWidth="xl">
|
<div dangerouslySetInnerHTML={{__html: bannerHTML}}/>
|
||||||
<div dangerouslySetInnerHTML={{__html: bannerHTML}}/>
|
</Container>)}
|
||||||
</Container>
|
</Box>);
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Banner;
|
export default Banner;
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import {useEffect, useState} from "react";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {GET_CONFIG} from "@/core/data/apiRoutes";
|
import {GET_CONFIG} from "@/core/data/apiRoutes";
|
||||||
import {ConfigProvider} from "@witel/webapp-builder";
|
import {ConfigProvider} from "@witel/webapp-builder";
|
||||||
|
import {useRouter} from "next/router";
|
||||||
|
import {isValidJson} from "@/core/utils/isValidJson";
|
||||||
|
|
||||||
const ConfigApp = ({children}) => {
|
const ConfigApp = ({children}) => {
|
||||||
|
const router = useRouter()
|
||||||
const [error, setError] = useState(false)
|
const [error, setError] = useState(false)
|
||||||
const [config, setConfig] = useState()
|
const [config, setConfig] = useState()
|
||||||
|
|
||||||
@@ -11,7 +14,12 @@ const ConfigApp = ({children}) => {
|
|||||||
const fetchConfig = async () => {
|
const fetchConfig = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios(GET_CONFIG)
|
const response = await axios(GET_CONFIG)
|
||||||
setConfig(response.data)
|
let _config = {}
|
||||||
|
response.data.data.forEach(item => {
|
||||||
|
_config[item.name] = isValidJson(item.value) ? JSON.parse(item.value) : item.value
|
||||||
|
})
|
||||||
|
console.log(_config)
|
||||||
|
setConfig(_config)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(true)
|
setError(true)
|
||||||
}
|
}
|
||||||
@@ -19,7 +27,7 @@ const ConfigApp = ({children}) => {
|
|||||||
|
|
||||||
fetchConfig()
|
fetchConfig()
|
||||||
|
|
||||||
}, []);
|
}, [router]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigProvider config={config || {}}>{error ? <>Error request config</> : config && children}</ConfigProvider>)
|
<ConfigProvider config={config || {}}>{error ? <>Error request config</> : config && children}</ConfigProvider>)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL + "/api";
|
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL + "/api";
|
||||||
|
|
||||||
export const GET_CONFIG = process.env.NEXT_PUBLIC_CONFIG_APP_URL;
|
export const GET_CONFIG = process.env.NEXT_PUBLIC_BASE_URL + "/dashboard/settings/list";
|
||||||
|
|
||||||
// export const LOGIN_SEND_OTP_TOKEN = BASE_URL + "/login/send_otp";
|
// export const LOGIN_SEND_OTP_TOKEN = BASE_URL + "/login/send_otp";
|
||||||
export const LOGIN = BASE_URL + "/login";
|
export const LOGIN = BASE_URL + "/login";
|
||||||
|
|||||||
9
src/core/utils/isValidJson.js
Normal file
9
src/core/utils/isValidJson.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export const isValidJson = (value) => {
|
||||||
|
try {
|
||||||
|
JSON.parse(value)
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user