From d991a20b04c9ddb549011a60a1d6bb210953fa23 Mon Sep 17 00:00:00 2001 From: Alex Zhang Date: Tue, 11 Oct 2022 22:23:38 -0700 Subject: [PATCH 1/2] Add CSV Flow for create new group and use previous group --- app.js | 1 - client/src/components/CSVParser.js | 97 ++++++++++++++++++------------ client/src/css/CSVParser.css | 28 +++++++-- client/src/pages/Dashboard.js | 2 + 4 files changed, 84 insertions(+), 44 deletions(-) diff --git a/app.js b/app.js index b95030b..7e96e5d 100644 --- a/app.js +++ b/app.js @@ -11,7 +11,6 @@ const organizationRoutes = require("./routes/organizationRoutes"); const groupRoutes = require("./routes/groupRoutes"); const typeRoutes = require("./routes/typesRoutes"); - connectDB(); const port = process.env.PORT || 80; diff --git a/client/src/components/CSVParser.js b/client/src/components/CSVParser.js index 8f1b77c..ea3fa8f 100644 --- a/client/src/components/CSVParser.js +++ b/client/src/components/CSVParser.js @@ -11,6 +11,7 @@ import React, { useState } from "react"; import { useCSVReader, useCSVDownloader, formatFileSize } from "react-papaparse"; import { AiOutlineCloudUpload, AiOutlineDownload } from "react-icons/ai"; +import Select from "react-select"; import CloudUpload from "../images/CloudUpload.svg"; import FileIcon from "../images/File.svg"; @@ -25,6 +26,8 @@ function CSVParser({ setCSVUploaded, setSnackbar, selectedGroup, + setSelectedGroup, + groupOptions, orgId, setDataLoading, groupCreationVisible, @@ -39,10 +42,13 @@ function CSVParser({ const { CSVReader } = useCSVReader(); const { CSVDownloader, Type } = useCSVDownloader(); const [tableData, setTableData] = React.useState([]); - const group = selectedGroup; + const [group, setGroup] = useState(selectedGroup); const [noGroupCSVData, setNoGroupCSVData] = useState(null); const [formSubmittable, setFormSubmittable] = useState(false); - const [createCSVGroup, setCreateCSVGroup] = useState(false); // tracks if group creation from csv is toggled + // Tracks if group creation from CSV is toggled + const [useExistingCSVGroup, setUseExistingCSVGroup] = useState(false); + // Tracks if group select page (flow from uploading to existing group) is selected + const [groupSelectionVisible, setGroupSelectionVisible] = useState(false); React.useEffect(async () => { if (group) { @@ -162,16 +168,20 @@ function CSVParser({

Upload CSV File

-
- Upload -

Drag and drop files here to upload

-

or

-
- + {groupSelectionVisible ? ( +

Add CSV Upload to Group

+ ) : ( +
+ Upload +

Drag and drop files here to upload

+

or

+
+ +
-
+ )} {acceptedFile ? (
@@ -195,41 +205,49 @@ function CSVParser({
) : null} -
- {forceNewGroup ? ( + {forceNewGroup || groupSelectionVisible ? null : ( // We don't provide this dropdown option if we forceNewGroup +
+ setCreateCSVGroup(!createCSVGroup)} - checked - disabled + checked={useExistingCSVGroup} + onClick={() => setUseExistingCSVGroup(!useExistingCSVGroup)} /> - ) : ( - setCreateCSVGroup(!createCSVGroup)} +
+ )} + {groupSelectionVisible ? ( +
+

Select the group you want your CSV upload to go into.

+