diff --git a/client/src/components/AccountListing.js b/client/src/components/AccountListing.js
index 440e2a0..02e34ad 100644
--- a/client/src/components/AccountListing.js
+++ b/client/src/components/AccountListing.js
@@ -1,17 +1,44 @@
import { useState } from "react";
+import { GoTriangleDown, GoTriangleUp } from "react-icons/go";
const AccountListing = ({ user }) => {
const [open, setOpen] = useState(false);
+ async function deleteUser() {
+ const res = await fetch("/api/user/deleteUser", {
+ method: "DELETE",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ username: user.username }),
+ });
+ const data = await res.json();
+ if (!res.ok) {
+ console.log("error");
+ }
+ }
+
return (
{user.lastName + ", " + user.firstName}
-
setOpen((prev) => !prev)}
- >
+
+
+
setOpen((prev) => !prev)}
+ >
+ {open ? (
+
+ ) : (
+
+ )}
+
+
{open && (
@@ -21,16 +48,18 @@ const AccountListing = ({ user }) => {
{user.grade}
)}
-
- Title:
- {user.isBoard && user.title
- ? user.title
- : user.isBoard
- ? "Board title not specified"
- : user.isAdvisor
- ? "Advisor"
- : user.department + " Member"}
-
+ {(user.isBoard || user.isAdvisor) && (
+
+ Title:
+ {user.isBoard ? user.title : "Advisor"}
+
+ )}
+ {!user.isAdvisor && (
+
+ Department:
+ {user.department}
+
+ )}
)}
diff --git a/client/src/hooks/useAuth.js b/client/src/hooks/useAuth.js
index b83ee8c..68abafc 100644
--- a/client/src/hooks/useAuth.js
+++ b/client/src/hooks/useAuth.js
@@ -9,14 +9,14 @@ export function useAuth(type) {
const navigate = useNavigate();
- async function auth(username, password) {
+ async function auth(user) {
setIsLoading(true);
setError(null);
const response = await fetch("/api/user/authenticate", {
method: "POST",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ username, password, type }),
+ body: JSON.stringify({ ...user, type }),
});
const data = await response.json();
if (!response.ok) {
diff --git a/client/src/pages/AddAccount.js b/client/src/pages/AddAccount.js
index 0233604..5f934f8 100644
--- a/client/src/pages/AddAccount.js
+++ b/client/src/pages/AddAccount.js
@@ -1,14 +1,31 @@
-import HeaderBlock from "../components/HeaderBlock";
+import Button from "../components/Button";
+import useAuth from "../hooks/useAuth";
import { useState } from "react";
const AddAccount = () => {
const [username, setUsername] = useState("");
+ const [password, setPassword] = useState("");
const [first, setFirst] = useState("");
const [last, setLast] = useState("");
const [grade, setGrade] = useState();
const [department, setDepartment] = useState("");
+ const [isBoard, setIsBoard] = useState(false);
+ const [isAdvisor, setIsAdvisor] = useState(false);
+ const [boardTitle, setBoardTitle] = useState("");
+ const { auth, error, isLoading } = useAuth("signup");
async function handleSubmit(e) {
e.preventDefault();
+ await auth({
+ username,
+ password,
+ firstName: first,
+ lastName: last,
+ grade,
+ department,
+ isBoard,
+ isAdvisor,
+ title: boardTitle,
+ });
}
return (
@@ -29,6 +46,15 @@ const AddAccount = () => {
value={username}
/>
+
+
+ setPassword(e.target.value)}
+ value={password}
+ />
+
@@ -69,6 +95,51 @@ const AddAccount = () => {
/>
+
+ {isBoard && (
+
+
+ setBoardTitle(e.target.value)}
+ value={boardTitle}
+ />
+
+ )}
+
);
diff --git a/client/src/pages/Login.js b/client/src/pages/Login.js
index d8a9822..ece5c27 100644
--- a/client/src/pages/Login.js
+++ b/client/src/pages/Login.js
@@ -9,7 +9,7 @@ const Login = () => {
async function handleSubmit(e) {
e.preventDefault();
- await auth(username, password);
+ await auth({ username, password });
}
return (
diff --git a/server/controllers/userController.js b/server/controllers/userController.js
index 672c401..c921413 100644
--- a/server/controllers/userController.js
+++ b/server/controllers/userController.js
@@ -11,16 +11,17 @@ const authenticateUser = async (req, res) => {
let u;
if (user.type == "login") {
u = await User.login(user.username, user.password);
+ const token = createToken(u._id);
+ res.status(200).json({
+ username: user.username,
+ token,
+ isBoard: u.isBoard,
+ isAdvisor: u.isAdvisor,
+ });
} else {
u = await User.signup(user);
+ res.status(200);
}
- const token = createToken(u._id);
- res.status(200).json({
- username: user.username,
- token,
- isBoard: u.isBoard,
- isAdvisor: u.isAdvisor,
- });
} catch (error) {
res.status(400).json({ error: error.message });
}