Skip to content

Commit cfb1945

Browse files
committed
Improved upcoming donations page
1 parent f43d94d commit cfb1945

File tree

6 files changed

+157
-21
lines changed

6 files changed

+157
-21
lines changed

backend/app/models/meal_request.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _get_expanded_contacts_list(self, contacts):
9797
continue
9898
expanded_contacts.append(contact.to_serializable_dict())
9999
return expanded_contacts
100-
100+
101101
def to_serializable_dict(self):
102102
"""
103103
Returns a dict representation of the document that is JSON serializable
@@ -111,7 +111,9 @@ def to_serializable_dict(self):
111111
meal_request_dict["onsite_contacts"] = contacts
112112

113113
if self.donation_info and self.donation_info.donor_onsite_contacts:
114-
contacts = self._get_expanded_contacts_list(self.donation_info.donor_onsite_contacts)
114+
contacts = self._get_expanded_contacts_list(
115+
self.donation_info.donor_onsite_contacts
116+
)
115117
meal_request_dict["donation_info"]["donor_onsite_contacts"] = contacts
116118

117119
return meal_request_dict

backend/app/services/implementations/meal_request_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ def cancel_donation(self, meal_request_id: str) -> MealRequestDTO:
238238
)
239239

240240
donor = User.objects(id=meal_request.donation_info.donor.id).first()
241-
donor.info.involved_meal_requests = max(donor.info.involved_meal_requests - 1, 0)
241+
donor.info.involved_meal_requests = max(
242+
donor.info.involved_meal_requests - 1, 0
243+
)
242244
donor.save()
243245

244246
meal_request.donation_info = None
@@ -260,7 +262,9 @@ def delete_meal_request(self, meal_request_id: str) -> MealRequestDTO:
260262
raise Exception(f'Meal request "{meal_request_id}" not found')
261263

262264
requestor = User.objects(id=meal_request.requestor.id).first()
263-
requestor.info.involved_meal_requests = max(requestor.info.involved_meal_requests - 1, 0)
265+
requestor.info.involved_meal_requests = max(
266+
requestor.info.involved_meal_requests - 1, 0
267+
)
264268
requestor.save()
265269

266270
meal_request.delete()

frontend/src/components/common/MealRequestCalendarView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export const MealRequestCalendarView = ({
332332
icon: "fc-icon-chevron-left",
333333
click() {
334334
const prevMonth = new Date(date);
335+
prevMonth.setDate(1);
335336
prevMonth.setMonth(prevMonth.getMonth() - 1);
336337
setDate(prevMonth);
337338
},
@@ -340,6 +341,7 @@ export const MealRequestCalendarView = ({
340341
icon: "fc-icon-chevron-right",
341342
click() {
342343
const nextMonth = new Date(date);
344+
nextMonth.setDate(1);
343345
nextMonth.setMonth(nextMonth.getMonth() + 1);
344346
setDate(nextMonth);
345347
},

frontend/src/pages/ASPCalendar.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ const ASPCalendar = ({ authId }: ASPCalendarProps) => {
277277
<Td>
278278
<Text>
279279
{
280-
selectedMealRequest.requestor.info
280+
selectedMealRequest?.requestor?.info
281281
?.organizationAddress
282282
}
283283
</Text>
@@ -376,6 +376,32 @@ const ASPCalendar = ({ authId }: ASPCalendarProps) => {
376376
</Tr>
377377
) : null}
378378
</Table>
379+
<Box position="absolute" bottom={2} right={2}>
380+
<HStack spacing={2}>
381+
<Button
382+
variant="link"
383+
height="20px"
384+
fontSize="14px"
385+
textColor="black"
386+
fontWeight="normal"
387+
_hover={{ textDecoration: "underline" }}
388+
onClick={handleEdit(selectedMealRequest)}
389+
>
390+
Edit
391+
</Button>
392+
<Button
393+
variant="link"
394+
height="20px"
395+
fontSize="14px"
396+
textColor="red"
397+
fontWeight="normal"
398+
_hover={{ textDecoration: "underline" }}
399+
onClick={handleDelete(selectedMealRequest)}
400+
>
401+
Delete
402+
</Button>
403+
</HStack>
404+
</Box>
379405
</Card>
380406
) : (
381407
<Card padding={8} width="100%" variant="outline">

frontend/src/pages/EditMealRequestForm.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ const UPDATE_MEAL_REQUEST = gql`
102102
portions
103103
dietaryRestrictions
104104
}
105+
requestor {
106+
info {
107+
organizationAddress
108+
}
109+
}
105110
onsiteContacts {
106111
id
107112
name
@@ -151,6 +156,11 @@ const UPDATE_MEAL_DONATION = gql`
151156
email
152157
phone
153158
}
159+
requestor {
160+
info {
161+
organizationAddress
162+
}
163+
}
154164
donationInfo {
155165
donor {
156166
id

frontend/src/pages/UpcomingPage.tsx

Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,21 @@ const GET_MEAL_REQUESTS_BY_ID = gql`
114114
donor {
115115
info {
116116
organizationName
117+
primaryContact {
118+
name
119+
email
120+
phone
121+
}
117122
}
118123
}
124+
donorOnsiteContacts {
125+
name
126+
email
127+
phone
128+
}
129+
commitmentDate
119130
mealDescription
131+
additionalInfo
120132
}
121133
}
122134
}
@@ -159,7 +171,7 @@ function formatDate(inputDate: string): string {
159171
return date.toLocaleDateString("en-US", options);
160172
}
161173

162-
export const UpcomingCard = ({ event }: { event: UpcomingEvent }) => {
174+
export const UpcomingCard = ({ event, setShouldReload }: { event: UpcomingEvent, setShouldReload : (_: boolean) => void}) => {
163175
const { mealRequest } = event.extendedProps;
164176
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
165177
const [
@@ -173,17 +185,14 @@ export const UpcomingCard = ({ event }: { event: UpcomingEvent }) => {
173185
};
174186

175187
return (
176-
<div
177-
style={{
178-
maxWidth: "800px",
179-
}}
180-
>
188+
<div>
181189
{currentlyEditingMealRequestId ? (
182190
<EditMealRequestForm
183191
open={isEditModalOpen}
184-
onClose={() => {
192+
onClose={(newMealRequest) => {
185193
setIsEditModalOpen(false);
186194
setCurrentlyEditingMealRequestId(undefined);
195+
setShouldReload(true);
187196
}}
188197
mealRequestId={currentlyEditingMealRequestId}
189198
isEditDonation
@@ -197,7 +206,7 @@ export const UpcomingCard = ({ event }: { event: UpcomingEvent }) => {
197206
justifyContent="space-around"
198207
alignItems="center"
199208
>
200-
<VStack padding={10}>
209+
<VStack padding={1}>
201210
<Text fontSize="md">
202211
{
203212
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -226,7 +235,21 @@ export const UpcomingCard = ({ event }: { event: UpcomingEvent }) => {
226235
Edit My Donation
227236
</ChakraButton>
228237
</VStack>
229-
<VStack alignItems="left" padding={6}>
238+
239+
<VStack alignItems="left" padding={6} alignSelf="start">
240+
<HStack alignItems="top">
241+
<IoPersonOutline />
242+
<VStack alignItems="left">
243+
<Text fontSize="xs">
244+
<strong>
245+
ASP Name:
246+
<br />
247+
</strong>
248+
{mealRequest?.requestor.info?.organizationName}
249+
</Text>
250+
</VStack>
251+
</HStack>
252+
230253
<HStack alignItems="top">
231254
<IoLocationOutline />
232255
<VStack alignItems="left">
@@ -240,19 +263,30 @@ export const UpcomingCard = ({ event }: { event: UpcomingEvent }) => {
240263
</VStack>
241264
</HStack>
242265

266+
<HStack alignItems="top" gap={0}>
267+
<IoPersonOutline />
268+
<VStack alignItems="left" gap={0} spacing={0}>
269+
<Text variant="mobile-button-bold">ASP Primary Contact</Text>
270+
<Text fontSize="xs">{mealRequest?.requestor.info?.primaryContact.name}</Text>
271+
<Text fontSize="xs">{mealRequest?.requestor.info?.primaryContact.email}</Text>
272+
<Text fontSize="xs">{mealRequest?.requestor.info?.primaryContact.name}</Text>
273+
</VStack>
274+
</HStack>
275+
243276
<HStack alignItems="top">
244277
<IoPersonOutline />
245-
<VStack alignItems="left">
278+
<VStack alignItems="left" gap={0} spacing={1}>
246279
<Text fontSize="xs">
247280
<strong>ASP Onsite Staff:</strong>
248281
</Text>
249282
{mealRequest?.onsiteContacts.map((staffMember) => (
250-
<>
251-
<Text fontSize="xs">{staffMember.name}</Text>
252-
<Text fontSize="xs">{staffMember.email}</Text>
253-
<Text fontSize="xs">{staffMember.phone}</Text>
254-
</>
283+
<VStack alignItems="left" gap={0} spacing={0} key={staffMember.name + staffMember.email}>
284+
<Text fontSize="xs">{staffMember.name}</Text>
285+
<Text fontSize="xs">{staffMember.email}</Text>
286+
<Text fontSize="xs">{staffMember.phone}</Text>
287+
</VStack>
255288
))}
289+
256290
</VStack>
257291
</HStack>
258292

@@ -277,6 +311,54 @@ export const UpcomingCard = ({ event }: { event: UpcomingEvent }) => {
277311
</VStack>
278312
</HStack>
279313
</VStack>
314+
315+
<VStack padding={6} alignItems="left" justifyContent="start" alignSelf="start">
316+
<HStack alignItems="top" gap={0}>
317+
<IoPersonOutline />
318+
<VStack alignItems="left" gap={0} spacing={0}>
319+
<Text variant="mobile-button-bold">Your Primary Contact</Text>
320+
<Text fontSize="xs">{mealRequest?.donationInfo?.donor?.info?.primaryContact?.name}</Text>
321+
<Text fontSize="xs">{mealRequest?.donationInfo?.donor?.info?.primaryContact?.email}</Text>
322+
<Text fontSize="xs">{mealRequest?.donationInfo?.donor?.info?.primaryContact?.phone}</Text>
323+
</VStack>
324+
</HStack>
325+
326+
<HStack alignItems="top">
327+
<IoPersonOutline />
328+
<VStack alignItems="left" gap={0} spacing={1}>
329+
<Text fontSize="xs">
330+
<strong>Your Onsite Staff:</strong>
331+
</Text>
332+
{mealRequest?.donationInfo?.donorOnsiteContacts?.map((staffMember) => (
333+
<VStack alignItems="left" gap={0} spacing={0} key={staffMember.name + staffMember.email}>
334+
<Text fontSize="xs">{staffMember.name}</Text>
335+
<Text fontSize="xs">{staffMember.email}</Text>
336+
<Text fontSize="xs">{staffMember.phone}</Text>
337+
</VStack>
338+
))}
339+
</VStack>
340+
</HStack>
341+
<HStack alignItems="top">
342+
<EmailIcon />
343+
<VStack alignItems="left">
344+
<Text fontSize="xs">
345+
<strong>Your meal description</strong>
346+
<br />
347+
{mealRequest?.donationInfo.mealDescription}
348+
</Text>
349+
</VStack>
350+
</HStack>
351+
<HStack alignItems="top">
352+
<EmailIcon />
353+
<VStack alignItems="left">
354+
<Text fontSize="xs">
355+
<strong>Your additional information</strong>
356+
<br />
357+
{mealRequest?.donationInfo?.additionalInfo}
358+
</Text>
359+
</VStack>
360+
</HStack>
361+
</VStack>
280362
</Flex>
281363
</Card>
282364
</div>
@@ -300,6 +382,7 @@ const UpcomingPage = (): React.ReactElement => {
300382

301383
const [offset, setOffset] = useState(0);
302384
const [currentPage, setCurrentPage] = useState<number>(1);
385+
const [shouldReload, setShouldReload] = useState(false);
303386

304387
const [
305388
upcomingMealRequests,
@@ -442,6 +525,15 @@ const UpcomingPage = (): React.ReactElement => {
442525
// eslint-disable-next-line react-hooks/exhaustive-deps
443526
}, [currentPage]);
444527

528+
useEffect(() => {
529+
if (shouldReload) {
530+
reloadCompletedMealRequests();
531+
reloadUpcomingMealRequests();
532+
setShouldReload(false)
533+
}
534+
// eslint-disable-next-line react-hooks/exhaustive-deps
535+
}, [shouldReload]);
536+
445537
if (!authenticatedUser) {
446538
return <Navigate replace to={LOGIN_PAGE} />;
447539
}
@@ -543,7 +635,7 @@ const UpcomingPage = (): React.ReactElement => {
543635
<>
544636
<Stack direction="column">
545637
{upcomingMealRequests?.map((event) => (
546-
<UpcomingCard event={event} key={event.id} />
638+
<UpcomingCard event={event} key={event.id} setShouldReload={setShouldReload}/>
547639
))}
548640
</Stack>
549641
<HStack>

0 commit comments

Comments
 (0)