|
1 | 1 | import { Paintbrush } from "lucide-react"; |
2 | 2 | import { toast } from "sonner"; |
3 | 3 | import { |
4 | | - AlertDialog, |
5 | | - AlertDialogAction, |
6 | | - AlertDialogCancel, |
7 | | - AlertDialogContent, |
8 | | - AlertDialogDescription, |
9 | | - AlertDialogFooter, |
10 | | - AlertDialogHeader, |
11 | | - AlertDialogTitle, |
12 | | - AlertDialogTrigger, |
| 4 | + AlertDialog, |
| 5 | + AlertDialogAction, |
| 6 | + AlertDialogCancel, |
| 7 | + AlertDialogContent, |
| 8 | + AlertDialogDescription, |
| 9 | + AlertDialogFooter, |
| 10 | + AlertDialogHeader, |
| 11 | + AlertDialogTitle, |
| 12 | + AlertDialogTrigger, |
13 | 13 | } from "@/components/ui/alert-dialog"; |
14 | 14 | import { Button } from "@/components/ui/button"; |
15 | 15 | import { api } from "@/utils/api"; |
16 | 16 |
|
17 | 17 | interface Props { |
18 | | - id: string; |
19 | | - type: "application" | "compose"; |
| 18 | + id: string; |
| 19 | + type: "application" | "compose"; |
20 | 20 | } |
21 | 21 |
|
22 | 22 | export const ClearDeployments = ({ id, type }: Props) => { |
23 | | - const utils = api.useUtils(); |
24 | | - const { mutateAsync, isLoading } = |
25 | | - type === "application" |
26 | | - ? api.application.clearDeployments.useMutation() |
27 | | - : api.compose.clearDeployments.useMutation(); |
28 | | - const { data: isCloud } = api.settings.isCloud.useQuery(); |
| 23 | + const utils = api.useUtils(); |
| 24 | + const { mutateAsync, isLoading } = |
| 25 | + type === "application" |
| 26 | + ? api.application.clearDeployments.useMutation() |
| 27 | + : api.compose.clearDeployments.useMutation(); |
| 28 | + const { data: isCloud } = api.settings.isCloud.useQuery(); |
29 | 29 |
|
30 | | - if (isCloud) { |
31 | | - return null; |
32 | | - } |
| 30 | + if (isCloud) { |
| 31 | + return null; |
| 32 | + } |
33 | 33 |
|
34 | | - return ( |
35 | | - <AlertDialog> |
36 | | - <AlertDialogTrigger asChild> |
37 | | - <Button variant="outline" className="w-fit" isLoading={isLoading}> |
38 | | - Clear deployments |
39 | | - <Paintbrush className="size-4" /> |
40 | | - </Button> |
41 | | - </AlertDialogTrigger> |
42 | | - <AlertDialogContent> |
43 | | - <AlertDialogHeader> |
44 | | - <AlertDialogTitle> |
45 | | - Are you sure you want to clear old deployments? |
46 | | - </AlertDialogTitle> |
47 | | - <AlertDialogDescription> |
48 | | - This will delete all old deployment records and logs, keeping only the active deployment (the most recent successful one). |
49 | | - </AlertDialogDescription> |
50 | | - </AlertDialogHeader> |
51 | | - <AlertDialogFooter> |
52 | | - <AlertDialogCancel>Cancel</AlertDialogCancel> |
53 | | - <AlertDialogAction |
54 | | - onClick={async () => { |
55 | | - await mutateAsync({ |
56 | | - applicationId: id || "", |
57 | | - composeId: id || "", |
58 | | - }) |
59 | | - .then(async (result) => { |
60 | | - toast.success(`${result.deletedCount} old deployments cleared successfully`); |
61 | | - // Invalidate deployment queries to refresh the list |
62 | | - await utils.deployment.allByType.invalidate({ |
63 | | - id, |
64 | | - type, |
65 | | - }); |
66 | | - }) |
67 | | - .catch((err) => { |
68 | | - toast.error(err.message); |
69 | | - }); |
70 | | - }} |
71 | | - > |
72 | | - Confirm |
73 | | - </AlertDialogAction> |
74 | | - </AlertDialogFooter> |
75 | | - </AlertDialogContent> |
76 | | - </AlertDialog> |
77 | | - ); |
| 34 | + return ( |
| 35 | + <AlertDialog> |
| 36 | + <AlertDialogTrigger asChild> |
| 37 | + <Button variant="outline" className="w-fit" isLoading={isLoading}> |
| 38 | + Clear deployments |
| 39 | + <Paintbrush className="size-4" /> |
| 40 | + </Button> |
| 41 | + </AlertDialogTrigger> |
| 42 | + <AlertDialogContent> |
| 43 | + <AlertDialogHeader> |
| 44 | + <AlertDialogTitle> |
| 45 | + Are you sure you want to clear old deployments? |
| 46 | + </AlertDialogTitle> |
| 47 | + <AlertDialogDescription> |
| 48 | + This will delete all old deployment records and logs, keeping only |
| 49 | + the active deployment (the most recent successful one). |
| 50 | + </AlertDialogDescription> |
| 51 | + </AlertDialogHeader> |
| 52 | + <AlertDialogFooter> |
| 53 | + <AlertDialogCancel>Cancel</AlertDialogCancel> |
| 54 | + <AlertDialogAction |
| 55 | + onClick={async () => { |
| 56 | + await mutateAsync({ |
| 57 | + applicationId: id || "", |
| 58 | + composeId: id || "", |
| 59 | + }) |
| 60 | + .then(async (result) => { |
| 61 | + toast.success( |
| 62 | + `${result.deletedCount} old deployments cleared successfully`, |
| 63 | + ); |
| 64 | + // Invalidate deployment queries to refresh the list |
| 65 | + await utils.deployment.allByType.invalidate({ |
| 66 | + id, |
| 67 | + type, |
| 68 | + }); |
| 69 | + }) |
| 70 | + .catch((err) => { |
| 71 | + toast.error(err.message); |
| 72 | + }); |
| 73 | + }} |
| 74 | + > |
| 75 | + Confirm |
| 76 | + </AlertDialogAction> |
| 77 | + </AlertDialogFooter> |
| 78 | + </AlertDialogContent> |
| 79 | + </AlertDialog> |
| 80 | + ); |
78 | 81 | }; |
0 commit comments