@@ -10,11 +10,13 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
10
10
import { useCurrentWorkspaceId , useHasAdminPermission } from '@/store/user' ;
11
11
import { routeAuthBeforeLoad } from '@/utils/route' ;
12
12
import { createFileRoute , useNavigate } from '@tanstack/react-router' ;
13
- import { LuPencil } from 'react-icons/lu' ;
13
+ import { LuPencil , LuTrash } from 'react-icons/lu' ;
14
14
import { useTranslation } from '@i18next-toolkit/react' ;
15
15
import { ApplicationOverviewCard } from '@/components/application/ApplicationOverviewCard' ;
16
16
import { ApplicationDetailCard } from '@/components/application/ApplicationDetailCard' ;
17
17
import { ApplicationStatsChart } from '@/components/application/ApplicationStatsChart' ;
18
+ import { AlertConfirm } from '@/components/AlertConfirm' ;
19
+ import { message } from 'antd' ;
18
20
19
21
export const Route = createFileRoute ( '/application/$applicationId/' ) ( {
20
22
beforeLoad : routeAuthBeforeLoad ,
@@ -31,6 +33,25 @@ function PageComponent() {
31
33
const navigate = useNavigate ( ) ;
32
34
const hasAdminPermission = useHasAdminPermission ( ) ;
33
35
const { t } = useTranslation ( ) ;
36
+ const trpcUtils = trpc . useUtils ( ) ;
37
+
38
+ const deleteMutation = trpc . application . delete . useMutation ( {
39
+ onError : ( error ) => {
40
+ message . error ( error . message ) ;
41
+ } ,
42
+ } ) ;
43
+
44
+ const handleDeleteApplication = async ( ) => {
45
+ await deleteMutation . mutateAsync ( { workspaceId, applicationId } ) ;
46
+
47
+ message . success ( t ( 'Delete Success' ) ) ;
48
+
49
+ await trpcUtils . application . all . refetch ( { workspaceId } ) ;
50
+
51
+ navigate ( {
52
+ to : '/application' ,
53
+ } ) ;
54
+ } ;
34
55
35
56
if ( ! applicationId ) {
36
57
return < ErrorTip /> ;
@@ -52,19 +73,30 @@ function PageComponent() {
52
73
actions = {
53
74
< div className = "space-x-2" >
54
75
{ hasAdminPermission && (
55
- < Button
56
- size = "icon"
57
- variant = "outline"
58
- Icon = { LuPencil }
59
- onClick = { ( ) =>
60
- navigate ( {
61
- to : '/application/$applicationId/edit' ,
62
- params : {
63
- applicationId,
64
- } ,
65
- } )
66
- }
67
- />
76
+ < >
77
+ < Button
78
+ size = "icon"
79
+ variant = "outline"
80
+ Icon = { LuPencil }
81
+ onClick = { ( ) =>
82
+ navigate ( {
83
+ to : '/application/$applicationId/edit' ,
84
+ params : {
85
+ applicationId,
86
+ } ,
87
+ } )
88
+ }
89
+ />
90
+ < AlertConfirm
91
+ title = { t ( 'Delete Application' ) + ' ' + application . name }
92
+ description = { t (
93
+ 'Are you sure you want to delete this application? This action cannot be undone.'
94
+ ) }
95
+ onConfirm = { handleDeleteApplication }
96
+ >
97
+ < Button size = "icon" variant = "outline" Icon = { LuTrash } />
98
+ </ AlertConfirm >
99
+ </ >
68
100
) }
69
101
</ div >
70
102
}
0 commit comments