update project for webapp builder

This commit is contained in:
AmirHossein Mahmoodi
2023-12-12 14:41:54 +03:30
parent cbe5c410c7
commit 715cb6fa61
9 changed files with 3 additions and 1073 deletions

View File

@@ -16,7 +16,7 @@
"@mui/icons-material": "^5.11.16",
"@mui/lab": "^5.0.0-alpha.152",
"@mui/material": "^5.12.0",
"@witel/webapp-builder": "^1.0.6",
"@witel/webapp-builder": "^1.1.0",
"axios": "^1.4.0",
"colord": "^2.9.3",
"eslint": "8.36.0",

View File

@@ -1,32 +0,0 @@
import {Button, Typography} from "@mui/material";
import {useTranslations} from "next-intl";
import CenterLayout from "@/layouts/CenterLayout";
import {useRouter} from "next/router";
import {NextLinkComposed} from "@/core/components/LinkRouting";
const AccessibilityComponent = () => {
const t = useTranslations();
const router = useRouter();
return (
<CenterLayout>
<Typography
sx={{
fontSize: "16px",
fontWeight: 600,
my: 2
}}>
{t("LoanRequest.add_loan_request_permission")}
</Typography>
<Button color="primary" variant="contained"
component={NextLinkComposed}
to={{
pathname: "/dashboard/refahi/followUp-loan",
}}>
{t("LoanFollowUp.loan_follow_up_page")}
</Button>
</CenterLayout>
);
};
export default AccessibilityComponent;

View File

@@ -1,439 +0,0 @@
import StyledForm from "@/core/components/StyledForm";
import UploadSystem from "@/core/components/UploadSystem";
import {SEND_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes";
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
import {
Box,
Button,
Chip,
Divider,
FormControl,
FormHelperText,
InputLabel,
MenuItem,
Select,
Stack,
TextField
} from "@mui/material";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import useRequest from "@/lib/app/hooks/useRequest";
import useProvince from "@/lib/app/hooks/useProvince";
import {useRouter} from "next/router";
const AddFormComponent = () => {
const t = useTranslations();
const requestServer = useRequest()
const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince();
const router = useRouter();
// initial values, validation and request action of form
const initialValues = {
name: "",
phone_number: "",
province_id: "",
national_id: "",
shenasname_id: "",
sherkat_naft_doc: null,
estate_doc: null,
agreement_doc: null,
national_card_image: null,
shenasname_image: null,
payan_khedmat_image: null,
};
const validationSchema = Yup.object().shape({
name: Yup.string().required(t("LoanRequest.error_message_name")),
phone_number: Yup.string().required(
t("LoanRequest.error_message_phone_number")
),
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
national_id: Yup.string().required(
t("LoanRequest.error_message_national_id")
),
shenasname_id: Yup.string().required(
t("LoanRequest.error_message_shenasname_id")
),
sherkat_naft_doc: Yup.mixed().required(t("LoanRequest.error_message_sherkat_naft_doc")),
estate_doc: Yup.mixed().required(t("LoanRequest.error_message_estate_doc")),
agreement_doc: Yup.mixed().required(t("LoanRequest.error_message_agreement_doc")),
national_card_image: Yup.mixed().required(t("LoanRequest.error_message_national_card_image")),
shenasname_image: Yup.mixed().required(t("LoanRequest.error_message_shenasname_image")),
payan_khedmat_image: Yup.mixed().required(t("LoanRequest.error_message_payan_khedmat_image")),
});
const handleSubmit = (values, props) => {
const formData = new FormData();
formData.append("name", values.name);
formData.append("phone_number", values.phone_number);
formData.append("province_id", values.province_id);
formData.append("national_id", values.national_id);
formData.append("shenasname_id", values.shenasname_id);
if (values.sherkat_naft_doc != null)
formData.append("sherkat_naft_doc", values.sherkat_naft_doc);
if (values.estate_doc != null)
formData.append("estate_doc", values.estate_doc);
if (values.agreement_doc != null)
formData.append("agreement_doc", values.agreement_doc);
if (values.shenasname_image != null)
formData.append("shenasname_image", values.shenasname_image);
if (values.national_card_image != null)
formData.append("national_card_image", values.national_card_image);
if (values.payan_khedmat_image != null)
formData.append("payan_khedmat_image", values.payan_khedmat_image);
requestServer(SEND_LOAN_REQUEST_WELFARE, "post", {auth: true, data: formData})
.then(function (response) {
router.replace('/dashboard/refahi/followUp-loan');
})
.catch(function (error) {
})
.finally(function () {
props.setSubmitting(false);
});
};
// end initial values, validation and request action of form
return (
<Formik
initialValues={initialValues}
onSubmit={handleSubmit}
validationSchema={validationSchema}
>
{(props) => (
<Stack
spacing={2}
sx={{
p: 1,
width: "100%",
}}
>
<StyledForm sx={{width: "100%"}}>
<Box sx={{my: 1}}>
<Divider>
<Chip
label={t("LoanRequest.personal_info")}
/>
</Divider>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="name"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_name")}
placeholder={t("LoanRequest.text_field_enter_your_name")}
type={"text"}
error={!!(props.touched.name && props.errors.name)}
fullWidth
helperText={props.touched.name ? props.errors.name : null}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="phone_number"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_phone_number")}
placeholder={t(
"LoanRequest.text_field_enter_your_phone_number"
)}
type={"text"}
error={
!!(props.touched.phone_number && props.errors.phone_number)
}
fullWidth
helperText={
props.touched.phone_number
? props.errors.phone_number
: null
}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2},
mt: 0,
width: "100%",
}}
>
<FormControl
error={props.touched.province_id && !!props.errors.province_id}
sx={{width: "100%", mt: 2}}
size="small"
>
<InputLabel>{t("LoanRequest.text_field_province_id")}</InputLabel>
<Select
name="province_id"
disabled={isLoadingProvinceList || errorProvinceList}
label={t("LoanRequest.text_field_province_id")}
value={props.values.province_id}
onChange={(e) => {
props.setFieldValue("province_id", e.target.value);
}}
onBlur={props.handleBlur}
fullWidth
variant="outlined"
>
{isLoadingProvinceList ? (
<MenuItem>
{t("LoanRequest.text_field_loading_provinces_list")}
</MenuItem>
) : errorProvinceList ? (
<MenuItem>
{t("LoanRequest.text_field_error_fetching_provinces")}
</MenuItem>
) : (
provinceList.map((item) => (
<MenuItem key={item.id} value={item.id}>
{item.name}
</MenuItem>
))
)}
</Select>
<FormHelperText>
{props.touched.province_id && props.errors.province_id ? props.errors.province_id : ""}
</FormHelperText>
</FormControl>
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="national_id"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_national_id")}
placeholder={t(
"LoanRequest.text_field_enter_your_national_id"
)}
type={"text"}
error={
!!(props.touched.national_id && props.errors.national_id)
}
fullWidth
helperText={
props.touched.national_id
? props.errors.national_id
: null
}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="shenasname_id"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_shenasname_id")}
placeholder={t(
"LoanRequest.text_field_enter_your_shenasname_id"
)}
type={"text"}
error={
!!(props.touched.shenasname_id && props.errors.shenasname_id)
}
fullWidth
helperText={
props.touched.shenasname_id
? props.errors.shenasname_id
: null
}
/>
</Box>
</Box>
<Box sx={{my: 1}}>
<Divider>
<Chip
label={t("LoanRequest.uploading_documents")}
/>
</Divider>
</Box>
<Stack spacing={{xs: 1, sm: 2}} direction="row" useFlexGap flexWrap="wrap"
sx={{justifyContent: "center"}}>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
fieldName="sherkat_naft_doc"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_sherkat_naft_doc")}
enableDelete={false}
error={
!!(props.touched.sherkat_naft_doc && props.errors.sherkat_naft_doc)
}
helperText={
props.touched.sherkat_naft_doc ? props.errors.sherkat_naft_doc : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
fieldName="estate_doc"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_estate_doc")}
enableDelete={false}
error={
!!(props.touched.estate_doc && props.errors.estate_doc)
}
helperText={
props.touched.estate_doc ? props.errors.estate_doc : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
fieldName="agreement_doc"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_agreement_doc")}
enableDelete={false}
error={
!!(props.touched.agreement_doc && props.errors.agreement_doc)
}
helperText={
props.touched.agreement_doc ? props.errors.agreement_doc : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
fieldName="shenasname_image"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_shenasname_image")}
enableDelete={false}
error={
!!(props.touched.shenasname_image && props.errors.shenasname_image)
}
helperText={
props.touched.shenasname_image ? props.errors.shenasname_image : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
fieldName="payan_khedmat_image"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_payan_khedmat_image")}
enableDelete={false}
error={
!!(props.touched.payan_khedmat_image && props.errors.payan_khedmat_image)
}
helperText={
props.touched.payan_khedmat_image ? props.errors.payan_khedmat_image : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
fieldName="national_card_image"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_national_card_image")}
enableDelete={false}
error={
!!(props.touched.national_card_image && props.errors.national_card_image)
}
helperText={
props.touched.national_card_image ? props.errors.national_card_image : null
}
/>
</Box>
</Stack>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "center",
mx: "auto",
my: 2,
width: {xs: "100%", sm: "30%", md: "25%"},
}}
>
<Button
fullWidth
type="submit"
variant="contained"
size="large"
sx={{mt: 2}}
endIcon={<DataSaverOnIcon/>}
disabled={props.isSubmitting}
>
{t("LoanRequest.button_submit")}
</Button>
</Box>
</StyledForm>
</Stack>
)}
</Formik>
);
};
export default AddFormComponent;

View File

@@ -1,17 +0,0 @@
import DashboardLayouts from "@/layouts/dashboardLayouts";
import useUser from "@/lib/app/hooks/useUser";
import {useTranslations} from "next-intl";
import AddFormComponent from "@/components/dashboard/refahi/add-request-loan/forms/AddForm";
import AccessibilityComponent from "@/components/dashboard/refahi/add-request-loan/accessibility";
const LoanRequestComponent = () => {
const t = useTranslations();
const {user} = useUser();
return (
<DashboardLayouts>
{user.can_request_a_new_loan ? <AddFormComponent/> : <AccessibilityComponent/>}
</DashboardLayouts>
);
};
export default LoanRequestComponent;

View File

@@ -1,397 +0,0 @@
import StyledForm from "@/core/components/StyledForm";
import UploadSystem from "@/core/components/UploadSystem";
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 {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
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 = ({provinceList, initialValues}) => {
const t = useTranslations();
const requestServer = useRequest();
const router = useRouter();
// validation and request action of form
const validationSchema = Yup.object().shape({
name: Yup.string().required(t("LoanRequest.error_message_name")),
phone_number: Yup.string().required(
t("LoanRequest.error_message_phone_number")
),
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
national_id: Yup.string().required(t("LoanRequest.error_message_national_id")),
shenasname_id: Yup.string().required(t("LoanRequest.error_message_shenasname_id")),
sherkat_naft_doc: Yup.mixed().required(t("LoanRequest.error_message_sherkat_naft_doc")),
estate_doc: Yup.mixed().required(t("LoanRequest.error_message_estate_doc")),
agreement_doc: Yup.mixed().required(t("LoanRequest.error_message_agreement_doc")),
national_card_image: Yup.mixed().required(t("LoanRequest.error_message_national_card_image")),
shenasname_image: Yup.mixed().required(t("LoanRequest.error_message_shenasname_image")),
payan_khedmat_image: Yup.mixed().required(t("LoanRequest.error_message_payan_khedmat_image")),
});
const handleSubmit = (values, props) => {
const formData = new FormData();
formData.append("name", values.name);
formData.append("phone_number", values.phone_number);
formData.append("province_id", values.province_id);
formData.append("national_id", values.national_id);
formData.append("shenasname_id", values.shenasname_id);
if (values.sherkat_naft_doc != initialValues.sherkat_naft_doc)
formData.append("sherkat_naft_doc", values.sherkat_naft_doc);
if (values.estate_doc != initialValues.estate_doc)
formData.append("estate_doc", values.estate_doc);
if (values.agreement_doc != initialValues.agreement_doc)
formData.append("agreement_doc", values.agreement_doc);
if (values.shenasname_image != initialValues.shenasname_image)
formData.append("shenasname_image", values.shenasname_image);
if (values.national_card_image != initialValues.national_card_image)
formData.append("national_card_image", values.national_card_image);
if (values.payan_khedmat_image != initialValues.payan_khedmat_image)
formData.append("payan_khedmat_image", values.payan_khedmat_image);
requestServer(UPDATE_LOAN_REQUEST_WELFARE + router.query.id, "post", {auth: true, data: formData})
.then(function (response) {
})
.catch(function (error) {
})
.finally(function () {
props.setSubmitting(false);
});
};
if (!initialValues) return "";
return (
<Formik
initialValues={initialValues}
onSubmit={handleSubmit}
validationSchema={validationSchema}
>
{(props) => (
<Stack
spacing={2}
sx={{
p: 1,
width: "100%",
}}
>
<StyledForm sx={{width: "100%"}}>
<Box sx={{my: 1}}>
<Divider>
<Chip
label={t("LoanRequest.personal_info")}
/>
</Divider>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="name"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_name")}
placeholder={t("LoanRequest.text_field_enter_your_name")}
type={"text"}
error={!!(props.touched.name && props.errors.name)}
fullWidth
helperText={props.touched.name ? props.errors.name : null}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="phone_number"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_phone_number")}
placeholder={t(
"LoanRequest.text_field_enter_your_phone_number"
)}
type={"text"}
error={
!!(props.touched.phone_number && props.errors.phone_number)
}
fullWidth
helperText={
props.touched.phone_number
? props.errors.phone_number
: null
}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
name="province_id"
label={t("LoanRequest.text_field_province_id")} // t("LoanRequest.text_field_enter_your_province")
size="small"
selectType="province_id"
component={SelectBox}
selectors={provinceList}
select={props.values.province_id}
setFieldValue={props.setFieldValue}
setFieldTouched={props.setFieldTouched}
error={
!!(props.touched.province_id && props.errors.province_id)
}
helperText={
props.touched.province_id ? props.errors.province_id : null
}
/>
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="national_id"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_national_id")}
placeholder={t(
"LoanRequest.text_field_enter_your_national_id"
)}
type={"text"}
error={
!!(props.touched.national_id && props.errors.national_id)
}
fullWidth
helperText={
props.touched.national_id
? props.errors.national_id
: null
}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2},
my: 2,
width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="shenasname_id"
variant="outlined"
size="small"
label={t("LoanRequest.text_field_shenasname_id")}
placeholder={t(
"LoanRequest.text_field_enter_your_shenasname_id"
)}
type={"text"}
error={
!!(props.touched.shenasname_id && props.errors.shenasname_id)
}
fullWidth
helperText={
props.touched.shenasname_id
? props.errors.shenasname_id
: null
}
/>
</Box>
</Box>
<Box sx={{my: 1}}>
<Divider>
<Chip
label={t("LoanRequest.uploading_documents")}
/>
</Divider>
</Box>
<Stack spacing={{xs: 1, sm: 2}} direction="row" useFlexGap flexWrap="wrap"
sx={{justifyContent: "center"}}>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
default_image={initialValues.sherkat_naft_doc}
fieldName="sherkat_naft_doc"
imageAlt={t("LoanRequest.file_field_sherkat_naft_doc")}
label={t("LoanRequest.file_field_sherkat_naft_doc")}
enableDelete={false}
error={
!!(props.touched.sherkat_naft_doc && props.errors.sherkat_naft_doc)
}
helperText={
props.touched.sherkat_naft_doc ? props.errors.sherkat_naft_doc : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
default_image={initialValues.estate_doc}
fieldName="estate_doc"
imageAlt={t("LoanRequest.file_field_estate_doc")}
label={t("LoanRequest.file_field_estate_doc")}
enableDelete={false}
error={
!!(props.touched.estate_doc && props.errors.estate_doc)
}
helperText={
props.touched.estate_doc ? props.errors.estate_doc : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
default_image={initialValues.agreement_doc}
fieldName="agreement_doc"
imageAlt={t("LoanRequest.file_field_agreement_doc")}
label={t("LoanRequest.file_field_agreement_doc")}
enableDelete={false}
error={
!!(props.touched.agreement_doc && props.errors.agreement_doc)
}
helperText={
props.touched.agreement_doc ? props.errors.agreement_doc : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
default_image={initialValues.shenasname_image}
fieldName="shenasname_image"
imageAlt={t("LoanRequest.file_field_shenasname_image")}
label={t("LoanRequest.file_field_shenasname_image")}
enableDelete={false}
error={
!!(props.touched.shenasname_image && props.errors.shenasname_image)
}
helperText={
props.touched.shenasname_image ? props.errors.shenasname_image : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
default_image={initialValues.payan_khedmat_image}
fieldName="payan_khedmat_image"
imageAlt={t("LoanRequest.file_field_payan_khedmat_image")}
label={t("LoanRequest.file_field_payan_khedmat_image")}
enableDelete={false}
error={
!!(props.touched.payan_khedmat_image && props.errors.payan_khedmat_image)
}
helperText={
props.touched.payan_khedmat_image ? props.errors.payan_khedmat_image : null
}
/>
</Box>
<Box sx={{
mx: {xs: 0, sm: 1},
maxWidth: "200px"
}}>
<UploadSystem
setFieldValue={props.setFieldValue}
default_image={initialValues.national_card_image}
fieldName="national_card_image"
imageAlt={t("app_name")}
label={t("LoanRequest.file_field_national_card_image")}
enableDelete={false}
error={
!!(props.touched.national_card_image && props.errors.national_card_image)
}
helperText={
props.touched.national_card_image ? props.errors.national_card_image : null
}
/>
</Box>
</Stack>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "center",
mx: "auto",
my: 2,
width: {xs: "100%", sm: "30%", md: "25%"},
}}
>
<Button
fullWidth
type="submit"
variant="contained"
size="large"
sx={{mt: 2}}
endIcon={<DataSaverOnIcon/>}
disabled={props.isSubmitting}
>
{t("LoanRequest.button_submit")}
</Button>
</Box>
</StyledForm>
</Stack>
)}
</Formik>
);
};
export default EditFormComponent;

View File

@@ -1,81 +0,0 @@
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;

View File

@@ -1,52 +0,0 @@
import {
Card,
CardContent,
CardHeader,
Grid, IconButton, Tooltip,
Typography,
} from "@mui/material";
import SellIcon from '@mui/icons-material/Sell';
import EditIcon from '@mui/icons-material/Edit';
import {useTranslations} from "next-intl";
import {NextLinkComposed} from "@/core/components/LinkRouting";
const RequestCard = ({item}) => {
const t = useTranslations();
return (
<Grid item xs={12} md={6} lg={4}>
<Card sx={{
width: "100%",
boxShadow: "rgba(0, 0, 0, 0.15) 0px 5px 15px 0px"
}}>
<CardHeader
avatar={<SellIcon color="primary"/>}
title={`${t("LoanFollowUp.request_number")}: (${item.id})`}
subheader={item.latest_history_created_at}
action={
item.state_id === 7 ? ( // Use the ternary operator or if/else inside curly braces
<Tooltip title={t("LoanFollowUp.loan_request_correction")}>
<IconButton size="small"
color="primary"
variant="outlined"
component={NextLinkComposed}
to={{
pathname: `edit-request-loan/${item.id}`,
}} aria-label="fingerprint">
<EditIcon/>
</IconButton>
</Tooltip>
) : null
}
/>
<CardContent sx={{pt: 0}}>
<Typography variant="button">
{item.loan_state}
</Typography>
</CardContent>
</Card>
</Grid>
);
};
export default RequestCard;

View File

@@ -1,54 +0,0 @@
import DashboardLayouts from "@/layouts/dashboardLayouts";
import {Grid, Stack, Typography,} from "@mui/material";
import {useEffect, useState} from "react";
import {SHOW_LOAN_REQUEST_WELFARE} from "@/core/data/apiRoutes";
import useLoading from "@/lib/app/hooks/useLoading";
import useRequest from "@/lib/app/hooks/useRequest";
import moment from "jalali-moment";
import RequestCard from "@/components/dashboard/refahi/followUp-loan/RequestCard";
import {useTranslations} from "next-intl";
const LoanFollowUpComponent = () => {
const t = useTranslations()
const requestServer = useRequest();
const {setLoadingPage} = useLoading();
const [requestsList, setRequestsList] = useState(null);
// get form data
useEffect(() => {
setLoadingPage(true)
requestServer(SHOW_LOAN_REQUEST_WELFARE, "get", {auth: true, notification: false})
.then(function ({data}) {
const items = data.data;
const formattedData = items.map((item, index) => ({
id: item.id,
latest_history_created_at: moment(item.latest_history_created_at).locale("fa").format("HH:mm | YYYY/MM/DD"),
state_id: item.state_id,
loan_state: item.loan_state,
}));
setRequestsList(formattedData);
setLoadingPage(false)
})
.catch(function (error) {
})
}, []);
return (<DashboardLayouts>
<Stack
spacing={2}
sx={{
p: 4, width: "100%",
}}
>
{requestsList == null ? '' : requestsList.length ? (<Grid
container
columnSpacing={2}
rowSpacing={2}
sx={{alignItems: "start", justifyContent: "center"}}
>
{requestsList.map((item, index) => (<RequestCard item={item} key={item.id}/>))}
</Grid>) : (<Typography sx={{textAlign: 'center'}}>{t('LoanFollowUp.no_request_found')}</Typography>)}
</Stack>
</DashboardLayouts>);
};
export default LoanFollowUpComponent;

View File

@@ -5,9 +5,11 @@ import {GET_SIDEBAR_NOTIFICATION} from "@/core/data/apiRoutes";
const DashboardLayout = (props) => {
const {user} = useUser()
const middlewaresProps = props.middlewaresProps || {}
return (
<>
<DashboardLayoutPure
middlewares={{list: [], props: {...middlewaresProps}}}
loginUrl={'/login'}
user_introduction={user.type_name}
headerProfileItems={headerProfileItems}