"use client"; import { useState, useEffect } from "react"; import { toast } from "sonner"; import { AlertTriangle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Label } from "@/components/ui/label"; import { useI18n } from "@/i18n/i18n-context"; import { useDeleteApiKey } from "@/hooks/use-delete-api-key"; import type { ApiKey } from "@/types/api-key"; interface ApiKeyDeleteDialogProps { apiKey: ApiKey | null; open: boolean; onOpenChange: (open: boolean) => void; } export function ApiKeyDeleteDialog({ apiKey, open, onOpenChange, }: ApiKeyDeleteDialogProps) { const { t } = useI18n(); const deleteMutation = useDeleteApiKey(); const [deleteCustomPolicy, setDeleteCustomPolicy] = useState(true); const [deleteRamUser, setDeleteRamUser] = useState(true); useEffect(() => { if (open) { setDeleteCustomPolicy(true); setDeleteRamUser(true); } }, [open]); async function handleDelete() { if (!apiKey) return; try { await deleteMutation.mutateAsync({ serviceCredentialId: apiKey.serviceCredentialId, userPrincipalName: apiKey.userPrincipalName, deleteCustomPolicy, deleteRamUser, }); toast.success(t("apiKeys.delete.deleteSuccess")); onOpenChange(false); } catch (err) { toast.error( err instanceof Error ? err.message : t("apiKeys.delete.deleteFailed"), ); } } return ( {t("apiKeys.delete.title")}

{t("apiKeys.delete.warning")}

{apiKey ? ( <>

{t("apiKeys.delete.credentialNameLabel")} {apiKey.serviceCredentialName}

{apiKey.status === "Active" ? (

{t("apiKeys.delete.activeHint")}

) : null} ) : null}

{t("apiKeys.delete.cleanupHint")}

); }