Browse Source

Using Toasts and updated page layout

master
Denis Thiessen 10 months ago
parent
commit
cdf8d497b7
  1. 11
      src/components/SingleFileUpload.jsx
  2. 17
      src/index.js

11
src/components/SingleFileUpload.jsx

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

17
src/index.js

@ -4,7 +4,7 @@ import "./index.css"
import TimelineAreaChart from "./components/TimelineAreaChart" import TimelineAreaChart from "./components/TimelineAreaChart"
import TotalPieChart from "./components/TotalPieChart" import TotalPieChart from "./components/TotalPieChart"
import SingleFileUploader, { fileContent } from "./components/SingleFileUpload" import SingleFileUploader, { fileContent } from "./components/SingleFileUpload"
import { GeistProvider, CssBaseline, Tabs } from "@geist-ui/core"
import { GeistProvider, Page, CssBaseline, Tabs } from "@geist-ui/core"
export default function App() { export default function App() {
const [fileUploaded, setFileUploaded] = useState(false) const [fileUploaded, setFileUploaded] = useState(false)
@ -18,6 +18,7 @@ export default function App() {
} }
return ( return (
<Page>
<GeistProvider> <GeistProvider>
<CssBaseline /> <CssBaseline />
<Tabs initialValue="1"> <Tabs initialValue="1">
@ -25,11 +26,14 @@ export default function App() {
<SingleFileUploader onFileUploaded={handleUploadedFile} /> <SingleFileUploader onFileUploaded={handleUploadedFile} />
<br /> <br />
<hr /> <hr />
<h3>How to upload a file</h3>
<p>
Go to Clockify Reports Summary Time Report (Detailed) Export (As
a CSV file)
</p>
<h3>How to upload a file:</h3>
<ul>
<li>Go to Clockify</li>
<li>Reports</li>
<li>Summary</li>
<li>Time Report (Detailed)</li>
<li>Export (As a CSV file)</li>
</ul>
</Tabs.Item> </Tabs.Item>
<Tabs.Item label="Project timeline" value="2" disabled={!fileUploaded}> <Tabs.Item label="Project timeline" value="2" disabled={!fileUploaded}>
<TimelineAreaChart /> <TimelineAreaChart />
@ -39,6 +43,7 @@ export default function App() {
</Tabs.Item> </Tabs.Item>
</Tabs> </Tabs>
</GeistProvider> </GeistProvider>
</Page>
) )
} }

Loading…
Cancel
Save