forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-226] Pantry Deleting & Editing Food Requests Frontend #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jiang-h-y
wants to merge
6
commits into
main
Choose a base branch
from
hj/SSF-226-pantry-delete-edit-requests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1a7e2ed
added edit/delete buttons + edit view/delete modal + connected to bac…
jiang-h-y 45119d9
handle edge cases
jiang-h-y 16cd7c4
added success/error toasts
jiang-h-y a738bf4
moved colors into theme config instead of hard coding
jiang-h-y b96d71b
fixed delete button color + unclickable ui bug
jiang-h-y 96f34a0
resolve merge conflict
jiang-h-y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
apps/frontend/src/components/forms/pantryDeleteRequestModal.tsx
This file contains hidden or 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,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'} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
This way, we toggle visibility on the presence of the delete request rather than mounting and unmounting