RevokeCredentialModal.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { useParams } from 'common'
  2. import { toast } from 'sonner'
  3. import {
  4. Button,
  5. Dialog,
  6. DialogContent,
  7. DialogDescription,
  8. DialogFooter,
  9. DialogHeader,
  10. DialogSection,
  11. DialogSectionSeparator,
  12. DialogTitle,
  13. } from 'ui'
  14. import { useS3AccessKeyDeleteMutation } from '@/data/storage/s3-access-key-delete-mutation'
  15. interface RevokeCredentialModalProps {
  16. visible: boolean
  17. selectedCredential?: { id: string; description: string }
  18. onClose: () => void
  19. }
  20. export const RevokeCredentialModal = ({
  21. visible,
  22. selectedCredential,
  23. onClose,
  24. }: RevokeCredentialModalProps) => {
  25. const { ref: projectRef } = useParams()
  26. const { mutate: deleteS3AccessKey, isPending: isDeleting } = useS3AccessKeyDeleteMutation({
  27. onSuccess: () => {
  28. toast.success('Successfully revoked S3 access key')
  29. onClose()
  30. },
  31. })
  32. return (
  33. <Dialog open={visible} onOpenChange={onClose}>
  34. <DialogContent size="small">
  35. <DialogHeader>
  36. <DialogTitle>
  37. Revoke credential <code className="text-sm">{selectedCredential?.description}</code>
  38. </DialogTitle>
  39. </DialogHeader>
  40. <DialogSectionSeparator />
  41. <DialogSection>
  42. <DialogDescription>
  43. This action is irreversible and requests made with these access keys will stop working.
  44. </DialogDescription>
  45. </DialogSection>
  46. <DialogFooter className="flex justify-end gap-x-1">
  47. <Button type="outline" onClick={() => onClose()}>
  48. Cancel
  49. </Button>
  50. <Button
  51. type="danger"
  52. loading={isDeleting}
  53. onClick={async () => {
  54. if (!selectedCredential) return
  55. deleteS3AccessKey({ id: selectedCredential.id, projectRef })
  56. }}
  57. >
  58. Yes, revoke access keys
  59. </Button>
  60. </DialogFooter>
  61. </DialogContent>
  62. </Dialog>
  63. )
  64. }