From f15f4fc23015d27daa73f92d1caaae4256237d52 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Mon, 19 May 2025 16:36:23 +0330 Subject: [PATCH 1/4] edit refahi --- .../dashboard/followUp-loan/RequestCard.jsx | 6 +- .../dashboard/followUp-loan/index.jsx | 6 +- .../dashboard/navgan/show/index.jsx | 5 +- .../add-request-loan/RefahiLoanType.jsx | 2 - .../forms/BuildForm/BuildFormController.jsx | 63 +++++++++ .../forms/BuildForm/BuildRequestDetail.jsx | 67 +-------- .../forms/BuildForm/index.jsx | 126 ++++++++++------- .../RestoreForm/RestoreFormController.jsx | 65 +++++++++ .../RestoreForm/RestoreRequestDetail.jsx | 66 +-------- .../forms/RestoreForm/index.jsx | 125 +++++++++-------- .../refahi/add-request-loan/index.jsx | 2 +- .../dashboard/refahi/show/form/index.jsx | 132 ++++++++++++++++++ .../dashboard/refahi/show/index.jsx | 10 ++ src/core/data/apiRoutes.js | 1 + src/pages/dashboard/followUp-loan/index.jsx | 2 +- .../dashboard/refahi/[id]/show/index.jsx | 18 +++ 16 files changed, 442 insertions(+), 254 deletions(-) create mode 100644 src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx create mode 100644 src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx create mode 100644 src/components/dashboard/refahi/show/form/index.jsx create mode 100644 src/components/dashboard/refahi/show/index.jsx create mode 100644 src/pages/dashboard/refahi/[id]/show/index.jsx diff --git a/src/components/dashboard/followUp-loan/RequestCard.jsx b/src/components/dashboard/followUp-loan/RequestCard.jsx index 62ab5c7..6d6dc57 100644 --- a/src/components/dashboard/followUp-loan/RequestCard.jsx +++ b/src/components/dashboard/followUp-loan/RequestCard.jsx @@ -7,7 +7,7 @@ import CancelIcon from "@mui/icons-material/Cancel"; import EditIcon from "@mui/icons-material/Edit"; import PendingIcon from "@mui/icons-material/Pending"; -const RequestCard = ({ item }) => { +const RequestCard = ({ item, id }) => { const t = useTranslations(); return ( @@ -115,13 +115,13 @@ const RequestCard = ({ item }) => { {item.state_id === 17 ? ( ) : ( diff --git a/src/components/dashboard/followUp-loan/index.jsx b/src/components/dashboard/followUp-loan/index.jsx index db402b4..afa0546 100644 --- a/src/components/dashboard/followUp-loan/index.jsx +++ b/src/components/dashboard/followUp-loan/index.jsx @@ -1,7 +1,7 @@ import { Box, Chip, Divider, Grid, Skeleton, Stack, Typography } from "@mui/material"; import { useEffect, useState } from "react"; import { SHOW_LOAN_REQUEST_NAVGAN, SHOW_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; -import RequestCard from "@/components/dashboard/followUp-loan/RequestCard"; +import RequestCard from "./RequestCard"; import { FullPageLayout, useRequest } from "@witel/webapp-builder"; import DirectionsCarIcon from "@mui/icons-material/DirectionsCar"; import VolunteerActivismIcon from "@mui/icons-material/VolunteerActivism"; @@ -74,7 +74,7 @@ const LoanFollowUpComponent = () => { {navganFollowUpList.map((item) => ( - + ))} @@ -124,7 +124,7 @@ const LoanFollowUpComponent = () => { {refahiFollowUpList.map((item) => ( - + ))} diff --git a/src/components/dashboard/navgan/show/index.jsx b/src/components/dashboard/navgan/show/index.jsx index 6dfeda9..284fa9f 100644 --- a/src/components/dashboard/navgan/show/index.jsx +++ b/src/components/dashboard/navgan/show/index.jsx @@ -1,10 +1,7 @@ -import { useTranslations } from "next-intl"; -import { CenterLayout, useUser } from "@witel/webapp-builder"; +import { CenterLayout } from "@witel/webapp-builder"; import ShowLoanForm from "@/components/dashboard/navgan/show/form"; const ShowLoan = () => { - const t = useTranslations(); - const { user } = useUser(); return ( diff --git a/src/components/dashboard/refahi/add-request-loan/RefahiLoanType.jsx b/src/components/dashboard/refahi/add-request-loan/RefahiLoanType.jsx index 8c1de45..961ba69 100644 --- a/src/components/dashboard/refahi/add-request-loan/RefahiLoanType.jsx +++ b/src/components/dashboard/refahi/add-request-loan/RefahiLoanType.jsx @@ -1,6 +1,4 @@ import { Button, Card, CardActions, CardContent, Stack, Typography } from "@mui/material"; -import DirectionsCarIcon from "@mui/icons-material/DirectionsCar"; -import VolunteerActivismIcon from "@mui/icons-material/VolunteerActivism"; import BuildIcon from "@mui/icons-material/Build"; import MapsHomeWorkIcon from "@mui/icons-material/MapsHomeWork"; import { useTranslations } from "next-intl"; diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx new file mode 100644 index 0000000..024ef2c --- /dev/null +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx @@ -0,0 +1,63 @@ +import { useReducer, useState } from "react"; +import { useTranslations } from "next-intl"; +import * as React from "react"; +import { Stack, Step, StepLabel, Stepper } from "@mui/material"; +import BuldToggleRealLegal from "./BuildToggleRealLegal"; +import BuildProjectInfo from "./BuildProjectInfo"; +import BuildRequestDetail from "./BuildRequestDetail"; +import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; + + +const BuildFormController = ({ handleSubmit, dispatch, state, submitting }) => { + const t = useTranslations(); + const [activeStep, setActiveStep] = useState(0); + const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); + const steps = [ + t("RefahiLoanRequest.step_personal_info"), + t("RefahiLoanRequest.step_project_info"), + t("RefahiLoanRequest.step_contact_info"), + ]; + const handleNext = () => setActiveStep((prev) => prev + 1); + const handleBack = () => setActiveStep((prev) => prev - 1); + return ( + + + {steps.map((label, index) => ( + + {label} + + ))} + + {activeStep === 0 && ( + + )} + {activeStep === 1 && ( + + )} + {activeStep === 2 && ( + + )} + + ); +}; +export default BuildFormController; diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx index 07f37b4..b340fda 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx @@ -8,17 +8,9 @@ import * as Yup from "yup"; import { useFormik } from "formik"; import PickerWithDynamicField from "@/core/components/EditedDatePicker"; import UploadImage from "./UploadImage"; -import { useRequest, useUser } from "@witel/webapp-builder"; -import { SEND_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; -import { useState } from "react"; -import { useRouter } from "next/router"; -const BuildRequestDetail = ({ state, handleBack, setFinishRefahiLoanRequest, dispatch }) => { +const BuildRequestDetail = ({ state, handleBack, handleSubmit, submitting }) => { const t = useTranslations(); - const [submitting, setSubmitting] = useState(false); - const requestServer = useRequest(); - const { getUser, changeUser } = useUser(); - const router = useRouter(); const initialValues = { requested_facility_amount: state.requested_facility_amount, @@ -75,63 +67,6 @@ const BuildRequestDetail = ({ state, handleBack, setFinishRefahiLoanRequest, dis .required(t("LoanRequest.checkbox_required")), }); - const handleSubmit = async (values) => { - let updatedState = { ...state, ...values }; - dispatch({ type: "SET_REQUEST_INFO", requestInfo: values }); - const formData = new FormData(); - const is_legal_person = updatedState.person_type === "real" ? 0 : 1; - delete updatedState.person_type; - if (updatedState.national_serial_number_or_tracking_code === "national_serial_number") { - formData.append("national_serial_number", updatedState.national_serial_number); - delete updatedState.national_card_tracking_code; - } else { - formData.append("national_tracking_code", updatedState.national_card_tracking_code); - delete updatedState.national_serial_number; - } - delete updatedState.national_serial_number_or_tracking_code; - delete updatedState.checkedBox; - formData.append("is_legal_person", is_legal_person); - - updatedState = { - ...updatedState, - birthday: updatedState.birthday.locale("en").format("YYYY-MM-DD"), - basic_approval_renewal_date: updatedState.basic_approval_renewal_date.locale("en").format("YYYY-MM-DD"), - company_register_date: updatedState.company_register_date - ? updatedState.company_register_date.locale("en").format("YYYY-MM-DD") - : "", - facility_usage_history: updatedState.facility_usage_history ? 1 : 0, - }; - - Object.keys(updatedState).forEach((key) => { - if (updatedState[key] !== null && updatedState[key] !== undefined) { - formData.append(key, updatedState[key]); - } - }); - if (!is_legal_person) { - formData.delete("company_register_date"); - formData.delete("shenase_meli"); - formData.delete("register_number"); - formData.delete("company_name"); - } - - try { - setSubmitting(true); - await requestServer(SEND_LOAN_REQUEST_REFAHI, "post", { - auth: true, - notification: true, - data: formData, - }); - // router.replace("/dashboard/followUp-loan"); - getUser((data) => { - changeUser(data); - setFinishRefahiLoanRequest(true); - }); - } catch (error) { - console.error("Error submitting request:", error); - } finally { - setSubmitting(false); - } - }; const formik = useFormik({ initialValues, diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/index.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/index.jsx index 5ff93c7..84a7d61 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/index.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/index.jsx @@ -1,11 +1,8 @@ import { useReducer, useState } from "react"; -import { useTranslations } from "next-intl"; import * as React from "react"; -import { Stack, Step, StepLabel, Stepper } from "@mui/material"; -import BuldToggleRealLegal from "./BuildToggleRealLegal"; -import BuildProjectInfo from "./BuildProjectInfo"; -import BuildRequestDetail from "./BuildRequestDetail"; -import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; +import { SEND_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; +import { useRequest, useUser } from "@witel/webapp-builder"; +import BuildFormController from "./BuildFormController"; const _data = { person_type: "real", @@ -68,56 +65,77 @@ const reducer = (state, action) => { }; const BuildForm = ({ setFinishRefahiLoanRequest }) => { - const t = useTranslations(); - const [activeStep, setActiveStep] = useState(0); + const [submitting, setSubmitting] = useState(false); const [state, dispatch] = useReducer(reducer, _data); - const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); - const steps = [ - t("RefahiLoanRequest.step_personal_info"), - t("RefahiLoanRequest.step_project_info"), - t("RefahiLoanRequest.step_contact_info"), - ]; - const handleNext = () => setActiveStep((prev) => prev + 1); - const handleBack = () => setActiveStep((prev) => prev - 1); + const requestServer = useRequest(); + const { getUser, changeUser } = useUser(); + + const handleSubmit = async (values) => { + let updatedState = { ...state, ...values }; + dispatch({ type: "SET_REQUEST_INFO", requestInfo: values }); + const formData = new FormData(); + const is_legal_person = updatedState.person_type === "real" ? 0 : 1; + delete updatedState.person_type; + if (updatedState.national_serial_number_or_tracking_code === "national_serial_number") { + formData.append("national_serial_number", updatedState.national_serial_number); + delete updatedState.national_card_tracking_code; + } else { + formData.append("national_tracking_code", updatedState.national_card_tracking_code); + delete updatedState.national_serial_number; + } + delete updatedState.national_serial_number_or_tracking_code; + delete updatedState.checkedBox; + formData.append("is_legal_person", is_legal_person); + + updatedState = { + ...updatedState, + birthday: updatedState.birthday.locale("en").format("YYYY-MM-DD"), + basic_approval_renewal_date: updatedState.basic_approval_renewal_date.locale("en").format("YYYY-MM-DD"), + company_register_date: updatedState.company_register_date + ? updatedState.company_register_date.locale("en").format("YYYY-MM-DD") + : "", + facility_usage_history: updatedState.facility_usage_history ? 1 : 0, + }; + + Object.keys(updatedState).forEach((key) => { + if (updatedState[key] !== null && updatedState[key] !== undefined) { + formData.append(key, updatedState[key]); + } + }); + if (!is_legal_person) { + formData.delete("company_register_date"); + formData.delete("shenase_meli"); + formData.delete("register_number"); + formData.delete("company_name"); + } + + try { + setSubmitting(true); + await requestServer(SEND_LOAN_REQUEST_REFAHI, "post", { + auth: true, + notification: true, + data: formData, + }); + getUser((data) => { + changeUser(data); + setFinishRefahiLoanRequest(true); + }); + } catch (error) { + console.error("Error submitting request:", error); + } finally { + setSubmitting(false); + } + }; return ( - - - {steps.map((label, index) => ( - - {label} - - ))} - - {activeStep === 0 && ( - - )} - {activeStep === 1 && ( - - )} - {activeStep === 2 && ( - - )} - + <> + + ); }; export default BuildForm; diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx new file mode 100644 index 0000000..2b446ae --- /dev/null +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx @@ -0,0 +1,65 @@ +import { useReducer, useState } from "react"; +import { useTranslations } from "next-intl"; +import * as React from "react"; +import { Stack, Step, StepLabel, Stepper } from "@mui/material"; +import RestoreProjectInfo from "./RestoreProjectInfo"; +import RestoreRequestDetail from "./RestoreRequestDetail"; +import RestoreToggleRealLegal from "./RestoreToggleRealLegal"; +import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; + + +const RestoreFormController = ({ state, dispatch, handleSubmit, submitting }) => { + console.log(state); + const t = useTranslations(); + const [activeStep, setActiveStep] = useState(0); + const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); + const steps = [ + t("RefahiLoanRequest.step_personal_info"), + t("RefahiLoanRequest.step_project_info"), + t("RefahiLoanRequest.step_contact_info"), + ]; + const handleNext = () => setActiveStep((prev) => prev + 1); + const handleBack = () => setActiveStep((prev) => prev - 1); + return ( + + + {steps.map((label, index) => ( + + {label} + + ))} + + {activeStep === 0 && ( + + )} + {activeStep === 1 && ( + + )} + {activeStep === 2 && ( + + )} + + ); +}; +export default RestoreFormController; diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx index 3615fac..3d631e9 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx @@ -13,12 +13,8 @@ import { useState } from "react"; import { useRequest, useUser } from "@witel/webapp-builder"; import { useRouter } from "next/router"; -const RestoreRequestDetail = ({ state, handleBack, dispatch, setFinishRefahiLoanRequest }) => { +const RestoreRequestDetail = ({ state, handleBack, handleSubmit, submitting }) => { const t = useTranslations(); - const [submitting, setSubmitting] = useState(false); - const requestServer = useRequest(); - const { getUser, changeUser } = useUser(); - const router = useRouter(); const initialValues = { requested_facility_amount: state.requested_facility_amount, @@ -68,66 +64,6 @@ const RestoreRequestDetail = ({ state, handleBack, dispatch, setFinishRefahiLoan .oneOf([true], t("LoanRequest.checkbox_required")) .required(t("LoanRequest.checkbox_required")), }); - const handleSubmit = async (values, props) => { - let updatedState = { ...state, ...values }; - dispatch({ type: "SET_REQUEST_INFO", requestInfo: values }); - const formData = new FormData(); - const is_legal_person = updatedState.person_type === "real" ? 0 : 1; - delete updatedState.person_type; - if (updatedState.national_serial_number_or_tracking_code === "national_serial_number") { - formData.append("national_serial_number", updatedState.national_serial_number); - delete updatedState.national_card_tracking_code; - } else { - formData.append("national_tracking_code", updatedState.national_card_tracking_code); - delete updatedState.national_serial_number; - } - delete updatedState.national_serial_number_or_tracking_code; - delete updatedState.checkedBox; - formData.append("is_legal_person", is_legal_person); - - updatedState = { - ...updatedState, - birthday: updatedState.birthday.locale("en").format("YYYY-MM-DD"), - exploitation_license_renewal_date: updatedState.exploitation_license_renewal_date - .locale("en") - .format("YYYY-MM-DD"), - exploitation_date: updatedState.exploitation_date.locale("en").format("YYYY-MM-DD"), - company_register_date: updatedState.company_register_date - ? updatedState.company_register_date.locale("en").format("YYYY-MM-DD") - : "", - facility_usage_history: updatedState.facility_usage_history ? 1 : 0, - }; - - Object.keys(updatedState).forEach((key) => { - if (updatedState[key] !== null && updatedState[key] !== undefined) { - formData.append(key, updatedState[key]); - } - }); - if (!is_legal_person) { - formData.delete("company_register_date"); - formData.delete("shenase_meli"); - formData.delete("register_number"); - formData.delete("company_name"); - } - - try { - setSubmitting(true); - await requestServer(SEND_LOAN_REQUEST_REFAHI, "post", { - auth: true, - notification: true, - data: formData, - }); - // router.replace("/dashboard/followUp-loan"); - getUser((data) => { - changeUser(data); - setFinishRefahiLoanRequest(true); - }); - } catch (error) { - console.error("Error submitting request:", error); - } finally { - setSubmitting(false); - } - }; const formik = useFormik({ initialValues, diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx index abb95c8..57e35db 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx @@ -1,11 +1,7 @@ import { useReducer, useState } from "react"; -import { useTranslations } from "next-intl"; -import * as React from "react"; -import { Stack, Step, StepLabel, Stepper } from "@mui/material"; -import RestoreProjectInfo from "./RestoreProjectInfo"; -import RestoreRequestDetail from "./RestoreRequestDetail"; -import RestoreToggleRealLegal from "./RestoreToggleRealLegal"; -import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; +import RestoreFormController from "./RestoreFormController"; +import { useRequest, useUser } from "@witel/webapp-builder"; +import { SEND_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; const _data = { person_type: "real", @@ -67,56 +63,75 @@ const reducer = (state, action) => { }; const RestoreForm = ({ setFinishRefahiLoanRequest }) => { - const t = useTranslations(); - const [activeStep, setActiveStep] = useState(0); - const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); + const [submitting, setSubmitting] = useState(false); const [state, dispatch] = useReducer(reducer, _data); - const steps = [ - t("RefahiLoanRequest.step_personal_info"), - t("RefahiLoanRequest.step_project_info"), - t("RefahiLoanRequest.step_contact_info"), - ]; - const handleNext = () => setActiveStep((prev) => prev + 1); - const handleBack = () => setActiveStep((prev) => prev - 1); + const requestServer = useRequest(); + const { getUser, changeUser } = useUser(); + + const handleSubmit = async (values, props) => { + let updatedState = { ...state, ...values }; + dispatch({ type: "SET_REQUEST_INFO", requestInfo: values }); + const formData = new FormData(); + const is_legal_person = updatedState.person_type === "real" ? 0 : 1; + delete updatedState.person_type; + if (updatedState.national_serial_number_or_tracking_code === "national_serial_number") { + formData.append("national_serial_number", updatedState.national_serial_number); + delete updatedState.national_card_tracking_code; + } else { + formData.append("national_tracking_code", updatedState.national_card_tracking_code); + delete updatedState.national_serial_number; + } + delete updatedState.national_serial_number_or_tracking_code; + delete updatedState.checkedBox; + formData.append("is_legal_person", is_legal_person); + + updatedState = { + ...updatedState, + birthday: updatedState.birthday.locale("en").format("YYYY-MM-DD"), + exploitation_license_renewal_date: updatedState.exploitation_license_renewal_date + .locale("en") + .format("YYYY-MM-DD"), + exploitation_date: updatedState.exploitation_date.locale("en").format("YYYY-MM-DD"), + company_register_date: updatedState.company_register_date + ? updatedState.company_register_date.locale("en").format("YYYY-MM-DD") + : "", + facility_usage_history: updatedState.facility_usage_history ? 1 : 0, + }; + + Object.keys(updatedState).forEach((key) => { + if (updatedState[key] !== null && updatedState[key] !== undefined) { + formData.append(key, updatedState[key]); + } + }); + if (!is_legal_person) { + formData.delete("company_register_date"); + formData.delete("shenase_meli"); + formData.delete("register_number"); + formData.delete("company_name"); + } + + try { + setSubmitting(true); + await requestServer(SEND_LOAN_REQUEST_REFAHI, "post", { + auth: true, + notification: true, + data: formData, + }); + getUser((data) => { + changeUser(data); + setFinishRefahiLoanRequest(true); + }); + } catch (error) { + console.error("Error submitting request:", error); + } finally { + setSubmitting(false); + } + }; + return ( - - - {steps.map((label, index) => ( - - {label} - - ))} - - {activeStep === 0 && ( - - )} - {activeStep === 1 && ( - - )} - {activeStep === 2 && ( - - )} - + <> + + ); }; export default RestoreForm; diff --git a/src/components/dashboard/refahi/add-request-loan/index.jsx b/src/components/dashboard/refahi/add-request-loan/index.jsx index 00a7d6d..8c9acab 100644 --- a/src/components/dashboard/refahi/add-request-loan/index.jsx +++ b/src/components/dashboard/refahi/add-request-loan/index.jsx @@ -27,7 +27,7 @@ const AddRequestLoan = () => { - diff --git a/src/components/dashboard/refahi/show/form/index.jsx b/src/components/dashboard/refahi/show/form/index.jsx new file mode 100644 index 0000000..fc395ba --- /dev/null +++ b/src/components/dashboard/refahi/show/form/index.jsx @@ -0,0 +1,132 @@ +import { useEffect, useReducer, useState } from "react"; +import { GET_LOAN_DETAILS_REFAHI, SEND_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; +import { useRouter } from "next/router"; +import { SvgLoading, useRequest, useUser } from "@witel/webapp-builder"; +import { Stack, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; +import BuildFormController from "@/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController"; +import RestoreFormController + from "@/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController"; + + +const reducer = (state, action) => { + switch (action.type) { + case "SET_PERSONAL_INFO": + return { ...state, ...action.personalInfo }; + case "SET_PROJECT_INFO": + return { ...state, ...action.projectInfo }; + case "SET_REQUEST_INFO": + return { ...state, ...action.requestInfo }; + case "SET_PERSON_TYPE": + return { ...state, person_type: action.person_type }; + default: + return state; + } +}; + + +const ShowLoanForm = () => { + const t = useTranslations(); + const { query } = useRouter(); + const [LoanDetails, setLoanDetails] = useState({}); + const [submitting, setSubmitting] = useState(false); + const requestServer = useRequest(); + const { getUser, changeUser } = useUser(); + + const isRefahi1 = LoanDetails.refahi_type === 1; + const isRefahi2 = LoanDetails.refahi_type === 2; + + const _data = { + person_type: LoanDetails.is_legal_person === 1 ? "legal" : "real", + telephone_number: LoanDetails.telephone_number || "", + activity_type_id: LoanDetails.activity_type_id || "", + refahi_type: LoanDetails.refahi_type || 1, + requested_facility_amount: LoanDetails.requested_facility_amount || "", + person_share: LoanDetails.person_share || "", + user_existing_employment: LoanDetails.user_existing_employment || "", + user_committed_employment: LoanDetails.user_committed_employment || "", + father_name: LoanDetails.father_name || "", + gender: LoanDetails.gender || "", + welfare_complex_degree: LoanDetails.welfare_complex_degree || "", + first_name: LoanDetails.first_name || "", + last_name: LoanDetails.last_name || "", + city_id: LoanDetails.city_id || "", + project_city_id: LoanDetails.project_city_id || "", + province_id: LoanDetails.province_id || "", + project_province_id: LoanDetails.project_province_id || "", + education_id: LoanDetails.education_id || "", + occupation_id: LoanDetails.occupation_id || "", + national_id: LoanDetails.national_id || "", + national_serial_number: LoanDetails.national_serial_number || "", + national_card_tracking_code: LoanDetails?.national_card_tracking_code || "", + national_serial_number_or_tracking_code: + LoanDetails.national_serial_number ? "national_serial_number" : "national_card_tracking_code", + postal_code: LoanDetails.postal_code || "", + address: LoanDetails.address || "", + birthday: LoanDetails.birthday || "", + investment_amount: LoanDetails.investment_amount || "", + checkedBox: false, + facility_usage_history: LoanDetails.facility_usage_history || false, + company_register_date: LoanDetails.company_register_date || "", + shenase_meli: LoanDetails.shenase_meli || "", + register_number: LoanDetails.register_number || "", + company_name: LoanDetails.company_name || "", + + ...(isRefahi1 && { + basic_approval_number: LoanDetails.basic_approval_number || "", + basic_approval_renewal_date: LoanDetails.basic_approval_renewal_date || "", + basic_approval_renewal_image: LoanDetails.basic_approval_renewal_image || null, + basic_approval_image: LoanDetails.basic_approval_image || null, + project_axis: LoanDetails.project_axis || "", + project_physical_progress: LoanDetails.project_physical_progress || "", + project_kilometer_marker: LoanDetails.project_kilometer_marker || "", + project_direction: LoanDetails.project_direction || "", + project_address: LoanDetails.project_address || "", + }), + + ...(isRefahi2 && { + exploitation_date: LoanDetails.exploitation_date || "", + exploitation_license_renewal_date: LoanDetails.exploitation_license_renewal_date || "", + exploitation_license_image: LoanDetails.exploitation_license_image || null, + exploitation_license_renewal_image: LoanDetails.exploitation_license_renewal_image || null, + project_axis: LoanDetails.project_axis || "", + project_kilometer_marker: LoanDetails.project_kilometer_marker || "", + project_direction: LoanDetails.project_direction || "", + project_address: LoanDetails.project_address || "", + }), + }; + + const [state, dispatch] = useReducer(reducer, _data); + + useEffect(() => { + requestServer(GET_LOAN_DETAILS_REFAHI + query.id, "get", { auth: true, notification: false }) + .then(({ data }) => { + setLoanDetails(data.data); + }) + .catch(() => {}); + }, []); + + + if (Object.keys(LoanDetails).length === 0) { + return ( + + + {t("ShowLoan.loading_show_component")} + + ); + } + + const handleSubmit = async (values) => { + console.log(values); + }; + return ( + <> + {LoanDetails.refahi_type === 1 ? ( + + ) : ( + + )} + + ); +}; +export default ShowLoanForm; diff --git a/src/components/dashboard/refahi/show/index.jsx b/src/components/dashboard/refahi/show/index.jsx new file mode 100644 index 0000000..99b6c7e --- /dev/null +++ b/src/components/dashboard/refahi/show/index.jsx @@ -0,0 +1,10 @@ +import ShowLoanForm from "./form"; + +const ShowLoan = () => { + + return ( + + ); +}; + +export default ShowLoan; diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 31393e8..435777d 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -23,6 +23,7 @@ export const GET_EDUCATIONS_LIST = BASE_URL + "/education"; export const GET_OCCUPATIONS_LIST = BASE_URL + "/occupations"; export const GET_LOAN_DETAILS = BASE_URL + "/navgan/loan/details/"; +export const GET_LOAN_DETAILS_REFAHI = BASE_URL + "/refahi/loan/details/"; export const UPDATE_LOAN = BASE_URL + "/navgan/loan/update/"; export const GET_PROJECT_TITLE = BASE_URL + "/navgan_plans"; diff --git a/src/pages/dashboard/followUp-loan/index.jsx b/src/pages/dashboard/followUp-loan/index.jsx index e8d9112..3047966 100644 --- a/src/pages/dashboard/followUp-loan/index.jsx +++ b/src/pages/dashboard/followUp-loan/index.jsx @@ -1,4 +1,4 @@ -import LoanFollowUpComponent from "src/components/dashboard/followUp-loan"; +import LoanFollowUpComponent from "@/components/dashboard/followUp-loan"; import { globalServerProps } from "@/core/utils/globalServerProps"; export default function FollowUpLoan() { diff --git a/src/pages/dashboard/refahi/[id]/show/index.jsx b/src/pages/dashboard/refahi/[id]/show/index.jsx new file mode 100644 index 0000000..17ae10d --- /dev/null +++ b/src/pages/dashboard/refahi/[id]/show/index.jsx @@ -0,0 +1,18 @@ +import { parse } from "next-useragent"; +import ShowLoan from "@/components/dashboard/refahi/show"; +import { globalServerProps } from "@/core/utils/globalServerProps"; + +export default function ShowLoanRequest() { + return ; +} + +export async function getServerSideProps({ req, locale }) { + const { isBot } = parse(req.headers["user-agent"]); + return { + props: { + ...(await globalServerProps({ req, locale })), + title: "ShowLoan.show_loan_page", + layout: { name: "DashboardLayout" }, + }, + }; +} From da3c1ca582f973ab01b2453441f25c39ad005f91 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Tue, 20 May 2025 11:38:54 +0330 Subject: [PATCH 2/4] formatting --- .../dashboard/navgan/show/index.jsx | 1 - .../forms/BuildForm/BuildFormController.jsx | 4 +- .../forms/BuildForm/BuildRequestDetail.jsx | 25 +-- .../forms/BuildForm/UploadImage.jsx | 8 +- .../RestoreForm/RestoreFormController.jsx | 5 +- .../RestoreForm/RestoreRequestDetail.jsx | 28 ++- .../forms/RestoreForm/index.jsx | 7 +- .../dashboard/refahi/show/form/index.jsx | 196 +++++++++--------- .../dashboard/refahi/show/index.jsx | 99 ++++++++- .../first/LoanDescription/index.jsx | 28 +-- src/core/data/apiRoutes.js | 1 + 11 files changed, 248 insertions(+), 154 deletions(-) diff --git a/src/components/dashboard/navgan/show/index.jsx b/src/components/dashboard/navgan/show/index.jsx index 284fa9f..73c98eb 100644 --- a/src/components/dashboard/navgan/show/index.jsx +++ b/src/components/dashboard/navgan/show/index.jsx @@ -2,7 +2,6 @@ import { CenterLayout } from "@witel/webapp-builder"; import ShowLoanForm from "@/components/dashboard/navgan/show/form"; const ShowLoan = () => { - return ( diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx index 024ef2c..cbd99f6 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController.jsx @@ -7,8 +7,7 @@ import BuildProjectInfo from "./BuildProjectInfo"; import BuildRequestDetail from "./BuildRequestDetail"; import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; - -const BuildFormController = ({ handleSubmit, dispatch, state, submitting }) => { +const BuildFormController = ({ handleSubmit, dispatch, state, submitting, editDisabled }) => { const t = useTranslations(); const [activeStep, setActiveStep] = useState(0); const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); @@ -55,6 +54,7 @@ const BuildFormController = ({ handleSubmit, dispatch, state, submitting }) => { handleBack={handleBack} handleSubmit={handleSubmit} submitting={submitting} + editDisabled={editDisabled} /> )} diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx index b340fda..7e11a0f 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildRequestDetail.jsx @@ -9,7 +9,7 @@ import { useFormik } from "formik"; import PickerWithDynamicField from "@/core/components/EditedDatePicker"; import UploadImage from "./UploadImage"; -const BuildRequestDetail = ({ state, handleBack, handleSubmit, submitting }) => { +const BuildRequestDetail = ({ state, handleBack, handleSubmit, submitting, editDisabled }) => { const t = useTranslations(); const initialValues = { @@ -67,7 +67,6 @@ const BuildRequestDetail = ({ state, handleBack, handleSubmit, submitting }) => .required(t("LoanRequest.checkbox_required")), }); - const formik = useFormik({ initialValues, validationSchema, @@ -387,16 +386,18 @@ const BuildRequestDetail = ({ state, handleBack, handleSubmit, submitting }) => > {t("RefahiLoanRequest.back-button")} - + {editDisabled === 17 && ( + + )} ); diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/UploadImage.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/UploadImage.jsx index 9a4c2e8..811a572 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/UploadImage.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/UploadImage.jsx @@ -3,14 +3,14 @@ import * as React from "react"; import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; import { useState } from "react"; import { useTranslations } from "next-intl"; -import { FormHelperText, Stack } from "@mui/material"; +import { FormHelperText } from "@mui/material"; const UploadImage = ({ formik, fieldName }) => { const t = useTranslations(); - const [selectedImage, setSelectedImage] = useState(""); - const [fileType, setFileType] = useState(null); + const [selectedImage, setSelectedImage] = useState(formik.values[fieldName] ? formik.values[fieldName] : ""); + const [fileType, setFileType] = useState(formik.values[fieldName] ? "image/" : null); const [fileName, setFileName] = useState(null); - const [showAddIcon, setShowAddIcon] = useState(true); + const [showAddIcon, setShowAddIcon] = useState(!formik.values[fieldName]); const handleUploadChange = (event) => { const uploadedFile = event.target?.files?.[0]; if (uploadedFile) { diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx index 2b446ae..b14188a 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController.jsx @@ -7,9 +7,7 @@ import RestoreRequestDetail from "./RestoreRequestDetail"; import RestoreToggleRealLegal from "./RestoreToggleRealLegal"; import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; - -const RestoreFormController = ({ state, dispatch, handleSubmit, submitting }) => { - console.log(state); +const RestoreFormController = ({ state, dispatch, handleSubmit, submitting, editDisabled }) => { const t = useTranslations(); const [activeStep, setActiveStep] = useState(0); const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); @@ -57,6 +55,7 @@ const RestoreFormController = ({ state, dispatch, handleSubmit, submitting }) => handleBack={handleBack} handleSubmit={handleSubmit} submitting={submitting} + editDisabled={editDisabled} /> )} diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx index 3d631e9..7e8f7bc 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreRequestDetail.jsx @@ -8,12 +8,8 @@ import * as Yup from "yup"; import { useFormik } from "formik"; import PickerWithDynamicField from "@/core/components/EditedDatePicker"; import UploadImage from "@/components/dashboard/refahi/add-request-loan/forms/BuildForm/UploadImage"; -import { SEND_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; -import { useState } from "react"; -import { useRequest, useUser } from "@witel/webapp-builder"; -import { useRouter } from "next/router"; -const RestoreRequestDetail = ({ state, handleBack, handleSubmit, submitting }) => { +const RestoreRequestDetail = ({ state, handleBack, handleSubmit, submitting, editDisabled }) => { const t = useTranslations(); const initialValues = { @@ -336,16 +332,18 @@ const RestoreRequestDetail = ({ state, handleBack, handleSubmit, submitting }) = > {t("RefahiLoanRequest.back-button")} - + {editDisabled === 17 && ( + + )} ); diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx index 57e35db..4dfa48a 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/index.jsx @@ -130,7 +130,12 @@ const RestoreForm = ({ setFinishRefahiLoanRequest }) => { return ( <> - + ); }; diff --git a/src/components/dashboard/refahi/show/form/index.jsx b/src/components/dashboard/refahi/show/form/index.jsx index fc395ba..41a575e 100644 --- a/src/components/dashboard/refahi/show/form/index.jsx +++ b/src/components/dashboard/refahi/show/form/index.jsx @@ -1,13 +1,9 @@ -import { useEffect, useReducer, useState } from "react"; -import { GET_LOAN_DETAILS_REFAHI, SEND_LOAN_REQUEST_REFAHI } from "@/core/data/apiRoutes"; -import { useRouter } from "next/router"; -import { SvgLoading, useRequest, useUser } from "@witel/webapp-builder"; -import { Stack, Typography } from "@mui/material"; -import { useTranslations } from "next-intl"; +import { useReducer, useState } from "react"; +import { useRequest, useUser } from "@witel/webapp-builder"; import BuildFormController from "@/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildFormController"; -import RestoreFormController - from "@/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController"; - +import RestoreFormController from "@/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreFormController"; +import { UPDATE_LOAN_REFAHI } from "@/core/data/apiRoutes"; +import { useRouter } from "next/router"; const reducer = (state, action) => { switch (action.type) { @@ -24,107 +20,105 @@ const reducer = (state, action) => { } }; - -const ShowLoanForm = () => { - const t = useTranslations(); - const { query } = useRouter(); - const [LoanDetails, setLoanDetails] = useState({}); +const ShowLoanForm = ({ defaultData, refahi_type, queryID, editDisabled }) => { const [submitting, setSubmitting] = useState(false); const requestServer = useRequest(); + const router = useRouter(); const { getUser, changeUser } = useUser(); - - const isRefahi1 = LoanDetails.refahi_type === 1; - const isRefahi2 = LoanDetails.refahi_type === 2; - - const _data = { - person_type: LoanDetails.is_legal_person === 1 ? "legal" : "real", - telephone_number: LoanDetails.telephone_number || "", - activity_type_id: LoanDetails.activity_type_id || "", - refahi_type: LoanDetails.refahi_type || 1, - requested_facility_amount: LoanDetails.requested_facility_amount || "", - person_share: LoanDetails.person_share || "", - user_existing_employment: LoanDetails.user_existing_employment || "", - user_committed_employment: LoanDetails.user_committed_employment || "", - father_name: LoanDetails.father_name || "", - gender: LoanDetails.gender || "", - welfare_complex_degree: LoanDetails.welfare_complex_degree || "", - first_name: LoanDetails.first_name || "", - last_name: LoanDetails.last_name || "", - city_id: LoanDetails.city_id || "", - project_city_id: LoanDetails.project_city_id || "", - province_id: LoanDetails.province_id || "", - project_province_id: LoanDetails.project_province_id || "", - education_id: LoanDetails.education_id || "", - occupation_id: LoanDetails.occupation_id || "", - national_id: LoanDetails.national_id || "", - national_serial_number: LoanDetails.national_serial_number || "", - national_card_tracking_code: LoanDetails?.national_card_tracking_code || "", - national_serial_number_or_tracking_code: - LoanDetails.national_serial_number ? "national_serial_number" : "national_card_tracking_code", - postal_code: LoanDetails.postal_code || "", - address: LoanDetails.address || "", - birthday: LoanDetails.birthday || "", - investment_amount: LoanDetails.investment_amount || "", - checkedBox: false, - facility_usage_history: LoanDetails.facility_usage_history || false, - company_register_date: LoanDetails.company_register_date || "", - shenase_meli: LoanDetails.shenase_meli || "", - register_number: LoanDetails.register_number || "", - company_name: LoanDetails.company_name || "", - - ...(isRefahi1 && { - basic_approval_number: LoanDetails.basic_approval_number || "", - basic_approval_renewal_date: LoanDetails.basic_approval_renewal_date || "", - basic_approval_renewal_image: LoanDetails.basic_approval_renewal_image || null, - basic_approval_image: LoanDetails.basic_approval_image || null, - project_axis: LoanDetails.project_axis || "", - project_physical_progress: LoanDetails.project_physical_progress || "", - project_kilometer_marker: LoanDetails.project_kilometer_marker || "", - project_direction: LoanDetails.project_direction || "", - project_address: LoanDetails.project_address || "", - }), - - ...(isRefahi2 && { - exploitation_date: LoanDetails.exploitation_date || "", - exploitation_license_renewal_date: LoanDetails.exploitation_license_renewal_date || "", - exploitation_license_image: LoanDetails.exploitation_license_image || null, - exploitation_license_renewal_image: LoanDetails.exploitation_license_renewal_image || null, - project_axis: LoanDetails.project_axis || "", - project_kilometer_marker: LoanDetails.project_kilometer_marker || "", - project_direction: LoanDetails.project_direction || "", - project_address: LoanDetails.project_address || "", - }), - }; - - const [state, dispatch] = useReducer(reducer, _data); - - useEffect(() => { - requestServer(GET_LOAN_DETAILS_REFAHI + query.id, "get", { auth: true, notification: false }) - .then(({ data }) => { - setLoanDetails(data.data); - }) - .catch(() => {}); - }, []); - - - if (Object.keys(LoanDetails).length === 0) { - return ( - - - {t("ShowLoan.loading_show_component")} - - ); - } + const [state, dispatch] = useReducer(reducer, defaultData); const handleSubmit = async (values) => { - console.log(values); + let updatedState = { ...state, ...values }; + dispatch({ type: "SET_REQUEST_INFO", requestInfo: values }); + + const formData = new FormData(); + const is_legal_person = updatedState.person_type === "real" ? 0 : 1; + delete updatedState.person_type; + + if (updatedState.national_serial_number_or_tracking_code === "national_serial_number") { + formData.append("national_serial_number", updatedState.national_serial_number); + delete updatedState.national_card_tracking_code; + } else { + formData.append("national_tracking_code", updatedState.national_card_tracking_code); + delete updatedState.national_serial_number; + } + delete updatedState.national_serial_number_or_tracking_code; + delete updatedState.checkedBox; + + formData.append("is_legal_person", is_legal_person); + + // بررسی نوع درخواست رفاهی + const isType1 = updatedState.refahi_type === 1; + + updatedState = { + ...updatedState, + birthday: updatedState.birthday.locale("en").format("YYYY-MM-DD"), + ...(isType1 + ? { + basic_approval_renewal_date: updatedState.basic_approval_renewal_date + .locale("en") + .format("YYYY-MM-DD"), + } + : { + exploitation_license_renewal_date: updatedState.exploitation_license_renewal_date + .locale("en") + .format("YYYY-MM-DD"), + exploitation_date: updatedState.exploitation_date.locale("en").format("YYYY-MM-DD"), + }), + company_register_date: updatedState.company_register_date + ? updatedState.company_register_date.locale("en").format("YYYY-MM-DD") + : "", + facility_usage_history: updatedState.facility_usage_history ? 1 : 0, + }; + + Object.keys(updatedState).forEach((key) => { + if (updatedState[key] !== null && updatedState[key] !== undefined) { + formData.append(key, updatedState[key]); + } + }); + + if (!is_legal_person) { + formData.delete("company_register_date"); + formData.delete("shenase_meli"); + formData.delete("register_number"); + formData.delete("company_name"); + } + + try { + setSubmitting(true); + await requestServer(UPDATE_LOAN_REFAHI + queryID, "post", { + auth: true, + notification: true, + data: formData, + }); + getUser((data) => { + changeUser(data); + }); + router.push("/dashboard/followUp_loan"); + } catch (error) { + console.error("Error submitting request:", error); + } finally { + setSubmitting(false); + } }; return ( <> - {LoanDetails.refahi_type === 1 ? ( - + {refahi_type === 1 ? ( + ) : ( - + )} ); diff --git a/src/components/dashboard/refahi/show/index.jsx b/src/components/dashboard/refahi/show/index.jsx index 99b6c7e..7876f12 100644 --- a/src/components/dashboard/refahi/show/index.jsx +++ b/src/components/dashboard/refahi/show/index.jsx @@ -1,9 +1,106 @@ import ShowLoanForm from "./form"; +import { useEffect, useState } from "react"; +import { GET_LOAN_DETAILS_REFAHI } from "@/core/data/apiRoutes"; +import { CenterLayout, useRequest } from "@witel/webapp-builder"; +import { useRouter } from "next/router"; +import SvgLoading from "@/core/components/svgs/SvgLoading"; +import { Stack, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; +import moment from "jalali-moment"; const ShowLoan = () => { + const t = useTranslations(); + const requestServer = useRequest(); + const { query } = useRouter(); + const [LoanDetails, setLoanDetails] = useState({}); + const [LoanDetailsLoading, setLoanDetailsLoading] = useState(true); + const isRefahi1 = LoanDetails.refahi_type === 1; + const isRefahi2 = LoanDetails.refahi_type === 2; + const _data = { + person_type: LoanDetails?.is_legal_person === 1 ? "legal" : "real", + telephone_number: LoanDetails?.telephone_number || "", + activity_type_id: LoanDetails?.activity_type_id || "", + refahi_type: LoanDetails?.refahi_type || 1, + requested_facility_amount: LoanDetails?.requested_facility_amount || "", + person_share: LoanDetails?.person_share || "", + user_existing_employment: LoanDetails?.user_existing_employment || "", + user_committed_employment: LoanDetails?.user_committed_employment || "", + father_name: LoanDetails?.father_name || "", + gender: LoanDetails?.gender || "", + welfare_complex_degree: LoanDetails?.welfare_complex_degree || "", + first_name: LoanDetails?.first_name || "", + last_name: LoanDetails?.last_name || "", + city_id: LoanDetails?.city_id || "", + project_city_id: LoanDetails?.project_city_id || "", + province_id: LoanDetails?.province_id || "", + project_province_id: LoanDetails?.project_province_id || "", + education_id: LoanDetails?.education_id || "", + occupation_id: LoanDetails?.occupation_id || "", + national_id: LoanDetails?.national_id || "", + national_serial_number: LoanDetails?.national_serial_number || "", + national_card_tracking_code: LoanDetails?.national_card_tracking_code || "", + national_serial_number_or_tracking_code: LoanDetails?.national_serial_number + ? "national_serial_number" + : "national_card_tracking_code", + postal_code: LoanDetails?.postal_code || "", + address: LoanDetails?.address || "", + birthday: moment(LoanDetails?.birthday) || "", + investment_amount: LoanDetails?.investment_amount || "", + checkedBox: false, + facility_usage_history: LoanDetails?.facility_usage_history || false, + company_register_date: moment(LoanDetails?.company_register_date) || "", + shenase_meli: LoanDetails?.shenase_meli || "", + register_number: LoanDetails?.register_number || "", + company_name: LoanDetails?.company_name || "", + + ...(isRefahi1 && { + basic_approval_number: LoanDetails?.basic_approval_number || "", + basic_approval_renewal_date: moment(LoanDetails?.basic_approval_renewal_date) || "", + basic_approval_renewal_image: LoanDetails?.basic_approval_renewal_image || null, + basic_approval_image: LoanDetails?.basic_approval_image || null, + project_axis: LoanDetails?.project_axis || "", + project_physical_progress: LoanDetails?.project_physical_progress || "", + project_kilometer_marker: LoanDetails?.project_kilometer_marker || "", + project_direction: LoanDetails?.project_direction || "", + project_address: LoanDetails?.project_address || "", + }), + + ...(isRefahi2 && { + exploitation_date: moment(LoanDetails?.exploitation_date) || "", + exploitation_license_renewal_date: moment(LoanDetails?.exploitation_license_renewal_date) || "", + exploitation_license_image: LoanDetails?.exploitation_license_image || null, + exploitation_license_renewal_image: LoanDetails?.exploitation_license_renewal_image || null, + project_axis: LoanDetails?.project_axis || "", + project_kilometer_marker: LoanDetails?.project_kilometer_marker || "", + project_direction: LoanDetails?.project_direction || "", + project_address: LoanDetails?.project_address || "", + }), + }; + useEffect(() => { + requestServer(GET_LOAN_DETAILS_REFAHI + query.id, "get", { auth: true, notification: false }) + .then(({ data }) => { + setLoanDetails(data.data); + setLoanDetailsLoading(false); + }) + .catch(() => {}); + }, []); return ( - + <> + {LoanDetailsLoading ? ( + + + {t("ShowLoan.loading_show_component")} + + ) : ( + + )} + ); }; diff --git a/src/components/first/LoanDescription/index.jsx b/src/components/first/LoanDescription/index.jsx index 71ca20f..d02bd26 100644 --- a/src/components/first/LoanDescription/index.jsx +++ b/src/components/first/LoanDescription/index.jsx @@ -4,21 +4,21 @@ import DownloadIcon from "@mui/icons-material/Download"; const LoanDescription = () => { return ( - - + + ); }; -export default LoanDescription; \ No newline at end of file +export default LoanDescription; diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 435777d..f7cb86d 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -25,6 +25,7 @@ export const GET_OCCUPATIONS_LIST = BASE_URL + "/occupations"; export const GET_LOAN_DETAILS = BASE_URL + "/navgan/loan/details/"; export const GET_LOAN_DETAILS_REFAHI = BASE_URL + "/refahi/loan/details/"; export const UPDATE_LOAN = BASE_URL + "/navgan/loan/update/"; +export const UPDATE_LOAN_REFAHI = BASE_URL + "/refahi/loan/update/"; export const GET_PROJECT_TITLE = BASE_URL + "/navgan_plans"; export const GET_ACTIVITY_LIST = BASE_URL + "/activity_types"; From d3f6b8ae664b9696d359b49ddc6d8a259fda4479 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Tue, 20 May 2025 11:55:15 +0330 Subject: [PATCH 3/4] project_direction --- src/components/dashboard/refahi/show/index.jsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/dashboard/refahi/show/index.jsx b/src/components/dashboard/refahi/show/index.jsx index 7876f12..28908ec 100644 --- a/src/components/dashboard/refahi/show/index.jsx +++ b/src/components/dashboard/refahi/show/index.jsx @@ -53,17 +53,17 @@ const ShowLoan = () => { shenase_meli: LoanDetails?.shenase_meli || "", register_number: LoanDetails?.register_number || "", company_name: LoanDetails?.company_name || "", + project_axis: LoanDetails?.project_axis || "", + project_kilometer_marker: LoanDetails?.project_kilometer_marker || "", + project_direction: LoanDetails?.project_direction === "رفت" ? 1 : 0, + project_address: LoanDetails?.project_address || "", ...(isRefahi1 && { basic_approval_number: LoanDetails?.basic_approval_number || "", basic_approval_renewal_date: moment(LoanDetails?.basic_approval_renewal_date) || "", basic_approval_renewal_image: LoanDetails?.basic_approval_renewal_image || null, basic_approval_image: LoanDetails?.basic_approval_image || null, - project_axis: LoanDetails?.project_axis || "", project_physical_progress: LoanDetails?.project_physical_progress || "", - project_kilometer_marker: LoanDetails?.project_kilometer_marker || "", - project_direction: LoanDetails?.project_direction || "", - project_address: LoanDetails?.project_address || "", }), ...(isRefahi2 && { @@ -71,10 +71,6 @@ const ShowLoan = () => { exploitation_license_renewal_date: moment(LoanDetails?.exploitation_license_renewal_date) || "", exploitation_license_image: LoanDetails?.exploitation_license_image || null, exploitation_license_renewal_image: LoanDetails?.exploitation_license_renewal_image || null, - project_axis: LoanDetails?.project_axis || "", - project_kilometer_marker: LoanDetails?.project_kilometer_marker || "", - project_direction: LoanDetails?.project_direction || "", - project_address: LoanDetails?.project_address || "", }), }; useEffect(() => { From f4511c9072a56768447e0259d0bb409ba4a8ab19 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Tue, 20 May 2025 12:02:58 +0330 Subject: [PATCH 4/4] change project_direction --- .../add-request-loan/forms/BuildForm/BuildProjectInfo.jsx | 4 ++-- .../add-request-loan/forms/RestoreForm/RestoreProjectInfo.jsx | 4 ++-- src/components/dashboard/refahi/show/index.jsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildProjectInfo.jsx b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildProjectInfo.jsx index 26cdb36..6c08385 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildProjectInfo.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/BuildForm/BuildProjectInfo.jsx @@ -163,12 +163,12 @@ const BuildProjectInfo = ({ selectors={[ { id: 1, - value: 1, + value: 0, name: "رفت", }, { id: 2, - value: 0, + value: 1, name: "برگشت", }, ]} diff --git a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreProjectInfo.jsx b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreProjectInfo.jsx index 978912f..99fdaaa 100644 --- a/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreProjectInfo.jsx +++ b/src/components/dashboard/refahi/add-request-loan/forms/RestoreForm/RestoreProjectInfo.jsx @@ -163,12 +163,12 @@ const RestoreProjectInfo = ({ selectors={[ { id: 1, - value: 1, + value: 0, name: "رفت", }, { id: 2, - value: 0, + value: 1, name: "برگشت", }, ]} diff --git a/src/components/dashboard/refahi/show/index.jsx b/src/components/dashboard/refahi/show/index.jsx index 28908ec..889b3da 100644 --- a/src/components/dashboard/refahi/show/index.jsx +++ b/src/components/dashboard/refahi/show/index.jsx @@ -55,7 +55,7 @@ const ShowLoan = () => { company_name: LoanDetails?.company_name || "", project_axis: LoanDetails?.project_axis || "", project_kilometer_marker: LoanDetails?.project_kilometer_marker || "", - project_direction: LoanDetails?.project_direction === "رفت" ? 1 : 0, + project_direction: LoanDetails?.project_direction === "رفت" ? 0 : 1, project_address: LoanDetails?.project_address || "", ...(isRefahi1 && {