Skip to content

Commit

Permalink
feat: 10MB 이내의 파일만 등록 가능하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
llddang committed Nov 24, 2024
1 parent 680176d commit bb72364
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/containers/study/CreateDocumentModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const DocumentBoxIcon = {
URL: <BsLink45Deg />,
};

const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB

const CreateDocumentModal = ({ isOpen, onClose, categoryData, category }: DocumentModalProps) => {
const [doctype, setDocType] = useState<DocumentType>('IMAGE');
const [docList, setDocList] = useState<DocumentList>({
Expand Down Expand Up @@ -120,11 +122,19 @@ const CreateDocumentModal = ({ isOpen, onClose, categoryData, category }: Docume
...prev,
IMAGE: [
...prev.IMAGE,
...imgs.map((img) => ({
key: img.name,
name: img.name,
content: img,
})),
...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),
],
}));
},
Expand All @@ -134,11 +144,19 @@ const CreateDocumentModal = ({ isOpen, onClose, categoryData, category }: Docume
...prev,
DOCUMENT: [
...prev.DOCUMENT,
...files.map((file) => ({
key: file.name.toString(),
name: file.name,
content: file,
})),
...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),
],
}));
},
Expand Down

0 comments on commit bb72364

Please sign in to comment.