From 95b8e5e1679aa1fe8e7e71c4b4272813f2f725ce Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 09:58:53 +0330 Subject: [PATCH 1/7] TF-102 fixed favicon in project --- public/icons/favicon.png | Bin 0 -> 5300 bytes src/pages/_document.jsx | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 public/icons/favicon.png diff --git a/public/icons/favicon.png b/public/icons/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..c82bf9ae9a460e07f08680dac85d1b898b36ed25 GIT binary patch literal 5300 zcmV;l6ie%gP)!S`@hvq9~f(u4ao_ z-g39p@>-@@YFEqrvTG_XkS3U*BAc3ui6U-@z_1R?%sb!nyfd$N9HFe>`~7ZTFTcY( zGw(U)eg4n$oM$^nhCk^g`;+3rU%>v`B>VqLVs(MF{x?a@83ccqev|GJAm@8+I34G6 z9?$*%&zR#(hy+YdL~!HpOpM@kcP7x08PYfjIQMmK4K93VU`&*Pn$q6*y9CTapG|g< z3{;YUBQtm`H%F$J?PGYnBSU^kUs0#4L)}4m}2kVy@%*K6UU&c z?RWkzy^!Z%AUsZL3U6<3b@%SweY3N(^R8XHX0*@23~^+Hqv}giD~2^dS38#7P3JA#$^O5YZP zB{5J^TZsmVcuD1Js4q9x6sb7^{6*EXWW%&9Y(c5wVMz8ILUNs}fIwP?{ICOsoPjHIk5DWSwrvb(6TXsNxwpi-$6-MV#a zV=$C;s4$rW47UnAn)rITXkA_9g$1`NJRA8G%H;A~H@!ad$dM!G>C>kZi;Ig3=slJ8CarUpth5~N0au&E+^Cm# zWMpJqVnRaPfddE7zC#COq-ElTDbdI{nN}Sd68dFEX6FA`tyWdDX3ZipGBQTCYu8q@ zWWh2F88H~8Wu+K8WC+e*$T=L?GBEYj>C;bH%;pwt+qahu4DTe-cl1X+4@f~yNyBLX%p zF)=YNVSfT#0<_S}UEpT&M%>?~VdJLHL2D_sq^L-L2oAaKN6f)#@K-j%!mf)D z)g}hVla9m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iLy|tYup?$lEO2Kn2FbRiN=bz zo+3HOPWu9BsVS$ZuE^y#E|}I?esi2pvXG9FbM^4>@NUzlP3*^oMce+bU@{C+T4GN%FB;e*HrtG^+da%_INZf5WbE4pirq`tggYWfk|J`2$L8_xx!7ro zIU1!(0#%bgSh0#X@v|>ox-^D5^9CUAkx5%gzX;43oOl$88Uy6$#HD4cR_(mKyt>`K zeY-=sp|r*A!V+JqSL!%2p^!W+}sL$e0*{UR2FTo(qV(lTxMGT{{2Hzj-@O% zRvHBb6?SaF3B{u9*`2hJzp^6`I4c+ZC;u1ZZG+mTXJuuLrpMBLG$-Hp)b49n0o!XN z>D@VNMZfX-3`Rpp>aiYPG_w)$0qlZQGVb z52O - + {emotionStyleTags} From 481c2c02bfc807043948aabd4149e36b39caf63b Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 09:59:09 +0330 Subject: [PATCH 2/7] TF-102 fixed manifest in project --- public/manifest.json | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 public/manifest.json diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..32bacd5 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,57 @@ +{ + "short_name": "Loan Facilities Dashboard", + "name": "Loan Facilities User Dashboard", + "description": "Loan Facilities", + "version": "1.0.0", + "version_name": "1.0.0 beta", + "start_url": "/dashboard", + "orientation": "portrait", + "display": "standalone", + "theme_color": "#084070", + "background_color": "#084070", + "icons": [ + { + "src": "/icons/maskable_icon.png", + "sizes": "any", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x48.png", + "sizes": "48x48", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x72.png", + "sizes": "72x72", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x96.png", + "sizes": "96x96", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x128.png", + "sizes": "128x128", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x384.png", + "sizes": "384x384", + "type": "image/png" + }, + { + "src": "/icons/maskable_icon_x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "categories": [ + "government" + ] +} From f07c5c1b1574949a2cbedf90c7e5d0c1772f5d3f Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 10:04:35 +0330 Subject: [PATCH 3/7] TF-102 fixed bug notifications style --- .../components/notifications/ErrorNotification.jsx | 4 ++-- .../components/notifications/PendingNotification.jsx | 3 ++- .../components/notifications/SuccessNotification.jsx | 2 +- .../components/notifications/WarningNotification.jsx | 12 ++++++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/components/notifications/ErrorNotification.jsx b/src/core/components/notifications/ErrorNotification.jsx index 4c2e857..05e2fb9 100644 --- a/src/core/components/notifications/ErrorNotification.jsx +++ b/src/core/components/notifications/ErrorNotification.jsx @@ -4,7 +4,7 @@ import {toast} from "react-toastify"; const ErrorNotification = (t, status, message) => { toast( - ({closeToast}) => ( + () => ( <> { ); }; -export default ErrorNotification; +export default ErrorNotification; \ No newline at end of file diff --git a/src/core/components/notifications/PendingNotification.jsx b/src/core/components/notifications/PendingNotification.jsx index f3a0af4..6183f6b 100644 --- a/src/core/components/notifications/PendingNotification.jsx +++ b/src/core/components/notifications/PendingNotification.jsx @@ -3,9 +3,10 @@ import {toast} from "react-toastify"; const PendingNotification = (t) => { toast(t("notifications.pending"), { autoClose: false, + closeButton: false, closeOnClick: false, draggable: false, }); }; -export default PendingNotification; +export default PendingNotification; \ No newline at end of file diff --git a/src/core/components/notifications/SuccessNotification.jsx b/src/core/components/notifications/SuccessNotification.jsx index 998deaa..3507cef 100644 --- a/src/core/components/notifications/SuccessNotification.jsx +++ b/src/core/components/notifications/SuccessNotification.jsx @@ -39,4 +39,4 @@ const SuccessNotification = (t, status) => { ); }; -export default SuccessNotification; +export default SuccessNotification; \ No newline at end of file diff --git a/src/core/components/notifications/WarningNotification.jsx b/src/core/components/notifications/WarningNotification.jsx index 5e931f0..19d6a2f 100644 --- a/src/core/components/notifications/WarningNotification.jsx +++ b/src/core/components/notifications/WarningNotification.jsx @@ -1,10 +1,10 @@ import ReportIcon from "@mui/icons-material/Report"; -import {Box, Divider, Typography} from "@mui/material"; +import {Box, Typography} from "@mui/material"; import {toast} from "react-toastify"; const WarningNotification = (t, status) => { toast( - ({closeToast}) => ( + () => ( <> { - {t("warning")} ({t("code")}: {status}) + {t("notifications.warning")} ({t("notifications.code")}:{" "} + {status}) - {t("warning_static_text")} + {t("notifications.warning_static_text")} - ), { @@ -37,4 +37,4 @@ const WarningNotification = (t, status) => { ); }; -export default WarningNotification; +export default WarningNotification; \ No newline at end of file From 67e1801bb57b4d6fce696734b92a2b3aa0edb09c Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 10:15:01 +0330 Subject: [PATCH 4/7] TF-102 Add network config --- public/locales/fa/app.json | 2 + src/core/components/GlobalHead.jsx | 58 ++++++++++++++++++ src/core/components/NetworkComponent.jsx | 34 +++++++++++ src/layouts/AppLayout.jsx | 75 ++++-------------------- src/lib/app/hooks/useNetwork.jsx | 58 ++++++++++++++++++ src/lib/app/hooks/useRequest.js | 26 ++++---- 6 files changed, 176 insertions(+), 77 deletions(-) create mode 100644 src/core/components/GlobalHead.jsx create mode 100644 src/core/components/NetworkComponent.jsx create mode 100644 src/lib/app/hooks/useNetwork.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 435a0c7..c91dc84 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -15,6 +15,8 @@ "Resend_code_in": "ارسال مجدد کد در", "seconds_later": "ثانیه دیگر", "upload_file_text": "بارگذاری فایل", + "online_message": "شما به اینترنت وصل هستید", + "offline_message": "اتصال شما به اینترنت قطع شده است", "header": { "open_profile": "پروفایل", "edit_profile": "ویرایش پروفایل", diff --git a/src/core/components/GlobalHead.jsx b/src/core/components/GlobalHead.jsx new file mode 100644 index 0000000..5d6186d --- /dev/null +++ b/src/core/components/GlobalHead.jsx @@ -0,0 +1,58 @@ +import Head from "next/head"; + +const GlobalHead = () => { + return ( + + + + + + + + + + + + + + + + + + + + + ) +} + +export default GlobalHead \ No newline at end of file diff --git a/src/core/components/NetworkComponent.jsx b/src/core/components/NetworkComponent.jsx new file mode 100644 index 0000000..8ebbb68 --- /dev/null +++ b/src/core/components/NetworkComponent.jsx @@ -0,0 +1,34 @@ +import useNetwork from "@/lib/app/hooks/useNetwork"; +import {useEffect, useRef} from "react"; +import {toast} from "react-toastify"; +import WifiIcon from '@mui/icons-material/Wifi'; +import WifiOffIcon from '@mui/icons-material/WifiOff'; +import {useTranslations} from "next-intl"; + +const NetworkComponent = () => { + const toastId = useRef(null); + const network = useNetwork() + const t = useTranslations() + + useEffect(() => { + if (network.online) { + toast.update(toastId.current, { + type: toast.TYPE.SUCCESS, + render: t('online_message'), + autoClose: 2000, + closeButton: true, + closeOnClick: true, + icon: + }); + return + } + toast.dismiss() + toastId.current = toast.warn(t('offline_message'), { + autoClose: false, closeButton: false, closeOnClick: false, icon: + }) + }, [network.online]); + + return '' +} + +export default NetworkComponent \ No newline at end of file diff --git a/src/layouts/AppLayout.jsx b/src/layouts/AppLayout.jsx index 611e707..2b4593b 100644 --- a/src/layouts/AppLayout.jsx +++ b/src/layouts/AppLayout.jsx @@ -2,12 +2,13 @@ import theme from "@/core/utils/theme"; import useLanguage from "@/lib/app/hooks/useLanguage"; import useLoading from "@/lib/app/hooks/useLoading"; import useUser from "@/lib/app/hooks/useUser"; -import Head from "next/head"; import NextNProgress from "nextjs-progressbar"; import {useEffect} from "react"; import {ToastContainer} from "react-toastify"; import useDirection from "@/lib/app/hooks/useDirection"; import "react-toastify/dist/ReactToastify.css"; +import NetworkComponent from "@/core/components/NetworkComponent"; +import GlobalHead from "@/core/components/GlobalHead"; function AppLayout({children, isBot}) { const {languageIsReady} = useLanguage(); @@ -40,66 +41,16 @@ function AppLayout({children, isBot}) { if (!languageIsReady) return; } - return ( - <> - - - - - - - - - - - - - - - - - - - - - - - {children} - - ); + return (<> + + + + + {children} + ); } -export default AppLayout; +export default AppLayout; \ No newline at end of file diff --git a/src/lib/app/hooks/useNetwork.jsx b/src/lib/app/hooks/useNetwork.jsx new file mode 100644 index 0000000..4fff7fe --- /dev/null +++ b/src/lib/app/hooks/useNetwork.jsx @@ -0,0 +1,58 @@ +import {useEffect, useState} from "react"; + +function getNetworkConnection() { + return ( + navigator.connection || + navigator.mozConnection || + navigator.webkitConnection || + null + ); +} + +function getNetworkConnectionInfo() { + const connection = getNetworkConnection(); + if (!connection) { + return {}; + } + return { + rtt: connection.rtt, + type: connection.type, + saveData: connection.saveData, + downLink: connection.downLink, + downLinkMax: connection.downLinkMax, + effectiveType: connection.effectiveType, + }; +} + +function useNetwork() { + const [state, setState] = useState(() => { + return { + online: navigator.onLine, + }; + }); + useEffect(() => { + const handleOnline = () => { + setState((prevState) => ({ + ...prevState, + online: true, + })); + }; + const handleOffline = () => { + setState((prevState) => ({ + ...prevState, + online: false, + })); + }; + + window.addEventListener("online", handleOnline); + window.addEventListener("offline", handleOffline); + return () => { + window.removeEventListener("online", handleOnline); + window.removeEventListener("offline", handleOffline); + }; + }, []); + + return state; +} + +export default useNetwork; \ No newline at end of file diff --git a/src/lib/app/hooks/useRequest.js b/src/lib/app/hooks/useRequest.js index 5c567ca..d361e08 100644 --- a/src/lib/app/hooks/useRequest.js +++ b/src/lib/app/hooks/useRequest.js @@ -4,27 +4,23 @@ import PendingNotification from "@/core/components/notifications/PendingNotifica import {useTranslations} from "next-intl"; import useUser from "@/lib/app/hooks/useUser"; import {errorRequest, errorResponse, errorSetting} from "@/core/utils/errorHandler"; +import useNetwork from "@/lib/app/hooks/useNetwork"; const defaultOptions = { - auth: false, - data: {}, - requestOptions: { + auth: false, data: {}, requestOptions: { headers: {} - }, - notification: true, - pending: true, - success: { + }, notification: true, pending: true, success: { notification: { show: true, }, - }, - failed: { + }, failed: { notification: { show: true, }, }, } const useRequest = (initOptions) => { + const network = useNetwork() const t = useTranslations() const {token, clearToken} = useUser() let _options = {...defaultOptions, ...initOptions} @@ -32,20 +28,20 @@ const useRequest = (initOptions) => { function requestServer(url = '', method = 'get', options) { _options = {..._options, ...options} if (_options.auth) _options = { - ..._options, - requestOptions: { + ..._options, requestOptions: { ..._options.requestOptions, headers: {..._options.requestOptions.headers, authorization: `Bearer ${token}`} } } return new Promise((resolve, reject) => { + if (!network.online) { + reject() + return + } if (_options.notification && _options.failed.notification.show && _options.pending) PendingNotification(t) axios({ - url: url, - method: method, - data: _options.data, - ..._options.requestOptions + url: url, method: method, data: _options.data, ..._options.requestOptions }) .then(response => { successRequest(response, t, _options) From 650c02e09ea7c83d7f4fd969ac651751a9fa4d3e Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 10:34:32 +0330 Subject: [PATCH 5/7] TF-102 fixed error handler when response is logic error --- src/core/utils/errorHandler.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/utils/errorHandler.js b/src/core/utils/errorHandler.js index ec5858a..8dbd364 100644 --- a/src/core/utils/errorHandler.js +++ b/src/core/utils/errorHandler.js @@ -3,11 +3,11 @@ import WarningNotification from "@/core/components/notifications/WarningNotifica import {toast} from "react-toastify"; export const errorSetting = (t, notification) => { - //todo + if (notification) toast.dismiss(); } export const errorRequest = (t, notification) => { - //todo + if (notification) toast.dismiss(); } export const errorResponse = (response, clearToken, t, notification) => { @@ -48,7 +48,7 @@ const isServerError = status => status >= 500 && status <= 599; const isClientError = status => status >= 400 && status <= 499; const errorLogic = (response, t, notification) => { - if (notification) ErrorNotification(t, response.status) + if (notification) ErrorNotification(t, response.status, response.data.message) } const errorValidation = (response, t, notification) => { if (notification) { @@ -59,4 +59,4 @@ const errorValidation = (response, t, notification) => { ErrorNotification(t, response.status, errorsArray[item][0]); }) } -} +} \ No newline at end of file From cff36d5b0412aa3e409725bcd082509f18a295f4 Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 10:55:36 +0330 Subject: [PATCH 6/7] TF-102 fixed follow-up page when no request found --- public/locales/fa/app.json | 3 +- .../dashboard/refahi/followUp-loan/index.jsx | 46 ++++++++----------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index c91dc84..7289568 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -113,7 +113,8 @@ "loan_follow_up_page": "پیگیری درخواست", "loan_request_correction": "اصلاح درخواست", "loan_request_detail": "مشاهده جزئیات", - "request_number": "درخواست شماره" + "request_number": "درخواست شماره", + "no_request_found": "درخواستی یافت نشد" }, "LoanRequest": { "loan_request_page": "ثبت درخواست وام", diff --git a/src/components/dashboard/refahi/followUp-loan/index.jsx b/src/components/dashboard/refahi/followUp-loan/index.jsx index 331bab0..32b121d 100644 --- a/src/components/dashboard/refahi/followUp-loan/index.jsx +++ b/src/components/dashboard/refahi/followUp-loan/index.jsx @@ -1,19 +1,18 @@ import DashboardLayouts from "@/layouts/dashboardLayouts"; -import { - Grid, - Stack, -} from "@mui/material"; +import {Grid, Stack, Typography,} from "@mui/material"; import {useEffect, useState} from "react"; import {SHOW_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes"; import useLoading from "@/lib/app/hooks/useLoading"; import useRequest from "@/lib/app/hooks/useRequest"; import moment from "jalali-moment"; import RequestCard from "@/components/dashboard/refahi/followUp-loan/RequestCard"; +import {useTranslations} from "next-intl"; const LoanFollowUpComponent = () => { + const t = useTranslations() const requestServer = useRequest(); const {setLoadingPage} = useLoading(); - const [requestsList, setRequestsList] = useState([]); + const [requestsList, setRequestsList] = useState(null); // get form data useEffect(() => { setLoadingPage(true) @@ -33,28 +32,23 @@ const LoanFollowUpComponent = () => { }) }, []); - return ( - - + + {requestsList == null ? '' : requestsList.length ? ( - - {requestsList.map((item, index) => ( - - ))} - - - - ); + {requestsList.map((item, index) => ())} + ) : ({t('LoanFollowUp.no_request_found')})} + + ); }; export default LoanFollowUpComponent; From 6652615c94e40700abc0f2bb3e590342085b1ecc Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 27 Sep 2023 12:04:30 +0330 Subject: [PATCH 7/7] TF-102 fixed form in add-request-refahi --- public/locales/fa/app.json | 2 + .../refahi/add-request-loan/forms/AddForm.jsx | 96 +++++++++++-------- src/lib/app/hooks/useProvince.jsx | 29 ++++++ 3 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 src/lib/app/hooks/useProvince.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 7289568..6031f3e 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -135,6 +135,8 @@ "text_field_vehicle_type": "نام وسیله نقلیه", "text_field_enter_your_vehicle_type": "نام وسیله نقلیه خود را وارد کنید", "text_field_province": "استان", + "text_field_loading_provinces_list": "درحال دریافت استان ها", + "text_field_error_fetching_provinces": "خطا در دریافت استان ها", "text_field_enter_your_province": "استان خود را وارد کنید", "text_field_navgan_id": "شماره ناوگان", "text_field_enter_your_navgan_id": "شماره ناوگان خود را وارد کنید", diff --git a/src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx b/src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx index 06a40fc..4c67ee3 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx @@ -1,39 +1,30 @@ import StyledForm from "@/core/components/StyledForm"; import UploadSystem from "@/core/components/UploadSystem"; -import {GET_PROVINCE_LIST, SEND_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes"; -import useDirection from "@/lib/app/hooks/useDirection"; -import useUser from "@/lib/app/hooks/useUser"; +import {SEND_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes"; import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; -import {Box, Button, Chip, Divider, Stack, TextField} from "@mui/material"; +import { + Box, + Button, + Chip, + Divider, + FormControl, + FormHelperText, + InputLabel, + MenuItem, + Select, + Stack, + TextField +} from "@mui/material"; import {Field, Formik} from "formik"; import {useTranslations} from "next-intl"; -import {useEffect, useState} from "react"; import * as Yup from "yup"; -import SelectBox from "@/core/components/SelectBox"; import useRequest from "@/lib/app/hooks/useRequest"; +import useProvince from "@/lib/app/hooks/useProvince"; const AddFormComponent = () => { const t = useTranslations(); - const {directionApp} = useDirection(); - const {token} = useUser(); const requestServer = useRequest() - - const [provinceList, setProvinceList] = useState([]); - - // get province list - useEffect(() => { - requestServer(GET_PROVINCE_LIST, "get", {auth: true, notification: false}) - .then(function ({data}) { - const formattedData = data.map((province, index) => ({ - id: index, - name: province.name, - value: province.id, - })); - setProvinceList(formattedData); - }).catch(() => { - }) - }, []); - // end get province list + const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince() // initial values, validation and request action of form const initialValues = { @@ -183,27 +174,48 @@ const AddFormComponent = () => { - + > + {t("LoanRequest.text_field_province")} + + + {props.touched.province && props.errors.province ? props.errors.province : ""} + + { + const requestServer = useRequest({auth: true, notification: false}) + + //swr config + const fetcher = (...args) => { + return requestServer(args, 'get').then(({data}) => { + return data; + }).catch(() => { + }) + }; + + const {data, isLoading} = useSWR(GET_PROVINCE_LIST, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false + }); + + return { + provinceList: data, + isLoadingProvinceList: isLoading, + errorProvinceList: !data + } +}; + +export default useProvince; \ No newline at end of file