blob: b4cf7eea21903cec735339e0909fddb7406364e7 (
plain) (
blame)
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
|
"use client";
import { useRouter } from "next/navigation";
import { ActionButton } from "@/components/ui/action-button";
import ActionConfirmingDialog from "@/components/ui/action-confirming-dialog";
import { Button } from "@/components/ui/button";
import { useTranslation } from "@/lib/i18n/client";
import { useMutation } from "@tanstack/react-query";
import { Trash } from "lucide-react";
import { toast } from "sonner";
import { useTRPC } from "@karakeep/shared-react/trpc";
export default function DeleteApiKey({
name,
id,
}: {
name: string;
id: string;
}) {
const api = useTRPC();
const { t } = useTranslation();
const router = useRouter();
const mutator = useMutation(
api.apiKeys.revoke.mutationOptions({
onSuccess: () => {
toast.success("Key was successfully deleted");
router.refresh();
},
}),
);
return (
<ActionConfirmingDialog
title={"Delete API Key"}
description={
<p>
Are you sure you want to delete the API key "{name}"? Any
service using this API key will lose access.
</p>
}
actionButton={(setDialogOpen) => (
<ActionButton
type="button"
variant="destructive"
loading={mutator.isPending}
onClick={() =>
mutator.mutate({ id }, { onSuccess: () => setDialogOpen(false) })
}
>
{t("actions.delete")}
</ActionButton>
)}
>
<Button variant="ghost" title={t("actions.delete")}>
<Trash size={18} />
</Button>
</ActionConfirmingDialog>
);
}
|