Skip to content

Commit

Permalink
Merge pull request #70 from GTBitsOfGood/phoebe/change-search
Browse files Browse the repository at this point in the history
Update search bar
  • Loading branch information
dpang314 authored Oct 28, 2023
2 parents 8ae71cf + 44b8f0f commit 1d972c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/pages/api/get_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import User from "../../server/mongodb/models/User";
import requestWrapper from "../../server/utils/middleware";

async function handler(req, res) {
const { query } = req.query;
const users = await User.aggregate([
{
$lookup: {
Expand All @@ -16,6 +17,13 @@ async function handler(req, res) {
$and: [
{ "tenures.semester": { $in: [req.query.semester] } },
{ "tenures.year": { $in: [Number(req.query.year)] } },
{
$or: [
{ email: { $regex: new RegExp(query, "i") } },
{ firstName: { $regex: new RegExp(query, "i") } },
{ phoneNumber: { $regex: new RegExp(query, "i") } },
],
},

req.query.role == "All" ? {} : { "tenures.role": { $in: [req.query.role] } },
req.query.department == "All" ? {} : { "tenures.department": { $in: [req.query.department] } },
Expand Down
10 changes: 8 additions & 2 deletions src/screens/AdminDashboard/AdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function AdminDashboardPage({ url }) {
<SearchIcon />
</SearchIconWrapper>
<StyledInputBase
placeholder="Search"
placeholder="Search by name/email/phone number"
value={filter}
inputProps={{ "aria-label": "search" }}
onChange={(e) => setFilter(e.target.value)}
Expand Down Expand Up @@ -268,7 +268,13 @@ function AdminDashboardPage({ url }) {
</Box>
<div style={{ height: "78vh", width: "90vw" }}>
<DashboardContext.Provider value={{ url, isAddUser, setIsAddUser }}>
<UserTable currentSemester={semester} newMembers={newMembers} roleFilter={role} departmentFilter={department} />
<UserTable
filter={filter}
currentSemester={semester}
newMembers={newMembers}
roleFilter={role}
departmentFilter={department}
/>
</DashboardContext.Provider>
</div>
</Grid>
Expand Down
6 changes: 3 additions & 3 deletions src/screens/AdminDashboard/UserTable/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import TableContext from "../../../contexts/TableContext";
import { User } from "../types";
import sendRequest from "../../../server/utils/sendToBackend";

function UserTable({ currentSemester, newMembers, roleFilter, departmentFilter }) {
function UserTable({ currentSemester, newMembers, roleFilter, departmentFilter, filter }) {
const [userList, setUserList] = useState<User[]>([]);

useEffect(() => {
(async () => {
const response = await sendRequest(
`/api/get_users?department=${departmentFilter}&role=${roleFilter}` +
`/api/get_users?query=${filter}&department=${departmentFilter}&role=${roleFilter}` +
`&semester=${currentSemester.split(" ")[0]}&year=${currentSemester.split(" ")[1]}`,
"GET",
);
const { users } = response;
setUserList(users);
})();
}, [roleFilter, currentSemester, newMembers, departmentFilter]);
}, [roleFilter, currentSemester, newMembers, departmentFilter, filter]);

if (!userList) {
return (
Expand Down

0 comments on commit 1d972c7

Please sign in to comment.