From fd1a6bcf2e7411fd2e8a4dfb530e01dd65ade8e4 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Sat, 19 Aug 2023 13:38:51 +0330 Subject: [PATCH] add loan request/change structure and documentary/ making middle ware for user type/update breadcrumb --- public/locales/fa/app.json | 13 +- .../add-request-loan/forms/AddForm.jsx} | 4 +- .../add-request-loan}/index.jsx | 5 +- .../followUp-loan}/index.jsx | 0 .../add-request-loan/forms/AddForm.jsx} | 165 +++++------------- .../refahi/add-request-loan/index.jsx | 30 ++++ .../dashboard/refahi/followUp-loan/index.jsx | 123 +++++++++++++ src/core/components/SelectBox.jsx | 6 +- src/core/data/apiRoutes.js | 4 +- src/core/data/sidebarMenu.jsx | 27 ++- .../dashboardLayouts/breadcrumbs/index.jsx | 13 ++ .../dashboardLayouts/sidebar/SidebarList.jsx | 20 ++- src/lib/app/hooks/useRequest.js | 15 +- src/middlewares/UserType.jsx | 41 +++++ .../navgan/add-request-loan/index.jsx | 26 +++ .../followUp-loan}/index.jsx | 8 +- .../refahi/add-request-loan/index.jsx | 26 +++ .../followUp-loan}/index.jsx | 12 +- 18 files changed, 382 insertions(+), 156 deletions(-) rename src/components/dashboard/{loan-request/NavyForm.jsx => navgan/add-request-loan/forms/AddForm.jsx} (99%) rename src/components/dashboard/{loan-request => navgan/add-request-loan}/index.jsx (81%) rename src/components/dashboard/{loan-follow-up => navgan/followUp-loan}/index.jsx (100%) rename src/components/dashboard/{loan-request/WelfareServicesForm.jsx => refahi/add-request-loan/forms/AddForm.jsx} (69%) create mode 100644 src/components/dashboard/refahi/add-request-loan/index.jsx create mode 100644 src/components/dashboard/refahi/followUp-loan/index.jsx create mode 100644 src/middlewares/UserType.jsx create mode 100644 src/pages/dashboard/navgan/add-request-loan/index.jsx rename src/pages/dashboard/{loan-request => navgan/followUp-loan}/index.jsx (64%) create mode 100644 src/pages/dashboard/refahi/add-request-loan/index.jsx rename src/pages/dashboard/{loan-follow-up => refahi/followUp-loan}/index.jsx (53%) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index a78653d..e595dc3 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -4,10 +4,10 @@ "dashboard": "داشبورد", "first_page": "خوش آمدید", "login": "ورود", + "pending": "درحال اجرا...", "login_user_panel": "ورود به پنل کاربران", "register_navy": "ثبت نام اعضای ناوگان", "register_welfare_services": "ثبت نام اعضای خدمات رفاهی", - "pending": "درحال اجرا...", "user_navy": "ناوگان", "page_not_found": "صفحه مورد نظر یافت نشد", "delete": "حذف", @@ -25,7 +25,12 @@ "success_static_text": "عملیات با موفقیت انجام شد", "code": "کد", "success": "موفق", - "error": "خطا" + "error": "خطا", + "pending": "درحال اجرا..." + }, + "Permission": { + "typography_you_dont_have_access": "شما دسترسی لازم برای مشاهده این صفحه را ندارید!", + "button_back_dashboard": "بازگشت به صفحه اصلی" }, "Titles": { "title_login_page": "صفحه ورود", @@ -48,8 +53,8 @@ }, "sidebar": { "dashboard": "داشبورد", - "loan-request": "درخواست وام", - "loan-follow-up": "پیگیری درخواست" + "add-request-loan": "درخواست وام", + "followUp-loan": "پیگیری درخواست" }, "Authorization": { "typography_your_login_is_valid_and_you_do_not_need_to_login_again": "شما دسترسی لازم به این صفحه را دارید نیاز به ورود مجدد نیست.", diff --git a/src/components/dashboard/loan-request/NavyForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx similarity index 99% rename from src/components/dashboard/loan-request/NavyForm.jsx rename to src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx index 3a380f1..760fed1 100644 --- a/src/components/dashboard/loan-request/NavyForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx @@ -13,7 +13,7 @@ import {useTranslations} from "next-intl"; import {useEffect, useState} from "react"; import * as Yup from "yup"; -const NavyFormComponent = () => { +const AddFormComponent = () => { const t = useTranslations(); const {directionApp} = useDirection(); const {token} = useUser(); @@ -486,4 +486,4 @@ const NavyFormComponent = () => { ); }; -export default NavyFormComponent; +export default AddFormComponent; diff --git a/src/components/dashboard/loan-request/index.jsx b/src/components/dashboard/navgan/add-request-loan/index.jsx similarity index 81% rename from src/components/dashboard/loan-request/index.jsx rename to src/components/dashboard/navgan/add-request-loan/index.jsx index a02af7a..cd9d359 100644 --- a/src/components/dashboard/loan-request/index.jsx +++ b/src/components/dashboard/navgan/add-request-loan/index.jsx @@ -1,10 +1,9 @@ import CenterLayout from "@/layouts/CenterLayout"; import DashboardLayouts from "@/layouts/dashboardLayouts"; import useUser from "@/lib/app/hooks/useUser"; -import NavyFormComponent from "./NavyForm"; -import WelfareServicesFormComponent from "./WelfareServicesForm"; import {Box, Chip, Divider} from "@mui/material"; import {useTranslations} from "next-intl"; +import AddFormComponent from "@/components/dashboard/navgan/add-request-loan/forms/AddForm"; const LoanRequestComponent = () => { const t = useTranslations(); @@ -22,7 +21,7 @@ const LoanRequestComponent = () => { /> - {user.type_id == 1 ? : } + ); diff --git a/src/components/dashboard/loan-follow-up/index.jsx b/src/components/dashboard/navgan/followUp-loan/index.jsx similarity index 100% rename from src/components/dashboard/loan-follow-up/index.jsx rename to src/components/dashboard/navgan/followUp-loan/index.jsx diff --git a/src/components/dashboard/loan-request/WelfareServicesForm.jsx b/src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx similarity index 69% rename from src/components/dashboard/loan-request/WelfareServicesForm.jsx rename to src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx index 782a256..319885e 100644 --- a/src/components/dashboard/loan-request/WelfareServicesForm.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/AddForm.jsx @@ -1,7 +1,6 @@ -import Notifications from "@/core/components/notifications"; import StyledForm from "@/core/components/StyledForm"; import UploadSystem from "@/core/components/UploadSystem"; -import {SEND_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes"; +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 DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; @@ -9,13 +8,32 @@ import {Box, Button, Stack, TextField} from "@mui/material"; import axios from "axios"; import {Field, Formik} from "formik"; import {useTranslations} from "next-intl"; -import {useState} from "react"; +import {useEffect, useState} from "react"; import * as Yup from "yup"; +import SelectBox from "@/core/components/SelectBox"; +import useRequest from "@/lib/app/hooks/useRequest"; -const WelfareServicesFormComponent = () => { +const AddFormComponent = () => { const t = useTranslations(); const {directionApp} = useDirection(); const {token} = useUser(); + const requestServer = useRequest() + + // get province list + const [provinceList, setProvinceList] = useState([]); + 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 // upload files const [selectedImageShenasname, setSelectedImageShenasname] = useState( @@ -57,8 +75,6 @@ const WelfareServicesFormComponent = () => { const initialValues = { name: "", phone_number: "", - vehicle_type: "", - plate_number: "", province: "", national_code: "", shenasname_id: "", @@ -71,12 +87,6 @@ const WelfareServicesFormComponent = () => { phone_number: Yup.string().required( t("LoanRequest.error_message_phone_number") ), - vehicle_type: Yup.string().required( - t("LoanRequest.error_message_vehicle_type") - ), - plate_number: Yup.string().required( - t("LoanRequest.error_message_plate_number") - ), province: Yup.string().required(t("LoanRequest.error_message_province")), national_code: Yup.string().required( t("LoanRequest.error_message_national_code") @@ -87,34 +97,23 @@ const WelfareServicesFormComponent = () => { }); const handleSubmit = async (values, props) => { - Notifications(t, undefined); const formData = new FormData(); formData.append("name", values.name); formData.append("phone_number", values.phone_number); - formData.append("vehicle_type", values.vehicle_type); - formData.append("plate_number", values.plate_number); formData.append("province_id", values.province); - formData.append("national_code", values.national_code); + formData.append("national_id", values.national_code); formData.append("shenasname_id", values.shenasname_id); if (values.shenasname_img != null) formData.append("shenasname_image", values.shenasname_img); if (values.national_card_img != null) formData.append("national_card_image", values.national_card_img); - await axios - .post(SEND_LOAN_REQUEST_WELFARE, formData, { - headers: { - Authorization: `Bearer ${token}`, - "Content-Type": "multipart/form-data", - }, - }) + requestServer(SEND_LOAN_REQUEST_WELFARE, "post", {auth: true, data: formData}) .then(function (response) { - Notifications(t, response); - }) - .catch(function (error) { - Notifications(t, error.response); - props.setSubmitting(false); - }); + + }).catch(function (error) { + props.setSubmitting(false); + }); }; // end initial values, validation and request action of form @@ -158,7 +157,7 @@ const WelfareServicesFormComponent = () => { label={t("LoanRequest.text_field_name")} placeholder={t("LoanRequest.text_field_enter_your_name")} type={"text"} - error={props.touched.name && props.errors.name ? true : false} + error={!!(props.touched.name && props.errors.name)} fullWidth helperText={props.touched.name ? props.errors.name : null} /> @@ -182,9 +181,7 @@ const WelfareServicesFormComponent = () => { )} type={"text"} error={ - props.touched.phone_number && props.errors.phone_number - ? true - : false + !!(props.touched.phone_number && props.errors.phone_number) } fullWidth helperText={ @@ -194,16 +191,6 @@ const WelfareServicesFormComponent = () => { } /> - - { }} > - - - - - - { )} type={"text"} error={ - props.touched.national_code && props.errors.national_code - ? true - : false + !!(props.touched.national_code && props.errors.national_code) } fullWidth helperText={ @@ -353,9 +274,7 @@ const WelfareServicesFormComponent = () => { )} type={"text"} error={ - props.touched.shenasname_id && props.errors.shenasname_id - ? true - : false + !!(props.touched.shenasname_id && props.errors.shenasname_id) } fullWidth helperText={ @@ -421,7 +340,7 @@ const WelfareServicesFormComponent = () => { size="large" sx={{mt: 2}} endIcon={} - disabled={props.isSubmitting ? true : false} + disabled={props.isSubmitting} > {t("LoanRequest.button_submit")} @@ -433,4 +352,4 @@ const WelfareServicesFormComponent = () => { ); }; -export default WelfareServicesFormComponent; +export default AddFormComponent; \ No newline at end of file diff --git a/src/components/dashboard/refahi/add-request-loan/index.jsx b/src/components/dashboard/refahi/add-request-loan/index.jsx new file mode 100644 index 0000000..df7fa4c --- /dev/null +++ b/src/components/dashboard/refahi/add-request-loan/index.jsx @@ -0,0 +1,30 @@ +import CenterLayout from "@/layouts/CenterLayout"; +import DashboardLayouts from "@/layouts/dashboardLayouts"; +import useUser from "@/lib/app/hooks/useUser"; +import {Box, Chip, Divider} from "@mui/material"; +import {useTranslations} from "next-intl"; +import AddFormComponent from "@/components/dashboard/refahi/add-request-loan/forms/AddForm"; + +const LoanRequestComponent = () => { + const t = useTranslations(); + const {user} = useUser(); + + return ( + + + + + + + + + + + ); +}; + +export default LoanRequestComponent; diff --git a/src/components/dashboard/refahi/followUp-loan/index.jsx b/src/components/dashboard/refahi/followUp-loan/index.jsx new file mode 100644 index 0000000..cda243c --- /dev/null +++ b/src/components/dashboard/refahi/followUp-loan/index.jsx @@ -0,0 +1,123 @@ +import DashboardLayouts from "@/layouts/dashboardLayouts"; +import useUser from "@/lib/app/hooks/useUser"; +import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +import { + Avatar, + Card, + CardActions, + CardContent, + CardHeader, + Collapse, + Grid, + IconButton, + Stack, + Typography +} from "@mui/material"; +import {styled} from "@mui/material/styles"; +import {useTranslations} from "next-intl"; +import {useState} from "react"; + +const ExpandMore = styled((props) => { + const {expand, ...other} = props; + return ; +})(({theme, expand}) => ({ + transform: !expand ? "rotate(0deg)" : "rotate(180deg)", + marginLeft: "auto", + transition: theme.transitions.create("transform", { + duration: theme.transitions.duration.shortest, + }), +})); + +const data = [ + { + name: "جان دو", + date: "۱۳۹۹/۰۴/۲۵", + description: + "لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است.", + }, + { + name: "جین اسمیت", + date: "۱۳۹۹/۰۴/۲۶", + description: "نُلا ویته الیت لیبرو آ، آ فارِترا آوگوه.", + }, + { + name: "مایک جانسون", + date: "۱۳۹۹/۰۴/۲۷", + description: + "دوئیس مولیس، است نُن کُمُدو لُکتوس، نیسی ارات پورتیتور لیگولا.", + }, +]; + +const LoanFollowUpComponent = () => { + const t = useTranslations(); + const {token} = useUser(); + + const [expanded, setExpanded] = useState([]); + + const handleExpandClick = (index) => { + setExpanded((prevExpanded) => { + const newExpanded = [...prevExpanded]; + newExpanded[index] = !newExpanded[index]; + return newExpanded; + }); + }; + + return ( + + + + {data.map((item, index) => ( + + + + } + title={item.name} + subheader={item.date} + /> + + + متن تست + + + + handleExpandClick(index)} + aria-expanded={expanded[index]} + aria-label="show more" + > + + + + + + اطلاعات تکمیلی: + {item.description} + + + + + ))} + + + + ); +}; + +export default LoanFollowUpComponent; diff --git a/src/core/components/SelectBox.jsx b/src/core/components/SelectBox.jsx index 4d10b5e..a24484c 100644 --- a/src/core/components/SelectBox.jsx +++ b/src/core/components/SelectBox.jsx @@ -10,6 +10,8 @@ function SelectBox({ error, helperText, }) { + + const selectId = String(select); const handleChange = (event) => { setFieldValue(selectType, event.target.value); }; @@ -28,8 +30,8 @@ function SelectBox({ {label}