Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV goes to mongoDB #117

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions frontend/src/components/newUID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

Check warning on line 1 in frontend/src/components/newUID.js

View workflow job for this annotation

GitHub Actions / Run linters frontend

'React' is defined but never used

export default function generateUID() {
const charset =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const uidLength = 28;
let uid = "";
for (let i = 0; i < uidLength; i += 1) {
const randomIndex = Math.floor(Math.random() * charset.length);
uid += charset.charAt(randomIndex);
}
return uid;
}
2 changes: 1 addition & 1 deletion frontend/src/containers/pages/ScenarioSelectionPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from "react";
import React, { useContext, useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import SideBar from "../../components/SideBar";
import ListContainer from "../../components/ListContainer";
Expand Down
42 changes: 32 additions & 10 deletions frontend/src/containers/pages/SceneSelectionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import AuthenticationContext from "../../context/AuthenticationContext";
import HelpButton from "../../components/HelpButton";
import AccessLevel from "../../enums/route.access.level";
import generateUID from "../../components/newUID";

/**
* Page that shows the scenes belonging to a scenario.
Expand All @@ -43,8 +44,25 @@
Papa.parse(selectedFile, {
header: true,
skipEmptyLines: true,
complete(results) {
console.log(results.data);
complete: async (results) => {
const usersData = results.data;
usersData.forEach(async (userData) => {
const { name, email } = userData;
const uid = generateUID(); // Implement your UID generation logic
const pictureURL = "null"; // Set the picture URL if available
const newUser = await usePost(

Check warning on line 53 in frontend/src/containers/pages/SceneSelectionPage.js

View workflow job for this annotation

GitHub Actions / Run linters frontend

'newUser' is assigned a value but never used
`/api/user/`,
{
name,
uid,
email,
pictureURL,
},
getUserIdToken
);
console.log(`User ${name} uploaded to MongoDB.`);
});
console.log("CSV data uploaded to MongoDB.");
},
});
};
Expand Down Expand Up @@ -202,14 +220,18 @@
>
Share
</Button>
<Button
className="btn top contained white"
color="default"
variant="outlined"
onClick={() => handCSVClick(true)}
>
Upload CSV
</Button>
{VpsUser.role === AccessLevel.USER ? (
<Button
className="btn top contained white"
color="default"
variant="outlined"
onClick={() => handCSVClick(true)}
>
Upload CSV
</Button>
) : (
""
)}
<input
type="file"
ref={fileInputRef}
Expand Down
Loading