LFFE-31 Merge branch 'feature/LFFE-31_review_clean_code_transportation' into 'develop'
This commit is contained in:
@@ -28,58 +28,44 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog ,handleSizeChangeCl
|
||||
const [accordionStates, setAccordionStates] = useState([]);
|
||||
const [hasAccordionOpened, setHasAccordionOpened] = useState([]);
|
||||
const {update_notification} = useNotification();
|
||||
const [hasImageShown, sethasImageShown] = useState(false);
|
||||
const [imageLink, setimageLink] = useState(null);
|
||||
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);
|
||||
const booleanData = Array.from({ length: response.data.data.attachment_files.length }, () => false);
|
||||
setAccordionStates(booleanData);
|
||||
setHasAccordionOpened(booleanData);
|
||||
setDetailsData(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
.catch(() => {
|
||||
}).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)
|
||||
if (!newAccordionStates[index])
|
||||
{
|
||||
handleSizeChangeClick(index , false);
|
||||
sethasImageShown(false);
|
||||
handleSizeChangeClick('sm');
|
||||
setHasImageShown(false);
|
||||
setIsSkeleton(false)
|
||||
}
|
||||
else {
|
||||
handleSizeChangeClick(index , true);
|
||||
sethasImageShown(true);
|
||||
setimageLink(detailsList.data.attachment_files[index])
|
||||
handleSizeChangeClick('xl');
|
||||
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)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -92,7 +78,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog ,handleSizeChangeCl
|
||||
})
|
||||
.test('fileType', `${t("TransportationAssistance.upload_file_format")}`, (value) => {
|
||||
if (!value) return true
|
||||
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);
|
||||
})
|
||||
})
|
||||
@@ -149,7 +135,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog ,handleSizeChangeCl
|
||||
hasAccordionOpened={hasAccordionOpened[index]}
|
||||
handleAccordionChange={() => handleAccordionChange(index)}
|
||||
accordionIndex={index}
|
||||
handleSizeChange={() => handleSizeChange(index)}
|
||||
downloadFile={file.attachment}
|
||||
/>
|
||||
));
|
||||
}
|
||||
@@ -237,7 +223,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog ,handleSizeChangeCl
|
||||
</Button>
|
||||
<Button onClick={formik.handleSubmit} variant="contained" color="primary"
|
||||
disabled={formik.isSubmitting || !formik.isValid ||
|
||||
isButtonDisabled }
|
||||
hasAccordionOpened.some((opened) => !opened) }
|
||||
>
|
||||
{t("ConfirmDialog.button-confirm")}
|
||||
</Button>
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
import {Box, Skeleton, Stack} from "@mui/material";
|
||||
import {useEffect} from "react";
|
||||
const ImageContent = (link) => {
|
||||
const ImageContent = (prop) => {
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
link.setIsSkeleton(false);
|
||||
}, 1000);
|
||||
prop.setIsSkeleton(false);
|
||||
}, 1500);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [link.isSkeleton]);
|
||||
}, [prop.isSkeleton]);
|
||||
|
||||
const isPDF = link && link.imageLink && link.imageLink.attachment && link.imageLink.attachment.endsWith('.pdf');
|
||||
const isPDF = prop.imageLink && prop.imageLink.attachment && prop.imageLink.attachment.endsWith('.pdf');
|
||||
return (
|
||||
<>
|
||||
<Stack sx={{width :"100%"}}>
|
||||
{link.isSkeleton && (
|
||||
{prop.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' }}/>
|
||||
<embed src={prop.imageLink.attachment} type="application/pdf" width="100%" height="700px" style={{ display: prop.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>
|
||||
prop.imageLink && prop.imageLink.attachment && (
|
||||
<Box sx={{display: prop.isSkeleton ? 'none' : 'flex' ,justifyContent:'center' , border: '1px solid #ccc' , p:5 , height: '700px' , borderRadius: '8px',}}>
|
||||
<Box component="img" src={prop.imageLink.attachment} alt="Image Preview" width="auto" height="auto" sx={{maxHeight: '700px' , maxWidth:'100%'}}></Box>
|
||||
</Box>
|
||||
)
|
||||
)}
|
||||
|
||||
@@ -14,14 +14,8 @@ const Confirm = ({rowId, mutate}) => {
|
||||
}
|
||||
}, [openConfirmDialog]);
|
||||
|
||||
const handleSizeChangeClick = (num , state) => {
|
||||
if (state===true){
|
||||
setDialogSize('xl');
|
||||
|
||||
}
|
||||
else {
|
||||
setDialogSize('sm');
|
||||
}
|
||||
const handleSizeChangeClick = (size) => {
|
||||
setDialogSize(size);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -10,29 +10,18 @@ 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 CustomAccordion = ({ title, hasOpened, hasAccordionOpened, handleAccordionChange, accordionIndex , downloadFile}) => {
|
||||
const [downloadStatus, setDownloadStatus] = useState('initial');
|
||||
const handleDownloadClick = (setStatus) => {
|
||||
|
||||
console.log(setStatus)
|
||||
const handleDownloadClick = (setStatus , url) => {
|
||||
setStatus('downloading');
|
||||
window.open(url, '_blank');
|
||||
setTimeout(() => {
|
||||
setStatus('completed');
|
||||
setTimeout(() => {
|
||||
setStatus('initial');
|
||||
}, 2500);
|
||||
}, 2000);
|
||||
// Perform the actual download logic here
|
||||
}, 1200);
|
||||
}, 1000);
|
||||
};
|
||||
return(
|
||||
<Accordion elevation={0} expanded={hasOpened || false} onChange={() => handleAccordionChange(accordionIndex)} sx={{
|
||||
@@ -52,7 +41,7 @@ const CustomAccordion = ({ title,
|
||||
<Grid container direction="column" alignItems="center">
|
||||
<Grid item>
|
||||
<ButtonGroup variant="contained" aria-label="outlined primary button group">
|
||||
<Button onClick={() => handleDownloadClick(setDownloadStatus)}>
|
||||
<Button onClick={() => handleDownloadClick(setDownloadStatus , downloadFile)}>
|
||||
{downloadStatus === 'completed' ? (
|
||||
<Check sx={{ color: 'white' }} fontSize="small" />
|
||||
) : downloadStatus === 'downloading' ? (
|
||||
|
||||
Reference in New Issue
Block a user