diff --git a/example.env.local b/example.env.local index 4be359a..9715afe 100644 --- a/example.env.local +++ b/example.env.local @@ -1,5 +1,5 @@ NEXT_PUBLIC_API_NAME = "Loan Facilities Dashboard" -NEXT_PUBLIC_API_VERSION = "1.25.4" +NEXT_PUBLIC_API_VERSION = "1.25.6" NEXT_PUBLIC_DEFAULT_LANGUAGE = "fa" NEXT_PUBLIC_DEFAULT_DIRECTION = "rtl" diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 24f4ad5..36abf09 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -299,7 +299,8 @@ "confirm": "ارجاع به مدیر کل", "upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد", "upload_file_format": "فرمت قابل قبول : png,jpg,pdf", - "excel_report": "گزارش اکسل" + "excel_report": "گزارش اکسل", + "confirm_text": "فرم الف و ب به رویت و تایید رسید." }, "InspectorExpert": { "name": "نام", @@ -361,10 +362,21 @@ "description": "توضیحات خود را وارد نمائید", "choose_file": "انتخاب فایل", "approved_amount": "مبلغ تصویب شده", + "sakht_period": "دوره ساخت", + "tanafos_period": "دوره تنفس", "approved_amount_error": "وارد کردن مبلغ تصویب شده الزامیست", + "sakht_period_error": "وارد کردن دوره ساخت الزامیست", + "tanafos_period_error": "وارد کردن دوره تنفس الزامیست", "approved_amount_positive": "مبلغ تصویب شده باید مثبت باشد", "approved_amount_number": "مبلغ تصویب شده باید عدد باشد", + "sakht_period_positive": "دوره ساخت باید مثبت باشد", + "tanafos_period_positive": "دوره تنفس باید مثبت باشد", + "sakht_period_number": "دوره ساخت باید عدد باشد", + "tanafos_period_number": "دوره تنفس باید عدد باشد", "toman": "میلیون تومان", + "tanafos_period_month": "ماه", + "approved_amount_title": "مبلغ تصویب شده کارگروه", + "sakht_period_day": "روز", "proposed_amount_error": "وارد کردن مقدار پیشنهادی الزامیست", "proposed_amount": "مبلغ پیشنهادی", "proposed_amount_positive": "مقدار پیشنهادی باید مثبت باشد", @@ -548,6 +560,8 @@ "LoanHistory": { "id": "کد یکتا", "name": "نام", + "tanafos_period": "دوره تنفس", + "sakht_period": "دوره ساخت", "national_id": "کد ملی", "phone_number": "موبایل", "proposed_amount": "مبلغ پیشنهادی", @@ -558,6 +572,7 @@ "vehicle_type": "نوع ماشین", "state_name": "وضعیت درخواست", "history": "تاریخچه", + "province_name": "استان", "Table_history_error": "خطا در دریافت اطلاعات", "history_report": "فایل ضمیمه", "Table_head_name": "نام", diff --git a/src/components/dashboard/loan-history/index.jsx b/src/components/dashboard/loan-history/index.jsx index 66f28de..222c6ae 100644 --- a/src/components/dashboard/loan-history/index.jsx +++ b/src/components/dashboard/loan-history/index.jsx @@ -137,17 +137,6 @@ function DashboardLoanHistoryComponent() { ); }, }, - { - accessorFn: (row) => - moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), - id: "updated_at", - header: t("LoanHistory.updated_at"), - enableColumnFilter: false, - datatype: "numeric", - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, { accessorFn: (row) => row.navgan_id, id: "navgan_id", @@ -167,6 +156,46 @@ function DashboardLoanHistoryComponent() { {renderedCellValue} ), }, + { + accessorFn: (row) => row.sakht_period, + id: "sakht_period", + header: t("LoanHistory.sakht_period"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals" + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.tanafos_period, + id: "tanafos_period", + header: t("LoanHistory.tanafos_period"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals" + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.province_name, + id: "province_name", + header: t("LoanHistory.province_name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, { accessorFn: (row) => row.vehicle_type, id: "vehicle_type", diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx index ada0a12..438def6 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx @@ -7,6 +7,7 @@ import { DialogContent, FormHelperText, Grid, + InputAdornment, LinearProgress, Stack, TextField, @@ -14,10 +15,7 @@ import { } from "@mui/material" import {useFormik} from "formik"; import {useTranslations} from "next-intl"; -import { - CONFIRM_MACHINARY_OFFICE, - CONFIRM_MACHINARY_OFFICE_DETAILS -} from "@/core/data/apiRoutes"; +import {CONFIRM_MACHINARY_OFFICE, CONFIRM_MACHINARY_OFFICE_DETAILS} from "@/core/data/apiRoutes"; import {useEffect, useState} from "react"; import PriceField from "@/core/components/PriceField"; import * as Yup from "yup"; @@ -28,13 +26,13 @@ const vehicle_amount = { "اتوبوس": 7000, "مینی بوس": 2000, } -const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type , handleSizeChangeClick}) => { +const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type, handleSizeChangeClick}) => { const t = useTranslations(); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); const [fileName, setfileName] = useState(null); const [showAddIcon, setShowAddIcon] = useState(true); - const requestServer = useRequest({auth: true , notification: false}) + const requestServer = useRequest({auth: true, notification: false}) const {update_notification} = useNotification() const [accordionStates, setAccordionStates] = useState([]); const [hasImageShown, setHasImageShown] = useState(false); @@ -46,7 +44,7 @@ const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type , han useEffect(() => { requestServer(`${CONFIRM_MACHINARY_OFFICE_DETAILS}/${rowId}`, 'get') .then((response) => { - const booleanData = Array.from({ length: response.data.data.attachment_files.length }, () => false); + const booleanData = Array.from({length: response.data.data.attachment_files.length}, () => false); setAccordionStates(booleanData); setDetailsData(response.data) }) @@ -60,13 +58,11 @@ const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type , han const newAccordionStates = accordionStates.map((state, i) => i === index ? !state : false); setAccordionStates(newAccordionStates); - if (!newAccordionStates[index]) - { + if (!newAccordionStates[index]) { handleSizeChangeClick('sm'); setHasImageShown(false); setIsSkeleton(false) - } - else { + } else { handleSizeChangeClick('xl'); setHasImageShown(true); setImageLink(detailsList.data.attachment_files[index]) @@ -75,14 +71,26 @@ const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type , han }; const validationSchema = Yup.object().shape({ - proposed_amount: Yup.mixed().test( - "is-number", - `${t("ConfirmDialog.proposed_amount_number")}`, - (value) => !isNaN(value) - ).test("max-amount", `${t("MachinaryOffice.max_amount", {value: parseInt(vehicle_amount[vehicle_type]).toLocaleString('en')})}`, - (value) => value <= vehicle_amount[vehicle_type]) + proposed_amount: Yup.mixed() + .test( + "is-number", + `${t("ConfirmDialog.proposed_amount_number")}`, + (value) => !isNaN(value) + ) + .test("max-amount", `${t("MachinaryOffice.max_amount", {value: parseInt(vehicle_amount[vehicle_type]).toLocaleString('en')})}`, + (value) => value <= vehicle_amount[vehicle_type]) .test("positive", `${t("ConfirmDialog.proposed_amount_positive")}`, (value) => value >= 0) .required(t("ConfirmDialog.proposed_amount_error")), + sakht_period: Yup.mixed() + .test("is-number", `${t("ConfirmDialog.sakht_period_number")}`, + (value) => !isNaN(value)) + .test("positive", `${t("ConfirmDialog.sakht_period_positive")}`, (value) => value > 0) + .required(t("ConfirmDialog.sakht_period_error")), + tanafos_period: Yup.mixed() + .test("is-number", `${t("ConfirmDialog.tanafos_period_number")}`, + (value) => !isNaN(value)) + .test("positive", `${t("ConfirmDialog.tanafos_period_positive")}`, (value) => value > 0) + .required(t("ConfirmDialog.tanafos_period_error")), confirm_img: Yup.mixed() .required(t("MachinaryOffice.upload_file_required")) .test('fileSize', `${t("MachinaryOffice.upload_file_unit")}`, (value) => { @@ -93,20 +101,35 @@ const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type , han return allowedTypes.includes(value.type); }) }); - const formik = useFormik({ initialValues: { description: "", proposed_amount: "", + sakht_period: "", + tanafos_period: "", confirm_img: null }, validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("proposed_amount", values.proposed_amount); + formData.append("sakht_period", values.sakht_period); + formData.append("tanafos_period", values.tanafos_period); if (values.description != "") formData.append("expert_description", values.description); - if (values.confirm_img != null) formData.append("attachment", values.confirm_img); + if (values.confirm_img != null) { + const attachments = [ + { + title: "فایل ضمیمه کارتابل قیمت گذاری", + file: values.confirm_img + } + ]; + attachments.forEach((attachment, index) => { + formData.append(`attachment[${index}][title]`, attachment.title); + formData.append(`attachment[${index}][file]`, attachment.file); + }); + } requestServer(`${CONFIRM_MACHINARY_OFFICE}/${rowId}`, 'post', { data: formData, + notification: true }).then((response) => { setOpenConfirmDialog(false) mutate() @@ -166,7 +189,7 @@ const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type , han - {loading ? : renderCustomAccordions()} + {loading ? : renderCustomAccordions()} + + {t("ConfirmDialog.sakht_period_day")}, + }} + /> + + + {t("ConfirmDialog.tanafos_period_month")}, + }} + /> + {t("MachinaryOffice.upload_file")} - - + + diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx index 445aab3..febb675 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx @@ -33,9 +33,15 @@ const Confirm = ({rowId, mutate, vehicle_type}) => { + PaperProps={{ + sx: { + transition: 'all .3s', + boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px' + } + }} maxWidth={dialogSize}> {t("MachinaryOffice.confirm")} - diff --git a/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx index 479b213..345f569 100644 --- a/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx @@ -30,8 +30,18 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("expert_description", values.description); - if (values.reject_img != null) formData.append("attachment", values.reject_img); - + if (values.reject_img != null) { + const attachments = [ + { + title: "فایل ضمیمه کارتابل قیمت گذاری", + file: values.reject_img + } + ]; + attachments.forEach((attachment, index) => { + formData.append(`attachment[${index}][title]`, attachment.title); + formData.append(`attachment[${index}][file]`, attachment.file); + }); + } requestServer(`${REJECT_MACHINARY_OFFICE}/${rowId}`, 'post', { data: formData, }).then((response) => { diff --git a/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx index 4078032..02c5348 100644 --- a/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx @@ -2,7 +2,6 @@ import UploadSystem from "@/core/components/UploadSystem"; import useNotification from "@/lib/app/hooks/useNotification"; import useRequest from "@/lib/app/hooks/useRequest"; import { - Box, Button, DialogActions, DialogContent, @@ -20,6 +19,7 @@ import {useEffect, useState} from "react"; import * as Yup from "yup"; import CustomAccordion from "@/core/components/CustomAccordion"; import ImageContent from "@/core/components/ImageContent"; +import NumberShowBox from "@/core/components/NumberShowBox"; const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeClick}) => { const t = useTranslations(); @@ -29,6 +29,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl const [showAddIcon, setShowAddIcon] = useState(true); const requestServer = useRequest({auth: true, notification: false}) const {update_notification} = useNotification() + const [attachmentsData, setAttachmentsData] = useState([]); const [accordionStates, setAccordionStates] = useState([]); const [hasImageShown, setHasImageShown] = useState(false); const [imageLink, setImageLink] = useState(null); @@ -52,9 +53,14 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl useEffect(() => { requestServer(`${CONFIRM_PROVINCE_MANAGER_DETAILS}/${rowId}`, 'get') .then((response) => { - const booleanData = Array.from({length: response.data.data.attachment_files.length}, () => false); - setAccordionStates(booleanData); - setDetailsData(response.data) + const allAttachments = []; + response.data.data.histories.map((history) => { + history.attachments.map((attachment) => { + allAttachments.push(attachment); + }); + }); + setAttachmentsData(allAttachments); + setDetailsData(response.data); }) .catch(() => { }).finally(() => { @@ -62,6 +68,13 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl }); }, []); + useEffect(() => { + if (attachmentsData.length !== 0) { + const booleanData = Array.from({length: attachmentsData.length}, () => false); + setAccordionStates(booleanData); + } + }, [attachmentsData]); + const handleAccordionChange = (index) => { const newAccordionStates = accordionStates.map((state, i) => i === index ? !state : false); setAccordionStates(newAccordionStates); @@ -73,7 +86,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl } else { handleSizeChangeClick('xl'); setHasImageShown(true); - setImageLink(detailsList.data.attachment_files[index]) + setImageLink(attachmentsData[index]) setIsSkeleton(true) } }; @@ -85,11 +98,22 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl }, validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - if (values.description != "") formData.append("expert_description", values.description); - if (values.confirm_img != null) formData.append("attachment", values.confirm_img); - + if (values.description !== "") formData.append("expert_description", values.description); + if (values.confirm_img != null) { + const attachments = [ + { + title: "فایل ضمیمه کارتابل بررسی وام های تبصره 18", + file: values.confirm_img + } + ]; + attachments.forEach((attachment, index) => { + formData.append(`attachment[${index}][title]`, attachment.title); + formData.append(`attachment[${index}][file]`, attachment.file); + }); + } requestServer(`${CONFIRM_NAVGAN_PROVINCE_MANAGER}/${rowId}`, 'post', { data: formData, + notification: true }).then((response) => { setOpenConfirmDialog(false) mutate() @@ -121,8 +145,8 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl }; const renderCustomAccordions = () => { - if (detailsList && detailsList.data && detailsList.data.attachment_files) { - return detailsList.data.attachment_files.map((file, index) => ( + if (attachmentsData) { + return attachmentsData.map((file, index) => ( handleAccordionChange(index)} accordionIndex={index} - downloadFile={file.attachment} + downloadFile={file.file} /> )); } return null; }; - const numberShowBox = () => { - return ( - <> - - {t("ConfirmDialog.proposed_amount")} - - {isNaN((detailsList?.data?.proposed_amount) / 10) - ? "" - : ((detailsList?.data?.proposed_amount) / 10).toLocaleString()}{" "} - {t("ConfirmDialog.unit")} - - - - {t("ConfirmDialog.approved_amount")} {t("secondary.passenger-boss")} - - {isNaN((detailsList?.data?.approved_amount) / 10) - ? "" - : ((detailsList?.data?.approved_amount) / 10).toLocaleString()}{" "} - {t("ConfirmDialog.unit")} - - - - ); - }; - return ( <> @@ -173,7 +168,26 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl {loading ? : <> - {numberShowBox()} + + + + {renderCustomAccordions()} } diff --git a/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx index 0b26c8b..8533094 100644 --- a/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx @@ -30,8 +30,18 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("expert_description", values.description); - if (values.reject_img != null) formData.append("attachment", values.reject_img); - + if (values.reject_img != null) { + const attachments = [ + { + title: "فایل ضمیمه کارتابل بررسی وام های تبصره 18", + file: values.reject_img + } + ]; + attachments.forEach((attachment, index) => { + formData.append(`attachment[${index}][title]`, attachment.title); + formData.append(`attachment[${index}][file]`, attachment.file); + }); + } requestServer(`${REJECT_NAVGAN_PROVINCE_MANAGER}/${rowId}`, 'post', { data: formData, }).then((response) => { diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx index a3a5580..8dfee61 100644 --- a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx @@ -2,7 +2,6 @@ import UploadSystem from "@/core/components/UploadSystem"; import useNotification from "@/lib/app/hooks/useNotification"; import useRequest from "@/lib/app/hooks/useRequest"; import { - Box, Button, DialogActions, DialogContent, @@ -21,6 +20,7 @@ import PriceField from "@/core/components/PriceField"; import * as Yup from "yup"; import CustomAccordion from "@/core/components/CustomAccordion"; import ImageContent from "@/core/components/ImageContent"; +import NumberShowBox from "@/core/components/NumberShowBox"; const vehicle_amount = { "اتوبوس": 7000, @@ -131,6 +131,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, vehicle_type, hand requestServer(`${CONFIRM_PASSENGER_BOSS}/${rowId}`, 'post',{ notification: true, data: formData, + notification: true }).then((response) => { setOpenConfirmDialog(false) mutate() @@ -198,22 +199,6 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, vehicle_type, hand } return null; }; - const numberShowBox = () => { - return ( - <> - - {t("ConfirmDialog.proposed_amount")} - - {isNaN((detailsList?.data?.proposed_amount) / 10) - ? "" - : ((detailsList?.data?.proposed_amount) / 10).toLocaleString()}{" "} - {t("ConfirmDialog.unit")} - - - - ); - }; return ( <> @@ -222,7 +207,21 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, vehicle_type, hand {loading ? : <> - {numberShowBox()} + + + {renderCustomAccordions()} } diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx index 9480f7a..ae1ceea 100644 --- a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx @@ -3,9 +3,9 @@ import useNotification from "@/lib/app/hooks/useNotification"; import useRequest from "@/lib/app/hooks/useRequest"; import { Box, - Button, + Button, Checkbox, DialogActions, - DialogContent, + DialogContent, FormControlLabel, FormHelperText, Grid, LinearProgress, @@ -20,6 +20,7 @@ import {useEffect, useState} from "react"; import * as Yup from "yup"; import CustomAccordion from "@/core/components/CustomAccordion"; import ImageContent from "@/core/components/ImageContent"; +import NumberShowBox from "@/core/components/NumberShowBox"; const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeClick}) => { const t = useTranslations(); @@ -27,7 +28,8 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl const [fileType, setfileType] = useState(null); const [fileName, setfileName] = useState(null); const [showAddIcon, setShowAddIcon] = useState(true); - const requestServer = useRequest({auth: true, notification: false}) + const requestServer = useRequest({auth: true, notification: false}); + const [attachmentsData, setAttachmentsData] = useState([]); const [accordionStates, setAccordionStates] = useState([]); const [hasAccordionOpened, setHasAccordionOpened] = useState([]); const {update_notification} = useNotification(); @@ -36,14 +38,19 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl const [detailsList, setDetailsData] = useState(null); const [loading, setLoading] = useState(true); const [isSkeleton, setIsSkeleton] = useState(false); + const [checked, setChecked] = useState(false); useEffect(() => { requestServer(`${GET_TRANSPORTATION_ASSISTANCE_DETAILS}/${rowId}`, 'get') .then((response) => { - const booleanData = Array.from({length: response.data.data.attachment_files.length}, () => false); - setAccordionStates(booleanData); - setHasAccordionOpened(booleanData); - setDetailsData(response.data) + const allAttachments = []; + response.data.data.histories.map((history) => { + history.attachments.map((attachment) => { + allAttachments.push(attachment); + }); + }); + setDetailsData(response.data); + setAttachmentsData(allAttachments); }) .catch(() => { }).finally(() => { @@ -51,6 +58,14 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl }); }, []); + useEffect(() => { + if (attachmentsData.length !== 0) { + const booleanData = Array.from({length: attachmentsData.length}, () => false); + setAccordionStates(booleanData); + setHasAccordionOpened(booleanData); + } + }, [attachmentsData]); + const handleAccordionChange = (index) => { const newAccordionStates = accordionStates.map((state, i) => i === index ? !state : false); setAccordionStates(newAccordionStates); @@ -58,12 +73,12 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl if (!newAccordionStates[index]) { handleSizeChangeClick('sm'); setHasImageShown(false); - setIsSkeleton(false) + setIsSkeleton(false); } else { handleSizeChangeClick('xl'); setHasImageShown(true); - setImageLink(detailsList.data.attachment_files[index]) - setIsSkeleton(true) + setImageLink(attachmentsData[index]); + setIsSkeleton(true); const newHasAccordionOpened = [...hasAccordionOpened]; newHasAccordionOpened[index] = true; setHasAccordionOpened(newHasAccordionOpened); @@ -91,11 +106,22 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl }, validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - if (values.description != "") formData.append("expert_description", values.description); - if (values.confirm_img != null) formData.append("attachment", values.confirm_img); - + if (values.description !== "") formData.append("expert_description", values.description); + if (values.confirm_img != null) { + const attachments = [ + { + title: "فایل ضمیمه کارتابل بررسی وام های تبصره 18", + file: values.confirm_img + } + ]; + attachments.forEach((attachment, index) => { + formData.append(`attachment[${index}][title]`, attachment.title); + formData.append(`attachment[${index}][file]`, attachment.file); + }); + } requestServer(`${CONFIRM_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { data: formData, + notification: true }).then((response) => { setOpenConfirmDialog(false) mutate() @@ -125,10 +151,13 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl setShowAddIcon(false); } }; + const handleCheckboxChange = (event) => { + setChecked(event.target.checked); + }; const renderCustomAccordions = () => { - if (detailsList && detailsList.data && detailsList.data.attachment_files) { - return detailsList.data.attachment_files.map((file, index) => ( + if (attachmentsData) { + return attachmentsData.map((file, index) => ( handleAccordionChange(index)} accordionIndex={index} - downloadFile={file.attachment} + downloadFile={file.file} /> )); } return null; }; - const numberShowBox = () => { - return ( - <> - - {t("ConfirmDialog.proposed_amount")} - - {isNaN((detailsList?.data?.proposed_amount) / 10) - ? "" - : ((detailsList?.data?.proposed_amount) / 10).toLocaleString()}{" "} - {t("ConfirmDialog.unit")} - - - - {t("ConfirmDialog.approved_amount")} {t("secondary.passenger-boss")} - - {isNaN((detailsList?.data?.approved_amount) / 10) - ? "" - : ((detailsList?.data?.approved_amount) / 10).toLocaleString()}{" "} - {t("ConfirmDialog.unit")} - - - - ); - }; return ( <> @@ -177,7 +178,26 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl {loading ? : <> - {numberShowBox()} + + + + {renderCustomAccordions()} } @@ -188,7 +208,9 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl multiline rows={8} label={<> - {t("ConfirmDialog.description")}{t("ConfirmDialog.optional")}} + {t("ConfirmDialog.description")} + {t("ConfirmDialog.optional")} + } value={formik.values.description} onChange={handleDescriptionChange} fullWidth @@ -216,12 +238,22 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl Boolean(formik.errors.confirm_img) } /> - + {formik.touched.confirm_img && formik.errors.confirm_img} + + + } + label={t("TransportationAssistance.confirm_text")} + /> + @@ -243,7 +275,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, handleSizeChangeCl diff --git a/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx index b692df4..e370041 100644 --- a/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx @@ -30,8 +30,18 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("expert_description", values.description); - if (values.reject_img != null) formData.append("attachment", values.reject_img); - + if (values.reject_img != null) { + const attachments = [ + { + title: "فایل ضمیمه کارتابل بررسی وام های تبصره 18", + file: values.reject_img + } + ]; + attachments.forEach((attachment, index) => { + formData.append(`attachment[${index}][title]`, attachment.title); + formData.append(`attachment[${index}][file]`, attachment.file); + }); + } requestServer(`${REJECT_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { data: formData, }).then((response) => { diff --git a/src/core/components/CustomAccordion.jsx b/src/core/components/CustomAccordion.jsx index 20ba932..de0c646 100644 --- a/src/core/components/CustomAccordion.jsx +++ b/src/core/components/CustomAccordion.jsx @@ -3,17 +3,28 @@ import { AccordionDetails, AccordionSummary, Box, - Typography, - Grid, ButtonGroup, Button, CircularProgress + Button, + ButtonGroup, + CircularProgress, + Grid, + Typography } from "@mui/material"; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import VerifiedIcon from '@mui/icons-material/Verified'; import Check from "@mui/icons-material/Check"; import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined"; import {useState} from "react"; -const CustomAccordion = ({ title, hasOpened, hasAccordionOpened, handleAccordionChange, accordionIndex , downloadFile}) => { + +const CustomAccordion = ({ + title, + hasOpened, + hasAccordionOpened, + handleAccordionChange, + accordionIndex, + downloadFile + }) => { const [downloadStatus, setDownloadStatus] = useState('initial'); - const handleDownloadClick = (setStatus , url) => { + const handleDownloadClick = (setStatus, url) => { setStatus('downloading'); window.open(url, '_blank'); setTimeout(() => { @@ -23,39 +34,40 @@ const CustomAccordion = ({ title, hasOpened, hasAccordionOpened, handleAccordion }, 1200); }, 1000); }; - return( - handleAccordionChange(accordionIndex)} sx={{ - mb: 2, - boxShadow: 1, - backgroundColor: "#f7f7f7" - }}> - }> - - - {title} - {hasAccordionOpened && } + return ( + handleAccordionChange(accordionIndex)} + sx={{ + mb: 2, + boxShadow: 1, + backgroundColor: "#f7f7f7" + }}> + }> + + + {title} + {hasAccordionOpened && } + - - - - - - - - + + + + + + + + - - - -); + + + ); } export default CustomAccordion; diff --git a/src/core/components/ImageContent.jsx b/src/core/components/ImageContent.jsx index f99e2e8..bf96a4b 100644 --- a/src/core/components/ImageContent.jsx +++ b/src/core/components/ImageContent.jsx @@ -1,30 +1,46 @@ import {Box, Skeleton, Stack} from "@mui/material"; import {useEffect} from "react"; + const ImageContent = (prop) => { useEffect(() => { const timer = setTimeout(() => { prop.setIsSkeleton(false); }, 1500); - return () => clearTimeout(timer); }, [prop.isSkeleton]); - - const isPDF = prop.imageLink && prop.imageLink.attachment && prop.imageLink.attachment.endsWith('.pdf'); + const isPDF = prop.imageLink && prop.imageLink.file && prop.imageLink.file.endsWith('.pdf'); return ( <> - + {prop.isSkeleton && ( - - + + )} {isPDF ? ( - + ) : ( - prop.imageLink && prop.imageLink.attachment && ( - - + prop.imageLink && prop.imageLink.file && ( + + ) )} diff --git a/src/core/components/NumberShowBox.jsx b/src/core/components/NumberShowBox.jsx new file mode 100644 index 0000000..b8e45b1 --- /dev/null +++ b/src/core/components/NumberShowBox.jsx @@ -0,0 +1,19 @@ +import {Box, Typography} from "@mui/material"; + +const NumberShowBox = ({showNumber, headerTitle, unitTitle}) => { + return ( + <> + + {headerTitle} + + {isNaN(showNumber) || showNumber === null + ? "" + : (showNumber).toLocaleString()}{" "} + {unitTitle} + + + + ); +}; +export default NumberShowBox \ No newline at end of file