mirror of
https://github.com/supabase/supabase.git
synced 2026-05-25 21:24:01 +08:00
* feat: add basic api keys ui * init JWT secrets. rough * Update JWTSecretKeysTable.tsx * added some info hover cards. • found this this is probably the wrong direction • will create a new page for next iteration. * init new version * add illustrations * Update JWTSecretKeysTablev2.tsx * chore: delete API key now works * some style changes * added better tables * Update JWTSecretKeysTablev2.tsx * add public JWT dialog * moar * adding sub layout in * starts adding in a ButtonGroup * about to make into separate components * added quick copy to project loading screen * build state * basic loading * confirm dialog and loading states * switched for better loading experience * moved styles of Input to InputVariants * issue with ref type * loading,error and rest states * new loading states * alt l;ayout * add group * updated error states for permissions * copy button behaviour for secret keys * delete dialog * Update QuickKeyCopy.tsx * fix type errors * Update JWTSecretKeysTablev2.tsx * update menu to hide pages * Update SettingsMenu.utils.tsx * Update resource-query.ts * remove old file * moved JWT secrets to use valtio * Update api-keys-query.ts * fix typecheck * rename files * remove JWT stuff * revert file * remove more JWT stuff * Update package.json * Update pnpm-lock.yaml * Update ProjectLayout.tsx * Update PublishableAPIKeys.tsx * Update api-keys-query.ts * refactor api-keys-query * Update SettingsMenu.utils.tsx * Some clean up * more clean up and refactor * Update APIKeyRow.tsx * Update LayoutHeader.tsx * resolve comments * Update CreateSecretAPIKeyModal.tsx * Update APIKeyRow.tsx * Add perms check for delete API keys * Remove console log * Delete ConnectDialog.tsx * use project ref --------- Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useParams } from 'common/hooks'
|
|
import { useAPIKeyDeleteMutation } from 'data/api-keys/api-key-delete-mutation'
|
|
import { APIKeysData } from 'data/api-keys/api-keys-query'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { DropdownMenuItem } from 'ui'
|
|
import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
|
|
|
|
interface APIKeyDeleteDialogProps {
|
|
apiKey: Extract<APIKeysData[number], { type: 'secret' | 'publishable' }>
|
|
}
|
|
|
|
export const APIKeyDeleteDialog = ({ apiKey }: APIKeyDeleteDialogProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
const canDeleteAPIKeys = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, '*')
|
|
|
|
const { mutate: deleteAPIKey, isLoading: isDeletingAPIKey } = useAPIKeyDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully deleted API key`)
|
|
setIsOpen(false)
|
|
},
|
|
})
|
|
|
|
const onDeleteAPIKey = () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
deleteAPIKey({ projectRef, id: apiKey.id })
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<DropdownMenuItem
|
|
className="flex gap-2 !pointer-events-auto"
|
|
onClick={async (e) => {
|
|
if (canDeleteAPIKeys) {
|
|
e.preventDefault()
|
|
setIsOpen(true)
|
|
}
|
|
}}
|
|
>
|
|
Delete API key
|
|
</DropdownMenuItem>
|
|
<TextConfirmModal
|
|
visible={isOpen}
|
|
onCancel={() => setIsOpen(false)}
|
|
onConfirm={onDeleteAPIKey}
|
|
title={`Delete ${apiKey.description ?? ''} API secret key`}
|
|
confirmString={apiKey.description || 'Delete API secret key'}
|
|
confirmLabel="Delete API secret key"
|
|
confirmPlaceholder="Type API key description to confirm"
|
|
loading={isDeletingAPIKey}
|
|
variant="destructive"
|
|
alert={{
|
|
title: 'This cannot be undone',
|
|
description:
|
|
'Deleting this API key will invalidate it immediately. Any applications using this key will no longer be able to access this project.',
|
|
}}
|
|
/>
|
|
</>
|
|
)
|
|
}
|