Skip to content

Commit

Permalink
fix: 학습자료 첨부에서 첨부파일에 null이 들어가는 빌드 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
llddang committed Nov 24, 2024
1 parent bb72364 commit 2c5bfee
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/containers/study/CreateDocumentModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,47 +117,47 @@ const CreateDocumentModal = ({ isOpen, onClose, categoryData, category }: Docume

const handleGetDoc = {
IMAGE: (e: ChangeEvent<HTMLInputElement>) => {
const imgs = Array.from(e.target.files || []);
const images = Array.from(e.target.files || []);
let alertFlag = false;
const filteredImages = images.reduce(
(r, img) => {
if (img.size >= MAX_FILE_SIZE) alertFlag = true;
else
r.push({
key: img.name,
name: img.name,
content: img,
});
return r;
},
[] as { key: string; name: string; content: File }[],
);
if (alertFlag) alert('10MB 이내의 파일을 첨부해주세요.');
setDocList((prev) => ({
...prev,
IMAGE: [
...prev.IMAGE,
...imgs
.map((img) => {
if (img.size >= MAX_FILE_SIZE) {
alert('10MB 이내의 파일을 첨부해주세요.');
return null;
}
return {
key: img.name,
name: img.name,
content: img,
};
})
.filter((v) => v !== null),
],
IMAGE: [...prev.IMAGE, ...filteredImages],
}));
},
DOCUMENT: (e: ChangeEvent<HTMLInputElement>) => {
const files = Array.from(e.target.files || []);
let alertFlag = false;
const filteredFiles = files.reduce(
(r, file) => {
if (file.size >= MAX_FILE_SIZE) alertFlag = true;
else
r.push({
key: file.name,
name: file.name,
content: file,
});
return r;
},
[] as { key: string; name: string; content: File }[],
);
if (alertFlag) alert('10MB 이내의 파일을 첨부해주세요.');
setDocList((prev) => ({
...prev,
DOCUMENT: [
...prev.DOCUMENT,
...files
.map((file) => {
if (file.size >= MAX_FILE_SIZE) {
alert('10MB 이내의 파일을 첨부해주세요.');
return null;
}
return {
key: file.name.toString(),
name: file.name,
content: file,
};
})
.filter((v) => v !== null),
],
DOCUMENT: [...prev.DOCUMENT, ...filteredFiles],
}));
},
URL: () => {
Expand Down

0 comments on commit 2c5bfee

Please sign in to comment.