add config app
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -31,4 +31,6 @@ cypress/screenshots
|
||||
.env
|
||||
.idea
|
||||
package-lock.json
|
||||
ecosystem.config.js
|
||||
ecosystem.config.js
|
||||
|
||||
public/config.json
|
||||
@@ -9,6 +9,8 @@ NEXT_PUBLIC_SECONDARY_MAIN = "#FF4E00"
|
||||
NEXT_PUBLIC_BASE_URL = "https://loan.witel.ir"
|
||||
NEXT_PUBLIC_POWERED_BY_URL = "https://witel.ir"
|
||||
|
||||
NEXT_PUBLIC_CONFIG_APP_URL = "http://localhost:3000/config.json"
|
||||
|
||||
#["NEXT_PUBLIC_HAS_WIDGET" , "NEXT_PUBLIC_HAS_NOTIFICATION"]
|
||||
NEXT_PUBLIC_HAS_VALUE=["NEXT_PUBLIC_HAS_NOTIFICATION"]
|
||||
|
||||
|
||||
51
public/config.json.example
Normal file
51
public/config.json.example
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"middlewares": {
|
||||
"/dashboard/navgan/add-request-loan":{
|
||||
"status" : false,
|
||||
"title":"اطلاع رسانی",
|
||||
"message": "ثبت نام به زودی آغاز خواهد شد."
|
||||
}
|
||||
},
|
||||
"add_request_loan_birthday_range": {
|
||||
"min": 1327,
|
||||
"max": 1380
|
||||
},
|
||||
"deadlines": {
|
||||
"register": {
|
||||
"date": {
|
||||
"from": "1402/10/02",
|
||||
"to": "1402/10/15"
|
||||
},
|
||||
"messages": {
|
||||
"before": "ثبت نام هنوز شروع نشده",
|
||||
"after": "زمان ثبت نام به اتمام رسید"
|
||||
},
|
||||
"timeline_label": {
|
||||
"primary": "ثبت نام متقاضی",
|
||||
"secondary": "ثبت نام متقاضیان واجد شرایط"
|
||||
}
|
||||
},
|
||||
"validation": {
|
||||
"date": {
|
||||
"from": "1402/10/15",
|
||||
"to": "1402/10/30"
|
||||
},
|
||||
"messages": {},
|
||||
"timeline_label": {
|
||||
"primary": "صحت سنجی متقاضیان",
|
||||
"secondary": "بررسی و کارشناسی درخواست ها"
|
||||
}
|
||||
},
|
||||
"done": {
|
||||
"date": {
|
||||
"from": "1402/11/01",
|
||||
"to": "1402/11/20"
|
||||
},
|
||||
"messages": {},
|
||||
"timeline_label": {
|
||||
"primary": "ارجاع به بانک",
|
||||
"secondary": "فرآیند معرفی ضامن و پرداخت"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 "@/lib/app/contexts/config";
|
||||
|
||||
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;
|
||||
|
||||
export const GET_CONFIG = process.env.NEXT_PUBLIC_CONFIG_APP_URL;
|
||||
|
||||
//login
|
||||
export const GET_USER_TOKEN = BASE_URL + "/dashboard/login";
|
||||
//end login
|
||||
|
||||
7
src/lib/app/contexts/config.jsx
Normal file
7
src/lib/app/contexts/config.jsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import {createContext} from "react";
|
||||
|
||||
export const ConfigContext = createContext()
|
||||
|
||||
export const ConfigProvider = ({children, config}) => {
|
||||
return <ConfigContext.Provider value={{config}}>{children}</ConfigContext.Provider>
|
||||
}
|
||||
12
src/lib/app/hooks/useConfig.jsx
Normal file
12
src/lib/app/hooks/useConfig.jsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import {useContext} from "react";
|
||||
import {ConfigContext} from "@/lib/app/contexts/config";
|
||||
|
||||
export const useConfig = () => {
|
||||
const context = useContext(ConfigContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useConfig must be used within a ConfigProvider");
|
||||
}
|
||||
|
||||
return {config: context.config};
|
||||
};
|
||||
@@ -10,11 +10,11 @@ import TitlePage from "@/core/components/TitlePage";
|
||||
import Layout from "@/layouts";
|
||||
import {ToastProvider} from "@/lib/app/contexts/toast";
|
||||
import {PrintProvider} from "@/lib/app/contexts/print";
|
||||
import ConfigApp from "@/core/components/Config";
|
||||
|
||||
const App = ({Component, pageProps}) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
return (<ConfigApp>
|
||||
<UserProvider>
|
||||
<LanguageProvider>
|
||||
<NextIntlProvider locale={pageProps.locale} messages={pageProps.messages || {}}>
|
||||
@@ -35,8 +35,7 @@ const App = ({Component, pageProps}) => {
|
||||
</NextIntlProvider>
|
||||
</LanguageProvider>
|
||||
</UserProvider>
|
||||
</>
|
||||
);
|
||||
</ConfigApp>);
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
||||
Reference in New Issue
Block a user