Просмотр исходного кода

check the file type and reject non-JSON file

CodeMaker-Zhao 2 лет назад
Родитель
Сommit
9b70222ff9
1 измененных файлов с 5 добавлено и 1 удалено
  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!')
+      }
     }
   }