-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement field deletion confirmation modal (#3694)
* feat: implement field deletion confirmation modal * refactor: rename context vars to xxDisclosure * refactor: remove unnecessary string literal
- Loading branch information
1 parent
91ae3af
commit 0b5e564
Showing
7 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
74 changes: 74 additions & 0 deletions
74
...d/src/features/admin-form/create/builder-and-design/DeleteFieldModal/DeleteFieldModal.tsx
This file contains 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,74 @@ | ||
import { useCallback, useMemo } from 'react' | ||
import { | ||
ButtonGroup, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
} from '@chakra-ui/react' | ||
|
||
import Button from '~components/Button' | ||
import { ModalCloseButton } from '~components/Modal' | ||
|
||
import { BASICFIELD_TO_DRAWER_META } from '../../constants' | ||
import { useBuilderAndDesignContext } from '../BuilderAndDesignContext' | ||
import { useDeleteFormField } from '../mutations/useDeleteFormField' | ||
import { | ||
BuildFieldState, | ||
stateDataSelector, | ||
useBuilderAndDesignStore, | ||
} from '../useBuilderAndDesignStore' | ||
|
||
export const DeleteFieldModal = (): JSX.Element => { | ||
const stateData = useBuilderAndDesignStore(stateDataSelector) | ||
const { | ||
deleteFieldModalDisclosure: { isOpen, onClose }, | ||
} = useBuilderAndDesignContext() | ||
|
||
const fieldTypeLabel = useMemo(() => { | ||
if (stateData.state === BuildFieldState.EditingField) { | ||
return BASICFIELD_TO_DRAWER_META[stateData.field.fieldType].label | ||
} | ||
return null | ||
}, [stateData]) | ||
|
||
const { deleteFieldMutation } = useDeleteFormField() | ||
|
||
const handleDeleteConfirmation = useCallback(() => { | ||
if (stateData.state === BuildFieldState.EditingField) { | ||
deleteFieldMutation.mutate(stateData.field._id, { | ||
onSuccess: onClose, | ||
}) | ||
} | ||
}, [deleteFieldMutation, onClose, stateData]) | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalCloseButton /> | ||
<ModalHeader>Delete {fieldTypeLabel} field</ModalHeader> | ||
<ModalBody> | ||
This field will be deleted permanently. Are you sure you want to | ||
proceed? | ||
</ModalBody> | ||
<ModalFooter> | ||
<ButtonGroup> | ||
<Button variant="clear" colorScheme="secondary" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button | ||
colorScheme="danger" | ||
onClick={handleDeleteConfirmation} | ||
isLoading={deleteFieldMutation.isLoading} | ||
> | ||
Yes, delete field | ||
</Button> | ||
</ButtonGroup> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/features/admin-form/create/builder-and-design/DeleteFieldModal/index.ts
This file contains 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 @@ | ||
export * from './DeleteFieldModal' |