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
- Loading branch information
Showing
9 changed files
with
265 additions
and
17 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
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
import { | ||
Button, | ||
HStack, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
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'; | ||
|
||
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" variant="ghost" onClick={onToggle}> | ||
Delete | ||
</Button> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Are you sure?</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
Delete credential '{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> | ||
</> | ||
); | ||
}; |
67 changes: 67 additions & 0 deletions
67
webapp/src/dogma/features/project/settings/mirrors/DeleteMirror.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,67 @@ | ||
import { | ||
Button, | ||
HStack, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
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'; | ||
|
||
export const DeleteMirror = ({ | ||
projectName, | ||
id, | ||
deleteMirror, | ||
isLoading, | ||
}: { | ||
projectName: string; | ||
id: string; | ||
deleteMirror: (projectName: string, id: string, ) => Promise<void>; | ||
isLoading: boolean; | ||
}): JSX.Element => { | ||
const { isOpen, onToggle, onClose } = useDisclosure(); | ||
const dispatch = useAppDispatch(); | ||
const handleDelete = async () => { | ||
try { | ||
await deleteMirror(projectName, id); | ||
dispatch(newNotification('Mirror 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" variant="ghost" onClick={onToggle}> | ||
Delete | ||
</Button> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Are you sure?</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
Delete mirror '{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> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.