Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/backend/src/foodRequests/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ export class RequestsService {
validateId(requestId, 'Request');

if (
dto.requestedSize == undefined &&
dto.requestedFoodTypes == undefined &&
dto.additionalInformation == undefined
dto.requestedSize === undefined &&
dto.requestedFoodTypes === undefined &&
dto.additionalInformation === undefined
) {
throw new BadRequestException(
'At least one field must be provided to update request',
Expand Down
12 changes: 12 additions & 0 deletions apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
BulkUpdateTrackingCostDto,
UpdateDonationItemDetailsDto,
PendingApplication,
UpdateFoodRequestBody,
DonationReminderDto,
} from 'types/types';

Expand Down Expand Up @@ -104,6 +105,17 @@ export class ApiClient {
.then((response) => response.data);
}

public async updateFoodRequest(
requestId: number,
body: UpdateFoodRequestBody,
): Promise<void> {
await this.axiosInstance.patch(`/api/requests/${requestId}`, body);
}

public async deleteFoodRequest(requestId: number): Promise<void> {
await this.axiosInstance.delete(`/api/requests/${requestId}`);
}

public async closeFoodRequest(requestId: number): Promise<void> {
await this.axiosInstance.patch(`/api/requests/${requestId}/close`, {});
}
Expand Down
20 changes: 19 additions & 1 deletion apps/frontend/src/components/foodRequestManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { capitalize, formatDate } from '@utils/utils';
import { FloatingAlert } from '@components/floatingAlert';
import { FoodRequestStatus, FoodRequestSummaryDto } from '../types/types';
import RequestDetailsModal from '@components/forms/requestDetailsModal';
import PantryDeleteRequestActionModal from '@components/forms/pantryDeleteRequestModal';
import VolunteerCloseRequestActionModal from '@components/forms/volunteerCloseRequestModal';
import VolunteerRequestActionRequiredModal from '@components/forms/volunteerRequestActionRequiredModal';
import CreateNewOrderModal from '@components/forms/createNewOrderModal';
Expand Down Expand Up @@ -43,6 +44,8 @@ const RequestManagement: React.FC<RequestManagementProps> = ({
>([]);
const [selectedViewDetailsRequest, setSelectedViewDetailsRequest] =
useState<FoodRequestSummaryDto | null>(null);
const [deleteRequest, setDeleteRequest] =
useState<FoodRequestSummaryDto | null>(null);
const [selectedActionRequest, setSelectedActionRequest] =
useState<FoodRequestSummaryDto | null>(null);
const [selectedCloseRequestAction, setSelectedCloseRequestAction] =
Expand Down Expand Up @@ -392,7 +395,7 @@ const RequestManagement: React.FC<RequestManagementProps> = ({
</Table.Row>
))}

{selectedViewDetailsRequest && (
{selectedViewDetailsRequest && !deleteRequest && (
Copy link
Copy Markdown

@dburkhart07 dburkhart07 Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what's causing your bug. We are doing conditional rendering for the dialog, as opposed to using the open prop. We want to keep the Dialog mounted whenever a request is selected, and let the open prop do the showing/hiding. We essentially don't want to keep mounting and unmounting like we are right now (when deleteRequest gets a value, the component becomes faulty and gets unmounted), and should change it to this:

{selectedViewDetailsRequest && (
    <RequestDetailsModal
      request={selectedViewDetailsRequest}
      isOpen={!deleteRequest} 
      onClose={() => {
        setSelectedViewDetailsRequest(null);
        if (initialRequestId) {
          navigate(location.pathname, { replace: true });
        }
      }}
      onSuccess={loadRequests}
      onDelete={() => setDeleteRequest(selectedViewDetailsRequest)}
    />
  )}

This way, we toggle visibility on the presence of the delete request rather than mounting and unmounting

<RequestDetailsModal
request={selectedViewDetailsRequest}
isOpen={selectedViewDetailsRequest !== null}
Expand All @@ -402,6 +405,21 @@ const RequestManagement: React.FC<RequestManagementProps> = ({
navigate(location.pathname, { replace: true });
}
}}
onSuccess={loadRequests}
onDelete={() => setDeleteRequest(selectedViewDetailsRequest)}
/>
)}

{deleteRequest && (
<PantryDeleteRequestActionModal
request={deleteRequest}
isOpen={deleteRequest !== null}
onClose={() => setDeleteRequest(null)}
onSuccess={() => {
setSuccessMessage('Successfully deleted food request.');
loadRequests();
setSelectedViewDetailsRequest(null);
}}
/>
)}

Expand Down
133 changes: 133 additions & 0 deletions apps/frontend/src/components/forms/pantryDeleteRequestModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React from 'react';
import {
Box,
Button,
VStack,
CloseButton,
Text,
Flex,
Dialog,
} from '@chakra-ui/react';
import { FoodRequestSummaryDto } from 'types/types';
import { formatDate } from '@utils/utils';
import apiClient from '@api/apiClient';
import { useAlert } from '../../hooks/alert';
import { FloatingAlert } from '@components/floatingAlert';
import { useModalBodyCleanup } from '../../hooks/modalBodyCleanup';

interface DeleteRequestActionModalProps {
request: FoodRequestSummaryDto;
isOpen: boolean;
onClose: () => void;
onSuccess: () => void;
}

const PantryDeleteRequestActionModal: React.FC<
DeleteRequestActionModalProps
> = ({ request, isOpen, onClose, onSuccess }) => {
useModalBodyCleanup();
const [alertState, setAlertMessage] = useAlert();

const onCloseRequest = async () => {
try {
await apiClient.deleteFoodRequest(request.requestId);
onClose();
onSuccess();
} catch {
setAlertMessage('Food request could not be deleted.');
}
};

const cancelButton = (
<Button
textStyle="p2"
fontWeight={600}
color="neutral.800"
variant="outline"
width={16}
flexShrink={0}
textAlign="center"
lineHeight="28px"
onClick={onClose}
>
Cancel
</Button>
);

const deleteButton = (
<Button
textStyle="p2"
fontWeight={600}
bg={'red.hover'}
color={'white'}
width="92px"
flexShrink={0}
textAlign="center"
lineHeight="28px"
onClick={onCloseRequest}
>
Delete
</Button>
);

return (
<Dialog.Root
open={isOpen}
size="md"
onOpenChange={(e: { open: boolean }) => {
if (!e.open) onClose();
}}
closeOnInteractOutside
>
{alertState && (
<FloatingAlert
key={alertState.id}
message={alertState.message}
status="error"
timeout={6000}
/>
)}
<Dialog.Backdrop />
<Dialog.Positioner>
<Dialog.Content>
<Dialog.CloseTrigger asChild>
<CloseButton size="lg" />
</Dialog.CloseTrigger>

<Dialog.Header pb={0}>
<Dialog.Title fontSize="18px" fontFamily="inter" fontWeight={600}>
Confirm Action
</Dialog.Title>
</Dialog.Header>
<Dialog.Body pb={6}>
<VStack align="stretch" gap={4}>
<Text textStyle="p2" color="gray.dark">
Are you sure you want to delete this food request? This action
cannot be undone.
</Text>
<Box
borderWidth={1}
p={6}
borderColor={'neutral.100'}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i think this is supposed to be #E4E4E7, not neutral 100

borderRadius={5}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this to 6?

>
<Text textStyle="p2" color="gray.dark">
Request #{request.requestId}
</Text>
<Text color="neutral.600" textStyle="p2" fontSize={'12'}>
Submitted {formatDate(request.requestedAt)}
</Text>
</Box>
<Flex justifyContent="flex-end" gap={2.5}>
{cancelButton}
{deleteButton}
</Flex>
</VStack>
</Dialog.Body>
</Dialog.Content>
</Dialog.Positioner>
</Dialog.Root>
);
};

export default PantryDeleteRequestActionModal;
Loading
Loading