From fb7bb856b5f7d59ea10e5800e0b6b25f3278b0d2 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Tue, 14 Nov 2023 11:10:27 +0330 Subject: [PATCH] LFFE-19 get vehicle type and set maximum number base on it --- public/locales/fa/app.json | 4 ++-- .../Form/ConfirmForm/ConfirmContent.jsx | 22 +++++++++++-------- .../Form/ConfirmForm/index.jsx | 6 +++-- .../machinary-office/TableRowActions.jsx | 2 +- .../Form/ConfirmForm/ConfirmContent.jsx | 15 +++++++++---- .../passenger-boss/Form/ConfirmForm/index.jsx | 6 +++-- .../passenger-boss/TableRowActions.jsx | 1 + 7 files changed, 36 insertions(+), 20 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 27d4b0e..0481f1a 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -206,7 +206,7 @@ "upload_file_required": "وارد کردن صورت جلسه کارگروه استانی الزامیست", "upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد", "upload_file_format": "فرمت قابل قبول : png,jpg,pdf", - "max_amount": "حداکثر مبلغ پیشنهادی {value} تومان می باشد" + "max_amount": "حداکثر مبلغ تصویب شده {value} میلیون تومان می باشد" }, "RefahiProvinceManager": { "name": "نام", @@ -305,7 +305,7 @@ "upload_file_required": "وارد کردن گزارش کارشناسی الزامیست", "upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد", "upload_file_format": "فرمت قابل قبول : png,jpg,pdf", - "max_amount": "حداکثر مبلغ پیشنهادی {value} هزار تومان می باشد" + "max_amount": "حداکثر مبلغ پیشنهادی {value} میلیون تومان می باشد" }, "UserManagement": { "name": "نام", diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx index 62b704c..93ee5a2 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx @@ -9,8 +9,7 @@ import {useState} from "react"; import PriceField from "@/core/components/PriceField"; import * as Yup from "yup"; -const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { - const max_amount_number = 70000000000 +const ConfirmContent = ({mutate, setOpenConfirmDialog, rowId, vehicle_type}) => { const t = useTranslations(); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); @@ -18,24 +17,30 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { const [showAddIcon, setShowAddIcon] = useState(true); const requestServer = useRequest({auth: true}) const {update_notification} = useNotification() - + let max_amount_number + if (vehicle_type === "اتوبوس") { + max_amount_number = 7000 + } else if (vehicle_type === "مینی بوس") { + max_amount_number = 2000 + } else { + max_amount_number = 5000 + } 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(max_amount_number).toLocaleString('en')})}`, (value) => value <= max_amount_number) + ).test("max-amount", `${t("MachinaryOffice.max_amount", {value: parseInt(max_amount_number / 10).toLocaleString('en')})}`, + (value) => value <= max_amount_number) .test("positive", `${t("ConfirmDialog.proposed_amount_positive")}`, (value) => value >= 0) .required(t("ConfirmDialog.proposed_amount_error")), confirm_img: Yup.mixed() .required(t("MachinaryOffice.upload_file_required")) .test('fileSize', `${t("MachinaryOffice.upload_file_unit")}`, (value) => { - // if (!value) return true; // Skip if no file is provided - return value.size <= 2 * 1024 * 1024; // 100KB limit (adjust as needed) + return value.size <= 2 * 1024 * 1024; }) .test('fileType', `${t("MachinaryOffice.upload_file_format")}`, (value) => { - // if (!value) return true; // Skip if no file is provided - const allowedTypes = ['image/jpg', 'image/jpeg', 'image/png', 'application/pdf']; // Define your allowed file types + const allowedTypes = ['image/jpg', 'image/jpeg', 'image/png', 'application/pdf']; return allowedTypes.includes(value.type); }) }); @@ -51,7 +56,6 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { formData.append("proposed_amount", values.proposed_amount); if (values.description != "") formData.append("expert_description", values.description); if (values.confirm_img != null) formData.append("attachment", values.confirm_img); - requestServer(`${CONFIRM_MACHINARY_OFFICE}/${rowId}`, 'post', { data: formData, }).then((response) => { diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx index 5ed809f..3affc7b 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm/index.jsx @@ -3,7 +3,8 @@ import {useTranslations} from "next-intl"; import {useState} from "react"; import ConfirmContent from "./ConfirmContent"; import CallMadeIcon from '@mui/icons-material/CallMade'; -const Confirm = ({rowId, mutate}) => { + +const Confirm = ({rowId, mutate, vehicle_type}) => { const t = useTranslations(); const [openConfirmDialog, setOpenConfirmDialog] = useState(false); return ( @@ -21,7 +22,8 @@ const Confirm = ({rowId, mutate}) => { {t("MachinaryOffice.confirm")} - + ) diff --git a/src/components/dashboard/machinary-office/TableRowActions.jsx b/src/components/dashboard/machinary-office/TableRowActions.jsx index 69f9d6f..f50938e 100644 --- a/src/components/dashboard/machinary-office/TableRowActions.jsx +++ b/src/components/dashboard/machinary-office/TableRowActions.jsx @@ -3,11 +3,11 @@ import Confirm from "./Form/ConfirmForm"; import Reject from "./Form/RejectForm"; const TableRow = ({row, mutate}) => { - return ( { - const max_amount_number = 70000000000 +const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, vehicle_type}) => { const t = useTranslations(); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); @@ -18,14 +17,22 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { const [showAddIcon, setShowAddIcon] = useState(true); const requestServer = useRequest({auth: true}) const {update_notification} = useNotification() - + let max_amount_number + if (vehicle_type === "اتوبوس") { + max_amount_number = 7000 + } else if (vehicle_type === "مینی بوس") { + max_amount_number = 2000 + } else { + max_amount_number = 5000 + } const validationSchema = Yup.object().shape({ approved_amount: Yup.mixed().test( "is-number", `${t("ConfirmDialog.approved_amount_number")}`, (value) => !isNaN(value) - ).test("max-amount", `${t("PassengerBoss.max_amount", {value: parseInt(max_amount_number).toLocaleString('en')})}`, (value) => value <= max_amount_number) + ).test("max-amount", `${t("PassengerBoss.max_amount", {value: parseInt(max_amount_number / 10).toLocaleString('en')})}`, + (value) => value <= max_amount_number) .test("positive", `${t("ConfirmDialog.approved_amount_positive")}`, (value) => value >= 0) .required(t("ConfirmDialog.approved_amount_error")), confirm_img: Yup.mixed() diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm/index.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm/index.jsx index 30f15dd..004d119 100644 --- a/src/components/dashboard/passenger-boss/Form/ConfirmForm/index.jsx +++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm/index.jsx @@ -3,7 +3,8 @@ import {useTranslations} from "next-intl"; import {useState} from "react"; import ConfirmContent from "./ConfirmContent"; import CallMadeIcon from '@mui/icons-material/CallMade'; -const Confirm = ({rowId, mutate}) => { + +const Confirm = ({rowId, mutate, vehicle_type}) => { const t = useTranslations(); const [openConfirmDialog, setOpenConfirmDialog] = useState(false); return ( @@ -21,7 +22,8 @@ const Confirm = ({rowId, mutate}) => { {t("PassengerBoss.confirm")} - + ) diff --git a/src/components/dashboard/passenger-boss/TableRowActions.jsx b/src/components/dashboard/passenger-boss/TableRowActions.jsx index d10e248..cef474d 100644 --- a/src/components/dashboard/passenger-boss/TableRowActions.jsx +++ b/src/components/dashboard/passenger-boss/TableRowActions.jsx @@ -8,6 +8,7 @@ const TableRow = ({row, mutate}) => {