diff --git a/src/components/common/ConfirmationModal.tsx b/src/components/common/ConfirmationModal.tsx index 54f545b..9a8ca0b 100644 --- a/src/components/common/ConfirmationModal.tsx +++ b/src/components/common/ConfirmationModal.tsx @@ -32,6 +32,9 @@ export function ConfirmationModal() { }; const handleCancel = () => { + if (isLoading) { + return; + } if (onCancel) { onCancel(); } @@ -39,7 +42,7 @@ export function ConfirmationModal() { }; return ( - +

{message}

diff --git a/src/pages/ApiKeysPage.tsx b/src/pages/ApiKeysPage.tsx index 8fe8d28..61573ed 100644 --- a/src/pages/ApiKeysPage.tsx +++ b/src/pages/ApiKeysPage.tsx @@ -115,14 +115,32 @@ export function ApiKeysPage() { }; const handleDelete = (index: number) => { + const apiKeyToDelete = apiKeys[index]; + if (!apiKeyToDelete) { + showNotification(t('notification.delete_failed'), 'error'); + return; + } + showConfirmation({ title: t('common.delete'), message: t('api_keys.delete_confirm'), variant: 'danger', onConfirm: async () => { + const latestKeys = useConfigStore.getState().config?.apiKeys; + const currentKeys = Array.isArray(latestKeys) ? latestKeys : []; + const deleteIndex = + currentKeys[index] === apiKeyToDelete + ? index + : currentKeys.findIndex((key) => key === apiKeyToDelete); + + if (deleteIndex < 0) { + showNotification(t('notification.delete_failed'), 'error'); + return; + } + try { - await apiKeysApi.delete(index); - const nextKeys = apiKeys.filter((_, idx) => idx !== index); + await apiKeysApi.delete(deleteIndex); + const nextKeys = currentKeys.filter((_, idx) => idx !== deleteIndex); setApiKeys(nextKeys); updateConfigValue('api-keys', nextKeys); clearCache('api-keys'); diff --git a/src/styles/components.scss b/src/styles/components.scss index 656de5d..76e59f5 100644 --- a/src/styles/components.scss +++ b/src/styles/components.scss @@ -453,6 +453,18 @@ textarea { &:active { transform: scale(0.95); } + + &:disabled { + cursor: not-allowed; + opacity: 0.6; + transform: none; + } + + &:disabled:hover { + color: var(--text-secondary); + background: var(--bg-secondary); + transform: none; + } } .modal-header {