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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 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 faa3232
requested changes (except hover color)
jiang-h-y e5462a2
add delete buttons for volunteers + admins
jiang-h-y f63abd0
fixed colors
jiang-h-y e36c4ec
made edit/delete buttons into shareable components
jiang-h-y 3b98060
updated branch + fixed alert message
jiang-h-y ae11f7f
updated branch + fixed alert message
jiang-h-y 38165b5
update branch + fix small bugs
jiang-h-y cd87e30
requested changes
jiang-h-y b4fd039
Merge branch 'main' into hj/SSF-226-pantry-delete-edit-requests
jiang-h-y 6182e99
Merge branch 'main' into hj/SSF-226-pantry-delete-edit-requests
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { HStack } from '@chakra-ui/react'; | ||
| import { Pencil, Trash2 } from 'lucide-react'; | ||
|
|
||
| interface EditDeleteButtonProps { | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| export const EditButton: React.FC<EditDeleteButtonProps> = ({ onClick }) => { | ||
| return ( | ||
| <HStack | ||
| width={6} | ||
| height={6} | ||
| minWidth={6} | ||
| padding={0.5} | ||
| justify="center" | ||
| align="center" | ||
| gap={1} | ||
| flexShrink={0} | ||
| borderRadius="sm" | ||
| color={'gray.800'} | ||
| background="gray.subtle" | ||
| cursor="pointer" | ||
| _hover={{ background: 'neutral.200' }} | ||
| onClick={onClick} | ||
| > | ||
| <Pencil size={14} /> | ||
| </HStack> | ||
| ); | ||
| }; | ||
|
|
||
| export const DeleteButton: React.FC<EditDeleteButtonProps> = ({ onClick }) => { | ||
| return ( | ||
| <HStack | ||
| width={6} | ||
| height={6} | ||
| minWidth={6} | ||
| padding={0.5} | ||
| justify="center" | ||
| align="center" | ||
| gap={1} | ||
| flexShrink={0} | ||
| borderRadius="sm" | ||
| color="red.700" | ||
| background="red.subtle" | ||
| cursor="pointer" | ||
| _hover={{ background: 'red.300' }} | ||
| onClick={onClick} | ||
| > | ||
| <Trash2 size={14} /> | ||
| </HStack> | ||
| ); | ||
| }; | ||
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
127 changes: 127 additions & 0 deletions
127
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,127 @@ | ||
| import React from 'react'; | ||
| import { | ||
| Box, | ||
| Button, | ||
| VStack, | ||
| CloseButton, | ||
| Text, | ||
| Flex, | ||
| Dialog, | ||
| } from '@chakra-ui/react'; | ||
| import { AlertStatus, 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.', AlertStatus.ERROR); | ||
| } | ||
| }; | ||
|
|
||
| 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={alertState.status} | ||
| 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={'gray.200'} | ||
| borderRadius={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}> | ||
| <Button | ||
|
jiang-h-y marked this conversation as resolved.
|
||
| textStyle="p2" | ||
| fontWeight={600} | ||
| color="neutral.800" | ||
| variant="outline" | ||
| h="36px" | ||
| px={3} | ||
| flexShrink={0} | ||
| textAlign="center" | ||
| lineHeight="28px" | ||
| onClick={onClose} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| textStyle="p2" | ||
| fontWeight={600} | ||
| bg={'red.hover'} | ||
| color={'white'} | ||
| width="92px" | ||
| h="36px" | ||
| px={5} | ||
| flexShrink={0} | ||
| textAlign="center" | ||
| onClick={onCloseRequest} | ||
| > | ||
| Delete | ||
| </Button> | ||
| </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.