forked from line/centraldogma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide ways to delete mirror and credential (line#1051)
There's no way to delete mirror and credential Result: - You can now delete mirror and credential.
- Loading branch information
Showing
14 changed files
with
374 additions
and
73 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
54 changes: 54 additions & 0 deletions
54
webapp/src/dogma/features/project/settings/DeleteConfirmationModal.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,54 @@ | ||
import { | ||
Button, | ||
HStack, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
} from '@chakra-ui/react'; | ||
|
||
interface DeleteConfirmationModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
type: string; | ||
id: string; | ||
projectName: string; | ||
handleDelete: () => void; | ||
isLoading: boolean; | ||
} | ||
|
||
export const DeleteConfirmationModal = ({ | ||
isOpen, | ||
onClose, | ||
id, | ||
type, | ||
projectName, | ||
handleDelete, | ||
isLoading, | ||
}: DeleteConfirmationModalProps): JSX.Element => { | ||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Are you sure?</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
Delete {type} '{id}' from {projectName}? | ||
</ModalBody> | ||
<ModalFooter> | ||
<HStack spacing={3}> | ||
<Button colorScheme="red" variant="outline" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button colorScheme="red" onClick={handleDelete} isLoading={isLoading} loadingText="Deleting"> | ||
Delete | ||
</Button> | ||
</HStack> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; |
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
46 changes: 46 additions & 0 deletions
46
webapp/src/dogma/features/project/settings/credentials/DeleteCredential.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,46 @@ | ||
import { Button, useDisclosure } from '@chakra-ui/react'; | ||
import { newNotification } from 'dogma/features/notification/notificationSlice'; | ||
import ErrorMessageParser from 'dogma/features/services/ErrorMessageParser'; | ||
import { useAppDispatch } from 'dogma/hooks'; | ||
import { MdDelete } from 'react-icons/md'; | ||
import { DeleteConfirmationModal } from 'dogma/features/project/settings/DeleteConfirmationModal'; | ||
|
||
export const DeleteCredential = ({ | ||
projectName, | ||
id, | ||
deleteCredential, | ||
isLoading, | ||
}: { | ||
projectName: string; | ||
id: string; | ||
deleteCredential: (projectName: string, id: string) => Promise<void>; | ||
isLoading: boolean; | ||
}): JSX.Element => { | ||
const { isOpen, onToggle, onClose } = useDisclosure(); | ||
const dispatch = useAppDispatch(); | ||
const handleDelete = async () => { | ||
try { | ||
await deleteCredential(projectName, id); | ||
dispatch(newNotification('Credential deleted.', `Successfully deleted ${id}`, 'success')); | ||
onClose(); | ||
} catch (error) { | ||
dispatch(newNotification(`Failed to delete ${id}`, ErrorMessageParser.parse(error), 'error')); | ||
} | ||
}; | ||
return ( | ||
<> | ||
<Button leftIcon={<MdDelete />} colorScheme="red" size="sm" onClick={onToggle}> | ||
Delete | ||
</Button> | ||
<DeleteConfirmationModal | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
id={id} | ||
type={'credential'} | ||
projectName={projectName} | ||
handleDelete={handleDelete} | ||
isLoading={isLoading} | ||
/> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.