Explorar o código

check the file type and reject non-JSON file

CodeMaker-Zhao %!s(int64=2) %!d(string=hai) anos
pai
achega
9b70222ff9
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      src/containers/Modals/ImportModal/index.tsx

+ 5 - 1
src/containers/Modals/ImportModal/index.tsx

@@ -54,7 +54,11 @@ export const ImportModal: React.FC<ModalProps> = ({ visible, setVisible }) => {
     e.preventDefault();
 
     if (e.type === 'drop' && e.dataTransfer.files.length) {
-      setJsonFile(e.dataTransfer.files[0])
+      if (e.dataTransfer.files[0].type === 'application/json') {
+        setJsonFile(e.dataTransfer.files[0])
+      } else {
+        toast.error('Please upload JSON file!')
+      }
     }
   }