mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 13:19:09 +03:00
* Bump react-query. Minor type and logic fixes. * Migrate all use of isLoading to isPending in mutations. * Fix type errors.
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { toast } from 'sonner'
|
|
|
|
import { useVaultSecretDeleteMutation } from 'data/vault/vault-secret-delete-mutation'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import type { VaultSecret } from 'types'
|
|
import { Modal } from 'ui'
|
|
|
|
interface DeleteSecretModalProps {
|
|
selectedSecret: VaultSecret | undefined
|
|
onClose: () => void
|
|
onDeleteStart?: (secretId: string) => void
|
|
}
|
|
|
|
const DeleteSecretModal = ({ selectedSecret, onClose, onDeleteStart }: DeleteSecretModalProps) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { mutate: deleteSecret, isPending: isDeleting } = useVaultSecretDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully deleted secret ${selectedSecret?.name}`)
|
|
onClose()
|
|
},
|
|
onError: (error) => {
|
|
toast.error(`Failed to delete secret: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const onConfirmDeleteSecret = async () => {
|
|
if (!project) return console.error('Project is required')
|
|
if (!selectedSecret) return
|
|
|
|
onDeleteStart?.(selectedSecret.id)
|
|
deleteSecret({
|
|
projectRef: project.ref,
|
|
connectionString: project?.connectionString,
|
|
id: selectedSecret.id,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
size="small"
|
|
alignFooter="right"
|
|
visible={selectedSecret !== undefined}
|
|
onCancel={onClose}
|
|
onConfirm={onConfirmDeleteSecret}
|
|
loading={isDeleting}
|
|
header="Confirm to delete secret"
|
|
>
|
|
<Modal.Content className="space-y-4">
|
|
<p className="text-sm">
|
|
The following secret will be permanently removed and cannot be recovered. Are you sure?
|
|
</p>
|
|
<div className="space-y-1">
|
|
<p className="text-sm">{selectedSecret?.description}</p>
|
|
<p className="text-sm text-foreground-light">
|
|
ID: <span className="font-mono">{selectedSecret?.id}</span>
|
|
</p>
|
|
</div>
|
|
</Modal.Content>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export default DeleteSecretModal
|