-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from AndrewCS149/adminInsightsPage
Add admin insights page
- Loading branch information
Showing
10 changed files
with
225 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useEffect, useState } from "react"; | ||
import "./styles/Insights.css"; | ||
import { MdDelete as Trash } from "react-icons/md"; | ||
|
||
interface IUserInfo { | ||
userName: string, | ||
email: string | ||
} | ||
|
||
const Insights = () => { | ||
const [users, setUsers] = useState<IUserInfo[]>(); | ||
|
||
const getUsers = async () => { | ||
await fetch("api/accounts/count", { | ||
method: "GET", | ||
headers: { | ||
"Authorization": `Bearer ${localStorage.getItem("token")}` | ||
} | ||
}).then((res) => { return res.json(); }) | ||
.then((data) => { | ||
setUsers(data); | ||
}); | ||
} | ||
|
||
const handleDeleteAccount = async (userName: string) => { | ||
const shouldDelete = window.confirm(`Are you sure you would like to delete user ${userName}?`); | ||
|
||
if (shouldDelete) { | ||
await fetch(`api/accounts/admin/${userName}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${localStorage.getItem("token")}` | ||
} | ||
}).then(() => { | ||
// users.filter((user) => user.userName !== userNameToRemove); | ||
setUsers(users?.filter((user) => user.userName !== userName)); | ||
}) | ||
.catch((e) => console.log(`Error deleting account: ${e}`)); | ||
} | ||
} | ||
|
||
useEffect(() => { getUsers() }, []); | ||
|
||
return ( | ||
<section className="insights"> | ||
<p>Total Users: {users?.length}</p> | ||
|
||
<table className="user-table"> | ||
<thead> | ||
<tr> | ||
<th>Username</th> | ||
<th>Email</th> | ||
<th>Delete</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{users?.map((user, index) => ( | ||
<tr key={index}> | ||
<td>{user.userName}</td> | ||
<td>{user.email}</td> | ||
<td><Trash className="delete-post-btn" onClick={() => handleDeleteAccount(user.userName)} /></td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</section> | ||
) | ||
} | ||
|
||
export default Insights; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.insights { | ||
font-family: 'Chivo Mono', monospace; | ||
margin-top: 150px; | ||
} | ||
|
||
.insights>table { | ||
border: .15em solid rgb(70, 68, 60); | ||
border-radius: .5em; | ||
width: 100%; | ||
} | ||
|
||
|
||
.insights>table th, | ||
.insights>table td { | ||
padding: 15px; | ||
text-align: left; | ||
} | ||
|
||
.insights>table>tbody tr:nth-child(odd) { | ||
background-color: rgb(26, 32, 41); | ||
} |
Oops, something went wrong.