LFFE-21 Merge branch 'feature/LFFE-21_transportation_assistance_show_file' into 'develop'
This commit is contained in:
@@ -1,21 +1,88 @@
|
||||
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_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes";
|
||||
import {useState} from "react";
|
||||
import {CONFIRM_TRANSPORTATION_ASSISTANCE, GET_TRANSPORTATION_ASSISTANCE_DETAILS} from "@/core/data/apiRoutes";
|
||||
import {useEffect, useState} from "react";
|
||||
import * as Yup from "yup";
|
||||
|
||||
const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
|
||||
import CustomAccordion from "@/core/components/CustomAccordion";
|
||||
import ImageContent from "@/components/dashboard/transportation-assistance/Form/ConfirmForm/ImageContent";
|
||||
const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog ,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 [accordionStates, setAccordionStates] = useState([]);
|
||||
const [hasAccordionOpened, setHasAccordionOpened] = useState([]);
|
||||
const {update_notification} = useNotification();
|
||||
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);
|
||||
const [isButtonDisabled, setIsButtonDisabled] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
requestServer(`${GET_TRANSPORTATION_ASSISTANCE_DETAILS}/${rowId}`, 'get')
|
||||
.then((response) => {
|
||||
const booleanArray = Array.from({ length: response.data.data.attachment_files.length }, () => false);
|
||||
setAccordionStates(booleanArray);
|
||||
setHasAccordionOpened(booleanArray);
|
||||
setDetailsData(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
}).finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (detailsList && detailsList.data && detailsList.data.attachment_files && detailsList.data.attachment_files.length !== 0) {
|
||||
setIsButtonDisabled(true);
|
||||
} else {
|
||||
setIsButtonDisabled(false);
|
||||
}
|
||||
}, [detailsList]);
|
||||
|
||||
const handleAccordionChange = (index) => {
|
||||
const newAccordionStates = accordionStates.map((state, i) => i === index ? !state : false);
|
||||
setAccordionStates(newAccordionStates);
|
||||
|
||||
if (newAccordionStates[index]===false)
|
||||
{
|
||||
handleSizeChangeClick(index , false);
|
||||
sethasImageShown(false);
|
||||
setIsSkeleton(false)
|
||||
}
|
||||
else {
|
||||
handleSizeChangeClick(index , true);
|
||||
sethasImageShown(true);
|
||||
setimageLink(detailsList.data.attachment_files[index])
|
||||
setIsSkeleton(true)
|
||||
const newHasAccordionOpened = [...hasAccordionOpened];
|
||||
newHasAccordionOpened[index] = true;
|
||||
setHasAccordionOpened(newHasAccordionOpened);
|
||||
|
||||
if (newHasAccordionOpened.every(opened => opened === true)) {
|
||||
setIsButtonDisabled(false)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
confirm_img: Yup.mixed().notRequired(t("ConfirmDialog.approved_amount_error"))
|
||||
@@ -72,51 +139,96 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
|
||||
}
|
||||
};
|
||||
|
||||
const renderCustomAccordions = () => {
|
||||
if (detailsList && detailsList.data && detailsList.data.attachment_files) {
|
||||
return detailsList.data.attachment_files.map((file, index) => (
|
||||
<CustomAccordion
|
||||
key={index}
|
||||
title={`${file.title}`}
|
||||
hasOpened={accordionStates[index]}
|
||||
hasAccordionOpened={hasAccordionOpened[index]}
|
||||
handleAccordionChange={() => handleAccordionChange(index)}
|
||||
accordionIndex={index}
|
||||
handleSizeChange={() => handleSizeChange(index)}
|
||||
/>
|
||||
));
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<DialogContent>
|
||||
<Stack spacing={2}>
|
||||
<Stack>
|
||||
<TextField
|
||||
name="description"
|
||||
multiline
|
||||
rows={8}
|
||||
label={<>
|
||||
<span>{t("ConfirmDialog.description")}</span><small>{t("ConfirmDialog.optional")}</small></>}
|
||||
value={formik.values.description}
|
||||
onChange={handleDescriptionChange}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
sx={{mt: 1}}
|
||||
/>
|
||||
</Stack>
|
||||
<Stack>
|
||||
<Typography>{t("UploadSystem.upload_file")}{t("UploadSystem.optional")}</Typography>
|
||||
<UploadSystem
|
||||
selectedImage={selectedImage}
|
||||
handleUploadChange={handleUploadChange} // Pass the updated function directly
|
||||
setselectedImage={setSelectedImage}
|
||||
setFieldValue={formik.setFieldValue} // Remove props.setFieldValue, use formik.setFieldValue
|
||||
fieldname="confirm_img"
|
||||
fileType={fileType}
|
||||
fileName={fileName}
|
||||
imageAlt={t("app_name")}
|
||||
imageSize={[250, 150]}
|
||||
setShowAddIcon={setShowAddIcon}
|
||||
showAddIcon={showAddIcon}
|
||||
onBlur={() => formik.handleBlur("confirm_img")}
|
||||
error={
|
||||
formik.touched.confirm_img &&
|
||||
Boolean(formik.errors.confirm_img)
|
||||
}
|
||||
/>
|
||||
<FormHelperText
|
||||
error={Boolean(formik.errors.confirm_img)}
|
||||
>
|
||||
{formik.touched.confirm_img && formik.errors.confirm_img}
|
||||
</FormHelperText>
|
||||
</Stack>
|
||||
</Stack>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={hasImageShown ? 6 : 12}>
|
||||
<Box sx={{ border: '1px solid #ccc' ,p:2 , mb:2 , borderRadius: '8px'}}>
|
||||
<Typography sx={{color: "primary.main" , fontWeight: 500}}>{t("ConfirmDialog.approved_amount")} {t("sidebar.machinery-expert")}</Typography>
|
||||
<Typography pt={1}>
|
||||
{isNaN((detailsList?.data?.proposed_amount) / 10)
|
||||
? ""
|
||||
: ((detailsList?.data?.proposed_amount) / 10).toLocaleString()}{" "}
|
||||
{t("ConfirmDialog.unit")}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ border: '1px solid #ccc' ,p:2 , mb:2 , borderRadius: '8px'}}>
|
||||
<Typography sx={{color: "primary.main" , fontWeight: 500}}>{t("ConfirmDialog.approved_amount")} {t("secondary.passenger-boss")}</Typography>
|
||||
<Typography pt={1}>
|
||||
{isNaN((detailsList?.data?.approved_amount) / 10)
|
||||
? ""
|
||||
: ((detailsList?.data?.approved_amount) / 10).toLocaleString()}{" "}
|
||||
{t("ConfirmDialog.unit")}
|
||||
</Typography>
|
||||
</Box>
|
||||
{loading ? <LinearProgress /> : renderCustomAccordions()}
|
||||
<Stack spacing={2}>
|
||||
<Stack>
|
||||
<TextField
|
||||
name="description"
|
||||
multiline
|
||||
rows={8}
|
||||
label={<>
|
||||
<span>{t("ConfirmDialog.description")}</span><small>{t("ConfirmDialog.optional")}</small></>}
|
||||
value={formik.values.description}
|
||||
onChange={handleDescriptionChange}
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
sx={{mt: 1}}
|
||||
/>
|
||||
</Stack>
|
||||
<Stack>
|
||||
<Typography>{t("UploadSystem.upload_file")}{t("UploadSystem.optional")}</Typography>
|
||||
<UploadSystem
|
||||
selectedImage={selectedImage}
|
||||
handleUploadChange={handleUploadChange}
|
||||
setselectedImage={setSelectedImage}
|
||||
setFieldValue={formik.setFieldValue}
|
||||
fieldname="confirm_img"
|
||||
fileType={fileType}
|
||||
fileName={fileName}
|
||||
imageAlt={t("app_name")}
|
||||
imageSize={[250, 150]}
|
||||
setShowAddIcon={setShowAddIcon}
|
||||
showAddIcon={showAddIcon}
|
||||
onBlur={() => formik.handleBlur("confirm_img")}
|
||||
error={
|
||||
formik.touched.confirm_img &&
|
||||
Boolean(formik.errors.confirm_img)
|
||||
}
|
||||
/>
|
||||
<FormHelperText
|
||||
error={Boolean(formik.errors.confirm_img)}
|
||||
>
|
||||
{formik.touched.confirm_img && formik.errors.confirm_img}
|
||||
</FormHelperText>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Stack sx={{ display: hasImageShown ? 'flex' : 'none', alignItems: 'center', gap: 0.5 , justifyContent:'center'}}>
|
||||
<ImageContent imageLink={imageLink} isSkeleton={isSkeleton} setIsSkeleton={setIsSkeleton}/>
|
||||
</Stack>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setOpenConfirmDialog(false)} variant="outlined" color="secondary"
|
||||
@@ -124,7 +236,9 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
|
||||
{t("ConfirmDialog.button-cancel")}
|
||||
</Button>
|
||||
<Button onClick={formik.handleSubmit} variant="contained" color="primary"
|
||||
disabled={formik.isSubmitting || !formik.isValid}>
|
||||
disabled={formik.isSubmitting || !formik.isValid ||
|
||||
isButtonDisabled }
|
||||
>
|
||||
{t("ConfirmDialog.button-confirm")}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import {Box, Skeleton, Stack} from "@mui/material";
|
||||
import {useEffect} from "react";
|
||||
const ImageContent = (link) => {
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
link.setIsSkeleton(false);
|
||||
}, 1000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [link.isSkeleton]);
|
||||
|
||||
const isPDF = link && link.imageLink && link.imageLink.attachment && link.imageLink.attachment.endsWith('.pdf');
|
||||
return (
|
||||
<>
|
||||
<Stack sx={{width :"100%"}}>
|
||||
{link.isSkeleton && (
|
||||
<Box sx={{display:'flex' ,justifyContent:'center' , border: '1px solid #ccc' ,p:5 , height: '700px' , borderRadius: '8px' , width:'100%'}}>
|
||||
<Skeleton variant="rectangular" animation="wave" sx={{ width: '100%', height: '100%' }} />
|
||||
</Box>
|
||||
)}
|
||||
{isPDF ? (
|
||||
<embed src={link.imageLink.attachment} type="application/pdf" width="100%" height="700px" style={{ display: link.isSkeleton ? 'none' : 'block' }}/>
|
||||
) : (
|
||||
link && link.imageLink && link.imageLink.attachment && (
|
||||
<Box sx={{display: link.isSkeleton ? 'none' : 'flex' ,justifyContent:'center' , border: '1px solid #ccc' , p:5 , height: '700px' , borderRadius: '8px',}}>
|
||||
<Box component="img" src={link.imageLink.attachment} alt="Image Preview" width="auto" height="auto" sx={{maxHeight: '700px' , maxWidth:'100%'}}></Box>
|
||||
</Box>
|
||||
)
|
||||
)}
|
||||
</Stack>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
export default ImageContent;
|
||||
@@ -1,27 +1,45 @@
|
||||
import {Dialog, DialogTitle, IconButton, Tooltip} from "@mui/material";
|
||||
import {Dialog, DialogTitle, IconButton, Tooltip} from "@mui/material";
|
||||
import {useTranslations} from "next-intl";
|
||||
import {useState} from "react";
|
||||
import {useState , useEffect} from "react";
|
||||
import ConfirmContent from "./ConfirmContent";
|
||||
import CallMadeIcon from '@mui/icons-material/CallMade';
|
||||
const Confirm = ({rowId, mutate}) => {
|
||||
const t = useTranslations();
|
||||
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||
const [dialogSize, setDialogSize] = useState('sm');
|
||||
|
||||
useEffect(() => {
|
||||
if (!openConfirmDialog) {
|
||||
setDialogSize('sm');
|
||||
}
|
||||
}, [openConfirmDialog]);
|
||||
|
||||
const handleSizeChangeClick = (num , state) => {
|
||||
if (state===true){
|
||||
setDialogSize('xl');
|
||||
|
||||
}
|
||||
else {
|
||||
setDialogSize('sm');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Tooltip title={t("ConfirmDialog.confirm")}>
|
||||
<IconButton
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
setOpenConfirmDialog(true)
|
||||
setOpenConfirmDialog(true);
|
||||
}}
|
||||
>
|
||||
<CallMadeIcon/>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Dialog fullWidth open={openConfirmDialog}
|
||||
PaperProps={{sx: {boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px'}}}>
|
||||
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}>
|
||||
<DialogTitle>{t("TransportationAssistance.confirm")}</DialogTitle>
|
||||
<ConfirmContent mutate={mutate} rowId={rowId} setOpenConfirmDialog={setOpenConfirmDialog}/>
|
||||
<ConfirmContent mutate={mutate} rowId={rowId} setOpenConfirmDialog={setOpenConfirmDialog} setDialogSize={setDialogSize} handleSizeChangeClick={handleSizeChangeClick}/>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
|
||||
72
src/core/components/CustomAccordion.jsx
Normal file
72
src/core/components/CustomAccordion.jsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
Accordion,
|
||||
AccordionDetails,
|
||||
AccordionSummary,
|
||||
Box,
|
||||
Typography,
|
||||
Grid, ButtonGroup, Button, CircularProgress
|
||||
} 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 VisibilityRoundedIcon from "@mui/icons-material/VisibilityRounded";
|
||||
import {useTranslations} from "next-intl";
|
||||
import {useState} from "react";
|
||||
|
||||
const CustomAccordion = ({ title,
|
||||
hasOpened,
|
||||
hasAccordionOpened,
|
||||
handleAccordionChange,
|
||||
accordionIndex,
|
||||
handleSizeChange }) => {
|
||||
const t = useTranslations();
|
||||
const [downloadStatus, setDownloadStatus] = useState('initial');
|
||||
const handleDownloadClick = (setStatus) => {
|
||||
|
||||
console.log(setStatus)
|
||||
setStatus('downloading');
|
||||
setTimeout(() => {
|
||||
setStatus('completed');
|
||||
setTimeout(() => {
|
||||
setStatus('initial');
|
||||
}, 2500);
|
||||
}, 2000);
|
||||
// Perform the actual download logic here
|
||||
};
|
||||
return(
|
||||
<Accordion elevation={0} expanded={hasOpened || false} onChange={() => handleAccordionChange(accordionIndex)} sx={{
|
||||
mb: 2,
|
||||
boxShadow: 1,
|
||||
backgroundColor: "#f7f7f7"
|
||||
}}>
|
||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||
<Box sx={{ width: "100%", display: "flex", alignItems: "center", justifyContent: "space-between" }}>
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
|
||||
<Typography sx={{ fontWeight: 500, color: "primary.main" }}>{title}</Typography>
|
||||
{hasAccordionOpened && <VerifiedIcon style={{ color: "green" }} />}
|
||||
</Box>
|
||||
</Box>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails sx={{ display: "flex", justifyContent: "center", alignItems: "center" }}>
|
||||
<Grid container direction="column" alignItems="center">
|
||||
<Grid item>
|
||||
<ButtonGroup variant="contained" aria-label="outlined primary button group">
|
||||
<Button onClick={() => handleDownloadClick(setDownloadStatus)}>
|
||||
{downloadStatus === 'completed' ? (
|
||||
<Check sx={{ color: 'white' }} fontSize="small" />
|
||||
) : downloadStatus === 'downloading' ? (
|
||||
<CircularProgress sx={{ color: 'white' }} size={18} />
|
||||
) : (
|
||||
<FileDownloadOutlinedIcon sx={{ color: 'white' }} fontSize="small" />
|
||||
)}
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
);
|
||||
}
|
||||
|
||||
export default CustomAccordion;
|
||||
38
src/core/components/DownloadSection.jsx
Normal file
38
src/core/components/DownloadSection.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined';
|
||||
import Check from '@mui/icons-material/Check';
|
||||
import {CircularProgress} from "@mui/material"
|
||||
const DownloadSection = ({ downloadStatus, onDownloadClick }) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
width: '30',
|
||||
height: '30',
|
||||
backgroundColor: downloadStatus === 'completed' ? '#0070f3' : 'white',
|
||||
border: `1px solid ${downloadStatus === 'completed' ? '#0070f3' : 'gray'}`,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
transition: 'background 0.2s, box-shadow 0.2s',
|
||||
boxShadow: downloadStatus === 'completed' ? '0 0 5px rgba(0, 112, 243, 0.5)' : 'none',
|
||||
padding:'5px'
|
||||
}}
|
||||
onClick={onDownloadClick}
|
||||
>
|
||||
{downloadStatus === 'completed' ? (
|
||||
<>
|
||||
<Check sx={{ color: 'white' }} fontSize="medium" />
|
||||
</>
|
||||
) : downloadStatus === 'downloading' ? (
|
||||
<CircularProgress size={25} />
|
||||
) : (
|
||||
<>
|
||||
<FileDownloadOutlinedIcon sx={{ color: '#0070f3' }} fontSize="medium" />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DownloadSection;
|
||||
@@ -43,6 +43,8 @@ export const EXPORT_PASSENGER_BOSS =
|
||||
export const GET_TRANSPORTATION_ASSISTANCE =
|
||||
BASE_URL + "/dashboard/transportation_assistant/show";
|
||||
|
||||
export const GET_TRANSPORTATION_ASSISTANCE_DETAILS =
|
||||
BASE_URL + "/dashboard/transportation_assistant";
|
||||
export const CONFIRM_TRANSPORTATION_ASSISTANCE =
|
||||
BASE_URL + "/dashboard/transportation_assistant/confirm";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user