formatting

This commit is contained in:
2025-05-20 11:38:54 +03:30
parent f15f4fc230
commit da3c1ca582
11 changed files with 248 additions and 154 deletions

View File

@@ -2,7 +2,6 @@ import { CenterLayout } from "@witel/webapp-builder";
import ShowLoanForm from "@/components/dashboard/navgan/show/form";
const ShowLoan = () => {
return (
<CenterLayout>
<ShowLoanForm />

View File

@@ -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}
/>
)}
</Stack>

View File

@@ -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")}
</Button>
<Button
onClick={formik.handleSubmit}
endIcon={<BeenhereIcon />}
variant={"contained"}
size={"large"}
color={"primary"}
disabled={submitting}
>
{t("RefahiLoanRequest.submit-button")}
</Button>
{editDisabled === 17 && (
<Button
onClick={formik.handleSubmit}
endIcon={<BeenhereIcon />}
variant={"contained"}
size={"large"}
color={"primary"}
disabled={submitting}
>
{t("RefahiLoanRequest.submit-button")}
</Button>
)}
</Stack>
</>
);

View File

@@ -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) {

View File

@@ -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}
/>
)}
</Stack>

View File

@@ -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")}
</Button>
<Button
onClick={formik.handleSubmit}
endIcon={<BeenhereIcon />}
variant={"contained"}
size={"large"}
color={"primary"}
disabled={submitting}
>
{t("RefahiLoanRequest.submit-button")}
</Button>
{editDisabled === 17 && (
<Button
onClick={formik.handleSubmit}
endIcon={<BeenhereIcon />}
variant={"contained"}
size={"large"}
color={"primary"}
disabled={submitting}
>
{t("RefahiLoanRequest.submit-button")}
</Button>
)}
</Stack>
</>
);

View File

@@ -130,7 +130,12 @@ const RestoreForm = ({ setFinishRefahiLoanRequest }) => {
return (
<>
<RestoreFormController handleSubmit={handleSubmit} dispatch={dispatch} submitting={submitting} state={state} />
<RestoreFormController
handleSubmit={handleSubmit}
dispatch={dispatch}
submitting={submitting}
state={state}
/>
</>
);
};

View File

@@ -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 (
<Stack sx={{ alignItems: "center", justifyContent: "center" }} spacing={3}>
<SvgLoading height={150} width={150} />
<Typography>{t("ShowLoan.loading_show_component")}</Typography>
</Stack>
);
}
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 ? (
<BuildFormController submitting={submitting} state={state} dispatch={dispatch} handleSubmit={handleSubmit} />
{refahi_type === 1 ? (
<BuildFormController
editDisabled={editDisabled}
submitting={submitting}
state={state}
dispatch={dispatch}
handleSubmit={handleSubmit}
/>
) : (
<RestoreFormController submitting={submitting} state={state} dispatch={dispatch} handleSubmit={handleSubmit} />
<RestoreFormController
editDisabled={editDisabled}
submitting={submitting}
state={state}
dispatch={dispatch}
handleSubmit={handleSubmit}
/>
)}
</>
);

View File

@@ -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 (
<ShowLoanForm />
<>
{LoanDetailsLoading ? (
<CenterLayout>
<SvgLoading height={150} width={150} />
<Typography sx={{ pt: 2 }}>{t("ShowLoan.loading_show_component")}</Typography>
</CenterLayout>
) : (
<ShowLoanForm
editDisabled={LoanDetails.state_id}
queryID={query.id}
refahi_type={LoanDetails.refahi_type}
defaultData={_data}
/>
)}
</>
);
};

View File

@@ -4,21 +4,21 @@ import DownloadIcon from "@mui/icons-material/Download";
const LoanDescription = () => {
return (
<Box sx={{ flex: 1 }}>
<Stack alignItems={"center"} justifyContent={"center"} sx={{pt : 15}}>
<Button variant="contained" startIcon={<DownloadIcon />}>
<Link
variant="subtitle1"
sx={{ padding: 1 }}
color={"white"}
download
underline="none"
href={"/files/راهنما.pdf"}
>
دریافت فایل های راهنما
</Link>
</Button>
<Stack alignItems={"center"} justifyContent={"center"} sx={{ pt: 15 }}>
<Button variant="contained" startIcon={<DownloadIcon />}>
<Link
variant="subtitle1"
sx={{ padding: 1 }}
color={"white"}
download
underline="none"
href={"/files/راهنما.pdf"}
>
دریافت فایل های راهنما
</Link>
</Button>
</Stack>
</Box>
);
};
export default LoanDescription;
export default LoanDescription;

View File

@@ -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";