TF-103 ban user to see edit page by changing router staticaly
This commit is contained in:
@@ -1,21 +1,19 @@
|
||||
import StyledForm from "@/core/components/StyledForm";
|
||||
import UploadSystem from "@/core/components/UploadSystem";
|
||||
import {GET_PROVINCE_LIST, UPDATE_LOAN_REQUEST_WELFARE, DETAILS_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes";
|
||||
import {UPDATE_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";
|
||||
import {Box, Button, Chip, Divider, Stack, TextField} from "@mui/material";
|
||||
import axios from "axios";
|
||||
import {Field, Formik} from "formik";
|
||||
import {useTranslations} from "next-intl";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import * as Yup from "yup";
|
||||
import SelectBox from "@/core/components/SelectBox";
|
||||
import useRequest from "@/lib/app/hooks/useRequest";
|
||||
import {useRouter} from "next/router";
|
||||
import useLoading from "@/lib/app/hooks/useLoading";
|
||||
|
||||
const EditFormComponent = () => {
|
||||
const EditFormComponent = ({provinceList, initialValues}) => {
|
||||
const t = useTranslations();
|
||||
const {directionApp} = useDirection();
|
||||
const {token} = useUser();
|
||||
@@ -23,51 +21,6 @@ const EditFormComponent = () => {
|
||||
const router = useRouter();
|
||||
const {setLoadingPage} = useLoading();
|
||||
|
||||
const [provinceList, setProvinceList] = useState(null);
|
||||
const [initialValues, setInitialValues] = useState(null);
|
||||
|
||||
// get province list
|
||||
useEffect(() => {
|
||||
setLoadingPage(true)
|
||||
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(() => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
||||
// get form data
|
||||
useEffect(() => {
|
||||
if (!provinceList) return;
|
||||
requestServer(DETAILS_LOAN_REQUEST_WELFARE + router.query.id, "get", {auth: true, notification: false})
|
||||
.then(function ({data}) {
|
||||
const item = data.data;
|
||||
const formattedData = {
|
||||
name: item.name,
|
||||
phone_number: item.phone_number,
|
||||
province_id: item.province_id,
|
||||
national_id: item.national_id,
|
||||
shenasname_id: item.shenasname_id,
|
||||
sherkat_naft_doc: item.sherkat_naft_doc,
|
||||
estate_doc: item.estate_doc,
|
||||
agreement_doc: item.agreement_doc,
|
||||
national_card_image: item.national_card_image,
|
||||
shenasname_image: item.shenasname_image,
|
||||
payan_khedmat_image: item.payan_khedmat_image,
|
||||
}
|
||||
setInitialValues(formattedData);
|
||||
setLoadingPage(false)
|
||||
})
|
||||
.catch(() => {
|
||||
})
|
||||
}, [provinceList]);
|
||||
|
||||
// validation and request action of form
|
||||
const validationSchema = Yup.object().shape({
|
||||
name: Yup.string().required(t("LoanRequest.error_message_name")),
|
||||
|
||||
@@ -1,15 +1,75 @@
|
||||
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
||||
import useUser from "@/lib/app/hooks/useUser";
|
||||
import {useTranslations} from "next-intl";
|
||||
import EditFormComponent from "@/components/dashboard/refahi/edit-request-loan/forms/EditForm";
|
||||
import {useEffect, useState} from "react";
|
||||
import {DETAILS_LOAN_REQUEST_WELFARE, GET_PROVINCE_LIST} from "@/core/data/apiRoutes";
|
||||
import useLoading from "@/lib/app/hooks/useLoading";
|
||||
import useRequest from "@/lib/app/hooks/useRequest";
|
||||
import {useRouter} from "next/router";
|
||||
|
||||
const LoanRequestComponent = () => {
|
||||
const t = useTranslations();
|
||||
const {user} = useUser();
|
||||
const requestServer = useRequest();
|
||||
const {setLoadingPage} = useLoading();
|
||||
const router = useRouter();
|
||||
|
||||
const [provinceList, setProvinceList] = useState(null);
|
||||
const [initialValues, setInitialValues] = useState(null);
|
||||
|
||||
// get province list
|
||||
useEffect(() => {
|
||||
setLoadingPage(true);
|
||||
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(() => {
|
||||
setLoadingPage(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
// get form data
|
||||
useEffect(() => {
|
||||
if (!provinceList) return;
|
||||
setLoadingPage(true);
|
||||
requestServer(DETAILS_LOAN_REQUEST_WELFARE + router.query.id, "get", {auth: true, notification: false})
|
||||
.then(function ({data}) {
|
||||
const item = data.data;
|
||||
const formattedData = {
|
||||
name: item.name,
|
||||
phone_number: item.phone_number,
|
||||
province_id: item.province_id,
|
||||
national_id: item.national_id,
|
||||
shenasname_id: item.shenasname_id,
|
||||
sherkat_naft_doc: item.sherkat_naft_doc,
|
||||
estate_doc: item.estate_doc,
|
||||
agreement_doc: item.agreement_doc,
|
||||
national_card_image: item.national_card_image,
|
||||
shenasname_image: item.shenasname_image,
|
||||
payan_khedmat_image: item.payan_khedmat_image,
|
||||
state_id: item.state_id
|
||||
};
|
||||
setInitialValues(formattedData);
|
||||
})
|
||||
.catch(() => {
|
||||
setLoadingPage(false);
|
||||
});
|
||||
}, [provinceList, router]);
|
||||
|
||||
// Redirect to /dashboard/refahi/followUp-loan if state_id is not 7
|
||||
useEffect(() => {
|
||||
if (initialValues && initialValues.state_id !== 7) {
|
||||
router.push('/dashboard/refahi/followUp-loan');
|
||||
}
|
||||
}, [initialValues, router]);
|
||||
|
||||
return (
|
||||
<DashboardLayouts>
|
||||
<EditFormComponent/>
|
||||
{initialValues && initialValues.state_id === 7 && (
|
||||
<EditFormComponent provinceList={provinceList} initialValues={initialValues}/>
|
||||
)}
|
||||
</DashboardLayouts>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user