-
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.
- Loading branch information
1 parent
d6ea6d4
commit 1b43b53
Showing
3 changed files
with
117 additions
and
7 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
102 changes: 102 additions & 0 deletions
102
frontend/src/features/workspace/components/WorkspaceModals/DeleteWorkspaceModal.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,102 @@ | ||
import { useForm } from 'react-hook-form' | ||
import { | ||
FormControl, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
Stack, | ||
Text, | ||
useBreakpointValue, | ||
} from '@chakra-ui/react' | ||
import { isEmpty } from 'lodash' | ||
|
||
import Button from '~components/Button' | ||
import FormErrorMessage from '~components/FormControl/FormErrorMessage' | ||
import Radio from '~components/Radio' | ||
|
||
export interface DeleteWorkspaceModalProps { | ||
isOpen: boolean | ||
onClose: () => void | ||
} | ||
|
||
const DELETE_OPTIONS = [ | ||
'Delete Workspace only', | ||
'Delete Workspace and all forms within', | ||
] | ||
|
||
export const DeleteWorkspaceModal = ({ | ||
isOpen, | ||
onClose, | ||
}: DeleteWorkspaceModalProps): JSX.Element => { | ||
const { | ||
handleSubmit, | ||
formState: { errors }, | ||
register, | ||
} = useForm() | ||
const modalSize = useBreakpointValue({ | ||
base: 'mobile', | ||
xs: 'mobile', | ||
md: 'md', | ||
}) | ||
|
||
// TODO (hans): Implement delete workspace functionality | ||
const handleDeleteWorkspace = handleSubmit((data) => { | ||
onClose() | ||
}) | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose} size={modalSize}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Delete workspace</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<Text textStyle="body-2" color="secondary.500"> | ||
All responses associated to the forms or workspaces will be deleted. | ||
</Text> | ||
<FormControl isRequired isInvalid={!isEmpty(errors)}> | ||
<Radio.RadioGroup mt="1.5rem"> | ||
{DELETE_OPTIONS.map((o, idx) => ( | ||
<Radio | ||
key={idx} | ||
value={o} | ||
{...register('radio', { | ||
required: { | ||
value: true, | ||
message: 'This field is required', | ||
}, | ||
})} | ||
> | ||
{o} | ||
</Radio> | ||
))} | ||
</Radio.RadioGroup> | ||
<FormErrorMessage>{errors['radio']?.message}</FormErrorMessage> | ||
</FormControl> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Stack | ||
w="100vw" | ||
direction={{ base: 'column', md: 'row' }} | ||
spacing={{ base: '2rem', md: '1rem' }} | ||
gap={{ base: '1rem', md: 'inherit' }} | ||
flexDir={{ base: 'column-reverse', md: 'inherit' }} | ||
justifyContent="flex-end" | ||
> | ||
<Button onClick={onClose} variant="clear" colorScheme="secondary"> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleDeleteWorkspace} colorScheme="danger"> | ||
Yes, delete workspace | ||
</Button> | ||
</Stack> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |