Spaces:
Build error
Build error
File size: 2,199 Bytes
b59aa07 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import React from "react";
import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
import { BrandButton } from "#/components/features/settings/brand-button";
import { LoadingSpinner } from "#/components/shared/loading-spinner";
import { ApiKey } from "#/api/api-keys";
import {
displayErrorToast,
displaySuccessToast,
} from "#/utils/custom-toast-handlers";
import { ApiKeyModalBase } from "./api-key-modal-base";
import { useDeleteApiKey } from "#/hooks/mutation/use-delete-api-key";
interface DeleteApiKeyModalProps {
isOpen: boolean;
keyToDelete: ApiKey | null;
onClose: () => void;
}
export function DeleteApiKeyModal({
isOpen,
keyToDelete,
onClose,
}: DeleteApiKeyModalProps) {
const { t } = useTranslation();
const deleteApiKeyMutation = useDeleteApiKey();
const handleDeleteKey = async () => {
if (!keyToDelete) return;
try {
await deleteApiKeyMutation.mutateAsync(keyToDelete.id);
displaySuccessToast(t(I18nKey.SETTINGS$API_KEY_DELETED));
onClose();
} catch (error) {
displayErrorToast(t(I18nKey.ERROR$GENERIC));
}
};
if (!keyToDelete) return null;
const modalFooter = (
<>
<BrandButton
type="button"
variant="danger"
className="grow"
onClick={handleDeleteKey}
isDisabled={deleteApiKeyMutation.isPending}
>
{deleteApiKeyMutation.isPending ? (
<LoadingSpinner size="small" />
) : (
t(I18nKey.BUTTON$DELETE)
)}
</BrandButton>
<BrandButton
type="button"
variant="secondary"
className="grow"
onClick={onClose}
isDisabled={deleteApiKeyMutation.isPending}
>
{t(I18nKey.BUTTON$CANCEL)}
</BrandButton>
</>
);
return (
<ApiKeyModalBase
isOpen={isOpen && !!keyToDelete}
title={t(I18nKey.SETTINGS$DELETE_API_KEY)}
footer={modalFooter}
>
<div data-testid="delete-api-key-modal">
<p className="text-sm">
{t(I18nKey.SETTINGS$DELETE_API_KEY_CONFIRMATION, {
name: keyToDelete.name,
})}
</p>
</div>
</ApiKeyModalBase>
);
}
|