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 = () => { />
+
+
+ + { + let prev = isBoard; + setIsBoard((prev) => !prev); + if (!prev) { + setIsAdvisor(false); + } + }} + checked={isBoard} + /> +
+
+ + { + let prev = isAdvisor; + setIsAdvisor((prev) => !prev); + if (!prev) { + setIsBoard(false); + setBoardTitle(""); + } + }} + checked={isAdvisor} + /> +
+
+ {isBoard && ( +
+ + setBoardTitle(e.target.value)} + value={boardTitle} + /> +
+ )} +