81 lines
3.0 KiB
JavaScript
81 lines
3.0 KiB
JavaScript
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
|
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";
|
|
import {log} from "next/dist/server/typescript/utils";
|
|
|
|
const LoanRequestComponent = () => {
|
|
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) return
|
|
if (initialValues.state_id === 7) return
|
|
|
|
router.replace('/dashboard/refahi/followUp-loan');
|
|
}, [initialValues]);
|
|
|
|
return (
|
|
<>
|
|
{initialValues && initialValues.state_id === 7 && (
|
|
<DashboardLayouts>
|
|
<EditFormComponent provinceList={provinceList} initialValues={initialValues}/>
|
|
</DashboardLayouts>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default LoanRequestComponent; |