Implement toast for upload event (#214)

* WIP success fail messages for upload document

* added success/error msgs for uploading feedback and disabled fileUploadProgress in backend

* implemented toast instead of success/error msg on modal for upload

* left over merge

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
This commit is contained in:
Sean Hatfield 2023-08-22 21:14:24 -07:00 committed by GitHub
parent c0adcc129d
commit bdf9529e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 31 deletions

View File

@ -24,6 +24,7 @@
"react-loading-icons": "^1.1.0", "react-loading-icons": "^1.1.0",
"react-loading-skeleton": "^3.1.0", "react-loading-skeleton": "^3.1.0",
"react-router-dom": "^6.3.0", "react-router-dom": "^6.3.0",
"react-toastify": "^9.1.3",
"text-case": "^1.0.9", "text-case": "^1.0.9",
"truncate": "^3.0.0", "truncate": "^3.0.0",
"uuid": "^9.0.0" "uuid": "^9.0.0"
@ -43,4 +44,4 @@
"tailwindcss": "^3.3.1", "tailwindcss": "^3.3.1",
"vite": "^4.3.0" "vite": "^4.3.0"
} }
} }

View File

@ -2,6 +2,8 @@ import React, { lazy, Suspense } from "react";
import { Routes, Route } from "react-router-dom"; import { Routes, Route } from "react-router-dom";
import { ContextWrapper } from "./AuthContext"; import { ContextWrapper } from "./AuthContext";
import PrivateRoute, { AdminRoute } from "./components/PrivateRoute"; import PrivateRoute, { AdminRoute } from "./components/PrivateRoute";
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
const Main = lazy(() => import("./pages/Main")); const Main = lazy(() => import("./pages/Main"));
const InvitePage = lazy(() => import("./pages/Invite")); const InvitePage = lazy(() => import("./pages/Invite"));
@ -51,6 +53,7 @@ export default function App() {
element={<AdminRoute Component={AdminAppearance} />} element={<AdminRoute Component={AdminAppearance} />}
/> />
</Routes> </Routes>
<ToastContainer />
</ContextWrapper> </ContextWrapper>
</Suspense> </Suspense>
); );

View File

@ -6,21 +6,18 @@ import { useDropzone } from "react-dropzone";
import { v4 } from "uuid"; import { v4 } from "uuid";
import System from "../../../../models/system"; import System from "../../../../models/system";
import { Frown } from "react-feather"; import { Frown } from "react-feather";
import showToast from "../../../../utils/toast";
export default function UploadToWorkspace({ workspace, fileTypes }) { export default function UploadToWorkspace({ workspace, fileTypes }) {
const [ready, setReady] = useState(null); const [ready, setReady] = useState(null);
const [files, setFiles] = useState([]); const [files, setFiles] = useState([]);
const [successMsg, setSuccessMsg] = useState("");
const [errorMsg, setErrorMsg] = useState("");
const handleUploadSuccess = () => { const handleUploadSuccess = () => {
setSuccessMsg("File uploaded successfully"); showToast("File uploaded successfully", "success");
setErrorMsg(null);
}; };
const handleUploadError = (message) => { const handleUploadError = (message) => {
setErrorMsg(`Upload failed: ${message}`); showToast(`Error uploading file: ${message}`, "error");
setSuccessMsg(null);
}; };
const onDrop = useCallback(async (acceptedFiles, rejections) => { const onDrop = useCallback(async (acceptedFiles, rejections) => {
@ -50,20 +47,6 @@ export default function UploadToWorkspace({ workspace, fileTypes }) {
checkProcessorOnline(); checkProcessorOnline();
}, []); }, []);
useEffect(() => {
if (!!successMsg) {
setTimeout(() => {
setSuccessMsg("");
}, 3_500);
}
if (!!errorMsg) {
setTimeout(() => {
setErrorMsg("");
}, 3_500);
}
}, [successMsg, errorMsg]);
const { getRootProps, getInputProps } = useDropzone({ const { getRootProps, getInputProps } = useDropzone({
onDrop, onDrop,
accept: { accept: {
@ -173,16 +156,6 @@ export default function UploadToWorkspace({ workspace, fileTypes }) {
{Object.values(fileTypes).flat().join(" ")} {Object.values(fileTypes).flat().join(" ")}
</code> </code>
</p> </p>
{successMsg && (
<p className="text-green-600 dark:text-green-400 text-sm text-center pt-2">
{successMsg}
</p>
)}
{errorMsg && (
<p className="text-red-600 dark:text-red-400 text-sm text-center pt-2">
{errorMsg}
</p>
)}
</ModalWrapper> </ModalWrapper>
); );
} }

View File

@ -0,0 +1,34 @@
import { toast } from "react-toastify";
import usePrefersDarkMode from "../hooks/usePrefersDarkMode";
const showToast = (message, type = "default") => {
const prefersDarkMode = usePrefersDarkMode();
const options = {
position: "bottom-center",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
theme: prefersDarkMode ? "dark" : "light",
};
switch (type) {
case "success":
toast.success(message, options);
break;
case "error":
toast.error(message, options);
break;
case "info":
toast.info(message, options);
break;
case "warning":
toast.warn(message, options);
break;
default:
toast(message, options);
}
};
export default showToast;

View File

@ -729,6 +729,11 @@ clone@^1.0.2:
resolved "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz" resolved "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz"
integrity sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg== integrity sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==
clsx@^1.1.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==
color-convert@^1.3.0, color-convert@^1.9.0: color-convert@^1.3.0, color-convert@^1.9.0:
version "1.9.3" version "1.9.3"
resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz" resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz"
@ -2043,6 +2048,13 @@ react-router@6.12.1:
dependencies: dependencies:
"@remix-run/router" "1.6.3" "@remix-run/router" "1.6.3"
react-toastify@^9.1.3:
version "9.1.3"
resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-9.1.3.tgz#1e798d260d606f50e0fab5ee31daaae1d628c5ff"
integrity sha512-fPfb8ghtn/XMxw3LkxQBk3IyagNpF/LIKjOBflbexr2AWxAH1MJgvnESwEwBn9liLFXgTKWgBSdZpw9m4OTHTg==
dependencies:
clsx "^1.1.1"
react@^18.2.0: react@^18.2.0:
version "18.2.0" version "18.2.0"
resolved "https://registry.npmjs.org/react/-/react-18.2.0.tgz" resolved "https://registry.npmjs.org/react/-/react-18.2.0.tgz"