diff --git a/pages/contributors.js b/pages/contributors.js index 6443398..03dcc9e 100755 --- a/pages/contributors.js +++ b/pages/contributors.js @@ -3,15 +3,19 @@ import { Button, Table, Modal, Input } from "antd"; import { useState } from "react"; import { EditOutlined, DeleteOutlined } from "@ant-design/icons"; - import Papa from "papaparse"; import React from "react"; const CSV = () => { + + const [isModalVisible, setIsModalVisible] = useState(false); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [submitted, setSubmitted] = useState(""); + const [newStudent, setNewStudent] = useState(null); // State to store parsed data const [parsedData, setParsedData] = useState([]); - const [dataBool, setDataBool] = useState(false); //State to store table Column name const [tableRows, setTableRows] = useState([]); @@ -19,60 +23,6 @@ const CSV = () => { //State to store the values const [values, setValues] = useState([]); - const csvData = []; - - - const addtoList = () => { - - console.log('values = '+ values); - - let objects = []; - - const firstValue = dataSource[dataSource.length - 1].id; - for (let i = 0; i < values.length; i ++) { - objects.push({ - id: firstValue + 1 + i, - name: values[i][1], - email: values[i][2], - address: values[i][3] - }); - - } - console.log('objects = '+ JSON.stringify(objects)) - - setDataSource([...dataSource, ...objects]); - - } - - const changeHandler = (event) => { - // Passing file data (event.target.files[0]) to parse using Papa.parse - Papa.parse(event.target.files[0], { - header: true, - skipEmptyLines: true, - complete: function (results) { - const rowsArray = []; - const valuesArray = []; - - // Iterating data to get column name and their values - results.data.map((d) => { - rowsArray.push(Object.keys(d)); - valuesArray.push(Object.values(d)); - }); - - // Parsed Data Response in array format - setParsedData(results.data); - - // Filtered Column Names - setTableRows(rowsArray[0]); - - // Filtered Values - setValues(valuesArray); - console.log('values = '+ values) - }, - }); - }; - - const [isEditing, setIsEditing] = useState(false); const [editingStudent, setEditingStudent] = useState(null); const [dataSource, setDataSource] = useState([ @@ -146,14 +96,66 @@ const CSV = () => { ]; + const addtoList = () => { + + console.log('values = '+ values); + + let objects = []; + + const firstValue = dataSource[dataSource.length - 1].id; + for (let i = 0; i < values.length; i ++) { + objects.push({ + id: firstValue + 1 + i, + name: values[i][1], + email: values[i][2], + address: values[i][3] + }); + + } + console.log('objects = '+ JSON.stringify(objects)) + + setDataSource([...dataSource, ...objects]); + + } + + const changeHandler = (event) => { + // Passing file data (event.target.files[0]) to parse using Papa.parse + Papa.parse(event.target.files[0], { + header: true, + skipEmptyLines: true, + complete: function (results) { + const rowsArray = []; + const valuesArray = []; + + // Iterating data to get column name and their values + results.data.map((d) => { + rowsArray.push(Object.keys(d)); + valuesArray.push(Object.values(d)); + }); + + // Parsed Data Response in array format + setParsedData(results.data); + // Filtered Column Names + setTableRows(rowsArray[0]); + + // Filtered Values + setValues(valuesArray); + console.log('values = '+ values) + }, + }); + }; + + + const onAddStudent = () => { - const randomNumber = parseInt(Math.random() * 1000); + setIsModalVisible(true); + const newStudent = { id: dataSource[dataSource.length - 1].id + 1, - name: "Name " + randomNumber, - email: randomNumber + "@gmail.com", - address: "Address " + randomNumber, + name: "Name", + email: "test@gmail.com", + submitted: "Yes", }; setDataSource((pre) => { return [...pre, newStudent]; @@ -180,12 +182,24 @@ const CSV = () => { setEditingStudent(null); }; + const handleOk = () => { + setIsModalVisible(false); + + + } + + const handleCancel = () => { + setIsModalVisible(false); + }; + + + return ( <>
- +
{ }} /> + + + setName(e.target.value)}/> + setEmail(e.target.value)}/> + setSubmitted(e.target.value)} /> +
diff --git a/pages/login.js b/pages/login.js new file mode 100644 index 0000000..9a735d3 --- /dev/null +++ b/pages/login.js @@ -0,0 +1,65 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import { Link } from 'react-router-dom'; + +function LoginSignupForm() { + const [formData, setFormData] = useState({ + username: '', + password: '', + }); + + const { username, password } = formData; + + const onChange = e => + setFormData({ ...formData, [e.target.name]: e.target.value }); + + const onSubmit = async e => { + e.preventDefault(); + + const config = { + headers: { + 'Content-Type': 'application/json', + }, + }; + + const body = JSON.stringify({ username, password }); + + try { + // Use axios to send a POST request to the /login or /signup route + // depending on whether the user is trying to login or sign up + const res = await axios.post( + '/login', + body, + config + ); + + console.log(res.data); + } catch (err) { + console.error(err.response.data); + } + }; + + return ( +
onSubmit(e)}> +

Login

+ onChange(e)} + /> + onChange(e)} + /> + + Sign Up +
+ ); +} + +export default LoginSignupForm; diff --git a/pages/signup.js b/pages/signup.js new file mode 100644 index 0000000..72336a1 --- /dev/null +++ b/pages/signup.js @@ -0,0 +1,64 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import { Link } from 'react-router-dom'; + +function SignUpPage() { + const [formData, setFormData] = useState({ + username: '', + password: '', + }); + + const { username, password } = formData; + + const onChange = e => + setFormData({ ...formData, [e.target.name]: e.target.value }); + + const onSubmit = async e => { + e.preventDefault(); + + const config = { + headers: { + 'Content-Type': 'application/json', + }, + }; + + const body = JSON.stringify({ username, password }); + + try { + // Use axios to send a POST request to the /signup route + const res = await axios.post( + '/register', + body, + config + ); + + console.log(res.data); + } catch (err) { + console.error(err.response.data); + } + }; + + return ( +
onSubmit(e)}> +

Sign Up

+ onChange(e)} + /> + onChange(e)} + /> + + Log In +
+ ); +} + +export default SignUpPage;