diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx index f0a8c12..c53c4c4 100644 --- a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx @@ -1,26 +1,80 @@ import UploadSystem from "@/core/components/UploadSystem"; import useNotification from "@/lib/app/hooks/useNotification"; import useRequest from "@/lib/app/hooks/useRequest"; -import {Button, DialogActions, DialogContent, FormHelperText, Stack, TextField, Typography} from "@mui/material" +import { + Box, + Button, + DialogActions, + DialogContent, + FormHelperText, + Grid, + LinearProgress, + Stack, + TextField, + Typography +} from "@mui/material" import {useFormik} from "formik"; import {useTranslations} from "next-intl"; -import {CONFIRM_PASSENGER_BOSS} from "@/core/data/apiRoutes"; -import {useState} from "react"; +import { + CONFIRM_PASSENGER_BOSS, + EXPORT_PASSENGER_BOSS_DETAILS, +} from "@/core/data/apiRoutes"; +import {useEffect, useState} from "react"; import PriceField from "@/core/components/PriceField"; import * as Yup from "yup"; +import CustomAccordion from "@/core/components/CustomAccordion"; +import ImageContent from "@/core/components/ImageContent"; const vehicle_amount = { "اتوبوس": 7000, "مینی بوس": 2000, } -const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, vehicle_type}) => { +const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, 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}) - const {update_notification} = useNotification() + const requestServer = useRequest({auth: true ,notification: false}) + const {update_notification} = useNotification(); + const [accordionStates, setAccordionStates] = useState([]); + const [hasImageShown, setHasImageShown] = useState(false); + const [imageLink, setImageLink] = useState(null); + const [detailsList, setDetailsData] = useState(null); + const [loading, setLoading] = useState(true); + const [isSkeleton, setIsSkeleton] = useState(false); + + useEffect(() => { + requestServer(`${EXPORT_PASSENGER_BOSS_DETAILS}/${rowId}`, 'get') + .then((response) => { + const booleanData = Array.from({ length: response.data.data.attachment_files.length }, () => false); + setAccordionStates(booleanData); + setDetailsData(response.data) + }) + .catch(() => { + }).finally(() => { + setLoading(false); + }); + }, []); + + const handleAccordionChange = (index) => { + const newAccordionStates = accordionStates.map((state, i) => i === index ? !state : false); + setAccordionStates(newAccordionStates); + + if (!newAccordionStates[index]) + { + handleSizeChangeClick('sm'); + setHasImageShown(false); + setIsSkeleton(false) + } + else { + handleSizeChangeClick('xl'); + setHasImageShown(true); + setImageLink(detailsList.data.attachment_files[index]) + setIsSkeleton(true) + } + }; + const validationSchema = Yup.object().shape({ approved_amount: Yup.mixed().test( @@ -92,77 +146,114 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog, vehicle_type}) => formik.setFieldValue("approved_amount", formik.values.approved_amount) } }; + + const renderCustomAccordions = () => { + if (detailsList && detailsList.data && detailsList.data.attachment_files) { + return detailsList.data.attachment_files.map((file, index) => ( + handleAccordionChange(index)} + accordionIndex={index} + downloadFile={file.attachment} + /> + )); + } + return null; + }; + return ( <> - - - - {t("ConfirmDialog.description")}{t("ConfirmDialog.optional")}} - value={formik.values.description} - onChange={handleDescriptionChange} - fullWidth - variant="outlined" - sx={{mt: 1}} - /> - - - - {t("ConfirmDialog.approved_amount")}{t("ConfirmDialog.unit")}} - type="text" - inputProps={{ - inputMode: "number", - min: 0, - pattern: "[0-9]*", - }} - variant="outlined" - value={formik.values.approved_amount} - onChange={handleAmountChange} - onBlur={formik.handleBlur("approved_amount")} - error={ - formik.touched.approved_amount && - Boolean(formik.errors.approved_amount) - } - helperText={ - formik.touched.approved_amount && formik.errors.approved_amount - } - sx={{mt: 1}} - fullWidth - /> - - - {t("PassengerBoss.upload_file")} - formik.handleBlur("confirm_img")} - error={ - formik.touched.confirm_img && - Boolean(formik.errors.confirm_img) - } - /> - - {formik.touched.confirm_img && formik.errors.confirm_img} - - - + + + + {t("ConfirmDialog.approved_amount")} {t("sidebar.machinery-expert")} + + {isNaN((detailsList?.data?.proposed_amount) / 10) + ? "" + : ((detailsList?.data?.proposed_amount) / 10).toLocaleString()}{" "} + {t("ConfirmDialog.unit")} + + + {loading ? : renderCustomAccordions()} + + + + {t("ConfirmDialog.description")}{t("ConfirmDialog.optional")}} + value={formik.values.description} + onChange={handleDescriptionChange} + fullWidth + variant="outlined" + sx={{mt: 1}} + /> + + + + {t("ConfirmDialog.approved_amount")}{t("ConfirmDialog.unit")}} + type="text" + inputProps={{ + inputMode: "number", + min: 0, + pattern: "[0-9]*", + }} + variant="outlined" + value={formik.values.approved_amount} + onChange={handleAmountChange} + onBlur={formik.handleBlur("approved_amount")} + error={ + formik.touched.approved_amount && + Boolean(formik.errors.approved_amount) + } + helperText={ + formik.touched.approved_amount && formik.errors.approved_amount + } + sx={{mt: 1}} + fullWidth + /> + + + {t("PassengerBoss.upload_file")} + formik.handleBlur("confirm_img")} + error={ + formik.touched.confirm_img && + Boolean(formik.errors.confirm_img) + } + /> + + {formik.touched.confirm_img && formik.errors.confirm_img} + + + + + + + + + +