I need to upload particular file upload but it upload all array of object #1328
vel-kathir
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
import React, { useCallback, useState, useEffect } from "react";
import { Grid, IconButton } from "@mui/material";
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
import Typography from "@mui/material/Typography";
import DeleteIcon from "@mui/icons-material/Delete";
import ArrowDownwardIcon from "@mui/icons-material/ArrowDownward";
import Pdf from "../../assets/images/pdf.svg";
import { useDropzone } from "react-dropzone";
import data from "../Jsons/Upload2.json";
const FileUploadUI = (props) => {
const { id } = props;
console.log(props);
const [uploadedFiles, setUploadedFiles] = useState([]);
const onDrop = useCallback(
(acceptedFiles) => handleDrop(acceptedFiles, id),
[id]
);
const handleDrop = useCallback((acceptedFiles, id) => {
const pdfFiles = acceptedFiles.filter(
(file) =>
file.type === "application/pdf" ||
file.type ===
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
);
console.log(id, "iopp");
if (pdfFiles?.length > 0) {
const updatedAccounts = data.map((account) => {
if (account.id === "1") {
const existingHdfcFiles = account.hdfc || [];
const newHdfcFiles = pdfFiles.map((pdfFile, index) => ({
path:
${pdfFile.name} (${index + 1}).pdf
,}));
return { ...account, hdfc: [...existingHdfcFiles, ...newHdfcFiles] };
}
return account;
});
setUploadedFiles(updatedAccounts);
} else {
console.log("Please upload a PDF file.");
}
}, []);
const { getRootProps, getInputProps } = useDropzone({
onDrop,
accept: ".pdf, .docx",
maxSize: 2 * 1024 * 1024,
});
console.log(uploadedFiles, "ppp");
return (
<Grid sx={{ p: "20px" }}>
{data.map((item) => (
<Grid
container
alignItems="center"
display={"flex"}
spacing={2}
marginTop={"19px"}
maxWidth={"max-content"}
>
<Grid
style={{
display: "flex",
gap: "10px",
}}
>
<Typography style={{ fontSize: "14px", marginTop: "15px" }}>
{item.num}
<Grid item height={"auto"}>
<Typography
sx={{
border: "solid 1px #DBDBDC",
p: 2,
minWidth: "300px",
borderRadius: 1,
background: "#f2f2f2",
fontSize: "14px",
}}
>
{item.content}
<Grid item height={"auto"}>
<Grid display={"flex"}>
<div {...getRootProps(id)} style={dropzoneStyles}>
<input {...getInputProps()} />
<Typography sx={{ fontSize: 13, color: "#A6A5A5" }}>
Upload
);
};
const dropzoneStyles = {
border: "1.5px dashed",
borderRadius: "6px",
padding: "1px",
textAlign: "center",
cursor: "pointer",
backgroundColor: "#f2f2f2",
width: "80px",
height: "50px",
color: "grey",
};
const iconStyles = {
fontSize: "1.5rem",
color: "#A6A5A5",
};
export default FileUploadUI;
data=[
{
"id":"1",
"num":"1)",
"content":"HDFC Current Account"
},
{
"id":"2",
"num":"2)",
"content":"Citi Bank Savings Account"
},
{
"id":"3",
"num":"3)",
"content":"Motilal Oswal Equity Account"
},
{
"id":"4",
"num":"4)",
"content":"Zerodha Equity Account"
},
{
"id":"5",
"num":"5)",
"content":"Axis Savings Account"
}
]
If I click a dropdown input the file is upload and need to set in the data
for example
data=[
{
"id":"1",
"num":"1)",
"content":"HDFC Current Account",
"bank":[{"0":file-1 format},{"1":file-2 format}]
},
{
"id":"2",
"num":"2)",
"content":"Citi Bank Savings Account"
},
{
"id":"3",
"num":"3)",
"content":"Motilal Oswal Equity Account"
},
{
"id":"4",
"num":"4)",
"content":"Zerodha Equity Account"
},
{
"id":"5",
"num":"5)",
"content":"Axis Savings Account",
"bank":[{"0":file-1 format},{"1":file-2 format}]
}
]
Beta Was this translation helpful? Give feedback.
All reactions