Skip to content

Commit ad902f3

Browse files
committed
Added go back to all meal requests button
1 parent 21cb65e commit ad902f3

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

backend/app/services/implementations/user_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,18 @@ def get_auth_id_by_user_id(self, user_id):
139139
)
140140
raise e
141141

142-
def get_users(self, offset, limit, role, name: Union[str, None], email : Union[str, None]):
142+
def get_users(
143+
self, offset, limit, role, name: Union[str, None], email: Union[str, None]
144+
):
143145
user_dtos = []
144146
filteredUsers = User.objects()
145147
if role:
146148
filteredUsers = filteredUsers.filter(info__role=role)
147149

148150
if name:
149-
filteredUsers = filteredUsers.filter(info__organization_name__icontains=name)
151+
filteredUsers = filteredUsers.filter(
152+
info__organization_name__icontains=name
153+
)
150154

151155
if email:
152156
filteredUsers = filteredUsers.filter(info__email__icontains=email)

backend/app/services/interfaces/user_service.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ def get_auth_id_by_user_id(self, user_id):
7575
pass
7676

7777
@abstractmethod
78-
def get_users(self, offset: int, limit: int, role: UserInfoRole, name: Union[str, None], email : Union[str, None]):
78+
def get_users(
79+
self,
80+
offset: int,
81+
limit: int,
82+
role: UserInfoRole,
83+
name: Union[str, None],
84+
email: Union[str, None],
85+
):
7986
"""
8087
Get all users (possibly paginated in the future)
8188

backend/tests/graphql/test_all_user_queries.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def test_all_users_fiter_by_email(user_setup):
230230
assert user_result["id"] == str(user_3.id)
231231
assert user_result["info"] == MOCK_INFO3_CAMEL
232232

233+
233234
# Note: mongomock does not currently support $geoNear queries, so cannot test
234235
# https://github.com/mongomock/mongomock/blob/develop/Missing_Features.rst
235236
# def test_get_asp_near_location(user_setup):

frontend/src/components/mealrequest/AdminListView.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ import {
2626
} from "@chakra-ui/react";
2727
import * as TABLE_LIBRARY_TYPES from "@table-library/react-table-library/types/table";
2828
import React, { useContext, useEffect, useState } from "react";
29-
import { BsFilter } from "react-icons/bs";
29+
import { BsFilter, BsReplyAll } from "react-icons/bs";
3030
import { FiFilter } from "react-icons/fi";
3131

32+
import { useNavigate } from "react-router-dom";
33+
34+
import { ADMIN_MEAL_REQUESTS_PAGE } from "../../constants/Routes";
3235
import AuthContext from "../../contexts/AuthContext";
3336
import {
3437
MealRequest,
@@ -478,6 +481,7 @@ const AdminListView = ({
478481
const [mealRequestId, setMealRequestId] = useState<string>("");
479482
const [isUpcoming, setIsUpcoming] = useState<boolean>(false);
480483
const [shouldReload, setShouldReload] = useState(false);
484+
const navigate = useNavigate();
481485

482486
const handleExpand = (item: TABLE_LIBRARY_TYPES.TableNode) => () => {
483487
if (item.pending) return;
@@ -631,7 +635,6 @@ const AdminListView = ({
631635

632636
useEffect(() => {
633637
if (shouldReload) {
634-
// console.log("Doing a reload! ", shouldReload);
635638
reloadMealRequests();
636639
setShouldReload(false);
637640
}
@@ -641,7 +644,7 @@ const AdminListView = ({
641644
useEffect(() => {
642645
reloadMealRequests();
643646
// eslint-disable-next-line react-hooks/exhaustive-deps
644-
}, [filter, sort, currentPage, authenticatedUser]);
647+
}, [filter, sort, currentPage, authenticatedUser, aspId, donorId]);
645648

646649
const COLUMNS = [
647650
{
@@ -887,6 +890,31 @@ const AdminListView = ({
887890
return (
888891
<Box mt="24px" width="80%">
889892
<Flex gap="10px" marginBottom="20px" justifyContent="flex-end">
893+
{aspId || donorId ?
894+
<Menu>
895+
<MenuButton
896+
as={ChakraButton}
897+
_hover={{ backgroundColor: "gray.200" }}
898+
padding="6px 10px"
899+
borderRadius="3px"
900+
fontSize="14px"
901+
border="solid 1px #E2E8F0"
902+
boxShadow="lg"
903+
backgroundColor="white"
904+
color="black"
905+
minWidth="75px"
906+
onClick={() => {
907+
navigate(ADMIN_MEAL_REQUESTS_PAGE, { replace: false } );
908+
}}
909+
>
910+
<Flex gap="2px">
911+
<BsReplyAll />
912+
<Text>
913+
View All Meal Requests
914+
</Text>
915+
</Flex>
916+
</MenuButton>
917+
</Menu> : null}
890918
<Menu>
891919
<MenuButton
892920
as={ChakraButton}

frontend/src/pages/AdminMealRequestsPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const GET_USER = gql`
2424
const AdminMealRequestsPage = (): React.ReactElement => {
2525
const { donorId, aspId } = useParams<{donorId: string, aspId: string}>();
2626

27-
const [title, setTitle] = useState<string>("All Meal Requests");
28-
const [description, setDescription] = useState<string>("Here is a table of all the meal requests");
27+
const [title, setTitle] = useState<string>("");
28+
const [description, setDescription] = useState<string>("");
2929

3030
const { data: donorData } = useQuery<GetUserData, GetUserVariables>(GET_USER, {
3131
variables: { id: donorId || "" },
@@ -46,6 +46,9 @@ const AdminMealRequestsPage = (): React.ReactElement => {
4646
const name = aspData.getUserById?.info?.organizationName;
4747
setTitle(`Meal Requests for ${name}`);
4848
setDescription(`Here is a table of all the meal requests for ${name}`);
49+
} else {
50+
setTitle("All Meal Requests");
51+
setDescription("Here is a table of all the meal requests");
4952
}
5053
}, [donorId, aspId, donorData, aspData]);
5154

0 commit comments

Comments
 (0)