change structure config app

This commit is contained in:
AmirHossein Mahmoodi
2024-01-23 11:42:46 +03:30
parent 0c2448e70d
commit 84bbe3e637
5 changed files with 28 additions and 12 deletions

View File

@@ -14,7 +14,7 @@
"register": {
"date": {
"from": "1402/10/02",
"to": "1402/10/15"
"to": "1402/11/15"
},
"messages": {
"before": "ثبت نام هنوز شروع نشده",
@@ -47,5 +47,6 @@
"secondary": "فرآیند معرفی ضامن و پرداخت"
}
}
}
},
"banner":"سلام"
}

View File

@@ -4,13 +4,11 @@ import {useConfig} from "@witel/webapp-builder";
const Banner = () => {
const {config} = useConfig();
const bannerHTML = config.banner;
return (
<Box sx={{backgroundColor: "primary.light"}}>
<Container sx={{py: 0.7}} maxWidth="xl">
return (<Box sx={{backgroundColor: "primary.light"}}>
{config.banner && config.banner !== "" && (<Container sx={{py: 0.7}} maxWidth="xl">
<div dangerouslySetInnerHTML={{__html: bannerHTML}}/>
</Container>
</Box>
);
</Container>)}
</Box>);
};
export default Banner;

View File

@@ -2,8 +2,11 @@ import {useEffect, useState} from "react";
import axios from "axios";
import {GET_CONFIG} from "@/core/data/apiRoutes";
import {ConfigProvider} from "@witel/webapp-builder";
import {useRouter} from "next/router";
import {isValidJson} from "@/core/utils/isValidJson";
const ConfigApp = ({children}) => {
const router = useRouter()
const [error, setError] = useState(false)
const [config, setConfig] = useState()
@@ -11,7 +14,12 @@ const ConfigApp = ({children}) => {
const fetchConfig = async () => {
try {
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) {
setError(true)
}
@@ -19,7 +27,7 @@ const ConfigApp = ({children}) => {
fetchConfig()
}, []);
}, [router]);
return (
<ConfigProvider config={config || {}}>{error ? <>Error request config</> : config && children}</ConfigProvider>)

View File

@@ -1,6 +1,6 @@
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 = BASE_URL + "/login";

View File

@@ -0,0 +1,9 @@
export const isValidJson = (value) => {
try {
JSON.parse(value)
return true
} catch (e) {
return false
}
}