mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
## Context Related to FE-2461 More refactoring to clean up usage of `useQueryStateWithSelect`, in the following pages - Auth OAuth Apps - Cron Jobs - Vaults Secrets Management - Database Hooks - Wrappers ## To test In each of those pages, verify that - [ ] Clicking the "new" cta updates the URL params, and refreshing should re-open the sheet - [ ] Editing an existing item should update URL params, and refreshing should re-open the sheet with the right item - Verify that if the URL param has the wrong id, page should not open the sheet, show a toast, and reset the URL param - [ ] Deleting an existing item should update URL params, and refreshing should re-open the sheet with the right item - Verify that if the URL param has the wrong id, page should not open the sheet, show a toast, and reset the URL param <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Added "item not found" toasts and clearer feedback after create/update/delete actions; prevent opening create flows when server features are disabled. * **Style** * Standardized button labels, sizes and modal/dialog spacing; refined table column widths and inline code formatting for readability. * **Refactor** * Simplified UI state flows across OAuth Apps, Hooks/Webhooks, Cron Jobs, Vault Secrets, and Wrappers to use consistent URL-driven interactions and centralized modals. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { useVaultSecretDeleteMutation } from 'data/vault/vault-secret-delete-mutation'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useEffect } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Modal } from 'ui'
|
|
|
|
import { useVaultSecretsQuery } from '@/data/vault/vault-secrets-query'
|
|
|
|
export const DeleteSecretModal = () => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { data: secrets = [], isSuccess } = useVaultSecretsQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const [secretIdToDelete, setSelectedSecretToDelete] = useQueryState('delete', parseAsString)
|
|
const selectedSecret = secrets.find((secret) => secret.id === secretIdToDelete)
|
|
|
|
const {
|
|
mutate: deleteSecret,
|
|
isPending: isDeleting,
|
|
isSuccess: isSuccessDelete,
|
|
} = useVaultSecretDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully deleted secret ${selectedSecret?.name}`)
|
|
setSelectedSecretToDelete(null)
|
|
},
|
|
onError: (error) => {
|
|
toast.error(`Failed to delete secret: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const onConfirmDeleteSecret = async () => {
|
|
if (!project) return console.error('Project is required')
|
|
if (!selectedSecret) return
|
|
|
|
deleteSecret({
|
|
projectRef: project.ref,
|
|
connectionString: project?.connectionString,
|
|
id: selectedSecret.id,
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (isSuccess && !!secretIdToDelete && !selectedSecret && !isSuccessDelete) {
|
|
toast('Secret not found')
|
|
setSelectedSecretToDelete(null)
|
|
}
|
|
}, [isSuccess, isSuccessDelete, secretIdToDelete, selectedSecret, setSelectedSecretToDelete])
|
|
|
|
return (
|
|
<Modal
|
|
size="small"
|
|
variant="danger"
|
|
alignFooter="right"
|
|
header="Confirm to delete secret"
|
|
visible={!!selectedSecret}
|
|
loading={isDeleting}
|
|
onCancel={() => setSelectedSecretToDelete(null)}
|
|
onConfirm={onConfirmDeleteSecret}
|
|
>
|
|
<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>
|
|
)
|
|
}
|