1
- import React from "react"
1
+ import React , { useState } from "react"
2
2
import NextLink from "next/link"
3
3
import { BiInfoCircle } from "@react-icons/all-files/bi/BiInfoCircle"
4
4
import { BsSearch } from "@react-icons/all-files/bs/BsSearch"
@@ -18,6 +18,15 @@ import {
18
18
Tab ,
19
19
TabPanels ,
20
20
TabPanel ,
21
+ Button ,
22
+ useDisclosure ,
23
+ AlertDialog ,
24
+ AlertDialogOverlay ,
25
+ AlertDialogContent ,
26
+ AlertDialogHeader ,
27
+ AlertDialogBody ,
28
+ AlertDialogFooter ,
29
+ useToast ,
21
30
} from "@chakra-ui/react"
22
31
import { useRouter } from "next/router"
23
32
import { SectionHeader } from "components/utils/Card"
@@ -33,6 +42,8 @@ import TraceList from "./TraceList"
33
42
import { AlertTab } from "./AlertTab"
34
43
import EndpointOverview from "./Overview"
35
44
import TestList from "./TestList"
45
+ import { deleteEndpoint } from "api/endpoints"
46
+ import { makeToast } from "utils"
36
47
37
48
interface EndpointPageProps {
38
49
endpoint : ApiEndpointDetailed
@@ -49,6 +60,10 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
49
60
"rgb(179, 181, 185)" ,
50
61
"rgb(91, 94, 109)" ,
51
62
)
63
+ const [ deleting , setDeleting ] = useState < boolean > ( false )
64
+ const { isOpen, onOpen, onClose } = useDisclosure ( )
65
+ const cancelRef = React . useRef ( )
66
+ const toast = useToast ( )
52
67
const { tab, uuid } = router . query
53
68
const getDefaultTab = ( ) => {
54
69
switch ( tab ) {
@@ -67,6 +82,27 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
67
82
}
68
83
}
69
84
85
+ const handleEndpointDelete = async ( ) => {
86
+ try {
87
+ setDeleting ( true )
88
+ await deleteEndpoint ( endpoint . uuid )
89
+ router . push ( "/endpoints" )
90
+ } catch ( err ) {
91
+ toast (
92
+ makeToast (
93
+ {
94
+ title : "Deleting endpoint failed..." ,
95
+ status : "error" ,
96
+ description : err . response ?. data ,
97
+ } ,
98
+ err . response ?. status ,
99
+ ) ,
100
+ )
101
+ } finally {
102
+ setDeleting ( false )
103
+ }
104
+ }
105
+
70
106
return (
71
107
< VStack
72
108
w = "full"
@@ -75,25 +111,32 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
75
111
h = "100vh"
76
112
overflow = "hidden"
77
113
>
78
- < VStack alignItems = "flex-start" pt = "6" px = "6" >
79
- < NextLink href = "/endpoints" >
80
- < HStack color = { headerColor } spacing = "1" cursor = "pointer" >
81
- < TiFlowSwitch />
82
- < Text fontWeight = "semibold" > Endpoints</ Text >
83
- </ HStack >
84
- </ NextLink >
85
- < HStack spacing = "4" pb = "6" >
86
- < Badge
87
- fontSize = "xl"
88
- px = "2"
89
- py = "1"
90
- colorScheme = { METHOD_TO_COLOR [ endpoint ?. method ] || "gray" }
91
- >
92
- { endpoint ?. method . toUpperCase ( ) }
93
- </ Badge >
94
- < Code fontSize = "xl" fontWeight = "semibold" p = "1" >
95
- { endpoint . path }
96
- </ Code >
114
+ < VStack w = "full" alignItems = "flex-start" pt = "6" px = "6" >
115
+ < HStack w = "full" justifyContent = "space-between" >
116
+ < VStack alignItems = "flex-start" >
117
+ < NextLink href = "/endpoints" >
118
+ < HStack color = { headerColor } spacing = "1" cursor = "pointer" >
119
+ < TiFlowSwitch />
120
+ < Text fontWeight = "semibold" > Endpoints</ Text >
121
+ </ HStack >
122
+ </ NextLink >
123
+ < HStack spacing = "4" pb = "6" >
124
+ < Badge
125
+ fontSize = "xl"
126
+ px = "2"
127
+ py = "1"
128
+ colorScheme = { METHOD_TO_COLOR [ endpoint ?. method ] || "gray" }
129
+ >
130
+ { endpoint ?. method . toUpperCase ( ) }
131
+ </ Badge >
132
+ < Code fontSize = "xl" fontWeight = "semibold" p = "1" >
133
+ { endpoint . path }
134
+ </ Code >
135
+ </ HStack >
136
+ </ VStack >
137
+ < Button colorScheme = "red" isLoading = { deleting } onClick = { onOpen } >
138
+ Delete
139
+ </ Button >
97
140
</ HStack >
98
141
</ VStack >
99
142
< Tabs
@@ -148,6 +191,37 @@ const EndpointPage: React.FC<EndpointPageProps> = React.memo(
148
191
</ TabPanel >
149
192
</ TabPanels >
150
193
</ Tabs >
194
+ < AlertDialog
195
+ isOpen = { isOpen }
196
+ leastDestructiveRef = { cancelRef }
197
+ onClose = { onClose }
198
+ >
199
+ < AlertDialogOverlay >
200
+ < AlertDialogContent >
201
+ < AlertDialogHeader fontSize = "lg" fontWeight = "bold" >
202
+ Delete Endpoint
203
+ </ AlertDialogHeader >
204
+
205
+ < AlertDialogBody >
206
+ Are you sure you want to delete this endpoint?
207
+ </ AlertDialogBody >
208
+
209
+ < AlertDialogFooter >
210
+ < Button ref = { cancelRef } onClick = { onClose } >
211
+ Cancel
212
+ </ Button >
213
+ < Button
214
+ isLoading = { deleting }
215
+ colorScheme = "red"
216
+ onClick = { handleEndpointDelete }
217
+ ml = { 3 }
218
+ >
219
+ Delete
220
+ </ Button >
221
+ </ AlertDialogFooter >
222
+ </ AlertDialogContent >
223
+ </ AlertDialogOverlay >
224
+ </ AlertDialog >
151
225
</ VStack >
152
226
)
153
227
} ,
0 commit comments