diff --git a/public/config.json.example b/public/config.json.example
index ac50d76..7dce39a 100644
--- a/public/config.json.example
+++ b/public/config.json.example
@@ -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":"سلام"
}
\ No newline at end of file
diff --git a/src/components/first/Banner.jsx b/src/components/first/Banner.jsx
index 3a8a26a..0c4ef35 100644
--- a/src/components/first/Banner.jsx
+++ b/src/components/first/Banner.jsx
@@ -4,13 +4,11 @@ import {useConfig} from "@witel/webapp-builder";
const Banner = () => {
const {config} = useConfig();
const bannerHTML = config.banner;
- return (
-
-
-
-
-
- );
+ return (
+ {config.banner && config.banner !== "" && (
+
+ )}
+ );
};
export default Banner;
diff --git a/src/core/components/Config.jsx b/src/core/components/Config.jsx
index 3c1d833..a137364 100644
--- a/src/core/components/Config.jsx
+++ b/src/core/components/Config.jsx
@@ -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 (
{error ? <>Error request config> : config && children})
diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js
index f2e42fc..1e69d2d 100644
--- a/src/core/data/apiRoutes.js
+++ b/src/core/data/apiRoutes.js
@@ -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";
diff --git a/src/core/utils/isValidJson.js b/src/core/utils/isValidJson.js
new file mode 100644
index 0000000..1ba1b86
--- /dev/null
+++ b/src/core/utils/isValidJson.js
@@ -0,0 +1,9 @@
+export const isValidJson = (value) => {
+ try {
+ JSON.parse(value)
+ return true
+ } catch (e) {
+ return false
+ }
+
+}
\ No newline at end of file