|
|
@ -1,4 +1,5 @@ |
|
|
|
import React, { useState, useEffect } from "react" |
|
|
|
import { useToasts } from '@geist-ui/core'; |
|
|
|
import PropTypes from "prop-types" |
|
|
|
|
|
|
|
export var fileContent = "{}" |
|
|
@ -8,9 +9,15 @@ function SingleFileUpload({ onFileUploaded }) { |
|
|
|
const [, setFile] = useState() |
|
|
|
const [fileUploaded, setFileUploaded] = useState(false) |
|
|
|
|
|
|
|
const { setToast } = useToasts() |
|
|
|
const showSuccessToast = () => setToast({ text: "File successfully uploaded", delay: 2000 }); |
|
|
|
const showInvalidCSVToast = () => setToast({ text: "Invalid CSV File", delay: 2000 }); |
|
|
|
const showInvalidFileToast = () => setToast({ text: "Wrong file type", delay: 2000 }); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (fileUploaded) { |
|
|
|
onFileUploaded() |
|
|
|
showSuccessToast(); |
|
|
|
} |
|
|
|
if (uploadFailed && !fileUploaded) { |
|
|
|
onFileUploaded() |
|
|
@ -20,7 +27,7 @@ function SingleFileUpload({ onFileUploaded }) { |
|
|
|
// Reads file. |
|
|
|
var readCallback = function (csvRawData) { |
|
|
|
if (!checkCSVValidity(csvRawData)) { |
|
|
|
alert("Invalid CSV File") |
|
|
|
showInvalidCSVToast(); |
|
|
|
uploadFailed = true |
|
|
|
setFileUploaded(false) |
|
|
|
fileContent = {} |
|
|
@ -49,7 +56,7 @@ function SingleFileUpload({ onFileUploaded }) { |
|
|
|
reader.onload = function (evt) { |
|
|
|
var uploadedFile = document.getElementById("fileInput").files[0] |
|
|
|
if (uploadedFile.type != "application/vnd.ms-excel") { |
|
|
|
alert("Wrong file type") |
|
|
|
showInvalidFileToast(); |
|
|
|
fileContent = "{}" |
|
|
|
return |
|
|
|
} |
|
|
|