@@ -29,7 +29,7 @@ import {
29
29
NotificationEndpointsList ,
30
30
TransformedEndpointItem ,
31
31
} from "./types" ;
32
- import { notificationTransform } from "./utils" ;
32
+ import { getNotificationConfigKey , notificationTransform } from "./utils" ;
33
33
import { AddIcon , LambdaIcon } from "../../../icons" ;
34
34
import TableWrapper from "../Common/TableWrapper/TableWrapper" ;
35
35
@@ -49,8 +49,12 @@ import PageLayout from "../Common/Layout/PageLayout";
49
49
import SearchBox from "../Common/SearchBox" ;
50
50
import RBIconButton from "../Buckets/BucketDetails/SummaryItems/RBIconButton" ;
51
51
import { IAM_PAGES } from "../../../common/SecureComponent/permissions" ;
52
- import { setErrorSnackMessage } from "../../../systemSlice" ;
52
+ import {
53
+ setErrorSnackMessage ,
54
+ setServerNeedsRestart ,
55
+ } from "../../../systemSlice" ;
53
56
import { useAppDispatch } from "../../../store" ;
57
+ import ConfirmDeleteTargetModal from "./ConfirmDeleteTargetModal" ;
54
58
55
59
interface IListNotificationEndpoints {
56
60
classes : any ;
@@ -88,6 +92,10 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
88
92
const [ filter , setFilter ] = useState < string > ( "" ) ;
89
93
const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
90
94
95
+ const [ isDelConfirmOpen , setIsDelConfirmOpen ] = useState < boolean > ( false ) ;
96
+ const [ selNotifyEndPoint , setSelNotifyEndpoint ] =
97
+ useState < TransformedEndpointItem | null > ( ) ;
98
+
91
99
//Effects
92
100
// load records on mount
93
101
useEffect ( ( ) => {
@@ -116,6 +124,39 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
116
124
setIsLoading ( true ) ;
117
125
} , [ ] ) ;
118
126
127
+ const resetNotificationConfig = (
128
+ ep : TransformedEndpointItem | undefined | null
129
+ ) => {
130
+ if ( ep ?. name ) {
131
+ const configKey = getNotificationConfigKey ( ep . name ) ;
132
+ let accountId = `:${ ep . account_id } ` ;
133
+ if ( configKey ) {
134
+ api
135
+ . invoke ( "POST" , `/api/v1/configs/${ configKey } ${ accountId } /reset` )
136
+ . then ( ( res ) => {
137
+ dispatch ( setServerNeedsRestart ( true ) ) ;
138
+ setSelNotifyEndpoint ( null ) ;
139
+ setIsDelConfirmOpen ( false ) ;
140
+ } )
141
+ . catch ( ( err : ErrorResponseHandler ) => {
142
+ setIsDelConfirmOpen ( false ) ;
143
+ dispatch ( setErrorSnackMessage ( err ) ) ;
144
+ } ) ;
145
+ } else {
146
+ setSelNotifyEndpoint ( null ) ;
147
+ setIsDelConfirmOpen ( false ) ;
148
+ console . log ( `Unable to find Config key for ${ ep . name } ` ) ;
149
+ }
150
+ }
151
+ } ;
152
+
153
+ const confirmDelNotifyEndpoint = ( record : TransformedEndpointItem ) => {
154
+ setSelNotifyEndpoint ( record ) ;
155
+ setIsDelConfirmOpen ( true ) ;
156
+ } ;
157
+
158
+ const tableActions = [ { type : "delete" , onClick : confirmDelNotifyEndpoint } ] ;
159
+
119
160
const filteredRecords = records . filter ( ( b : TransformedEndpointItem ) => {
120
161
if ( filter === "" ) {
121
162
return true ;
@@ -180,7 +221,7 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
180
221
< Fragment >
181
222
< Grid item xs = { 12 } className = { classes . tableBlock } >
182
223
< TableWrapper
183
- itemActions = { [ ] }
224
+ itemActions = { tableActions }
184
225
columns = { [
185
226
{
186
227
label : "Status" ,
@@ -262,6 +303,19 @@ const ListNotificationEndpoints = ({ classes }: IListNotificationEndpoints) => {
262
303
) }
263
304
</ Fragment >
264
305
) }
306
+
307
+ { isDelConfirmOpen ? (
308
+ < ConfirmDeleteTargetModal
309
+ onConfirm = { ( ) => {
310
+ resetNotificationConfig ( selNotifyEndPoint ) ;
311
+ } }
312
+ status = { `${ selNotifyEndPoint ?. status } ` }
313
+ serviceName = { `${ selNotifyEndPoint ?. service_name } ` }
314
+ onClose = { ( ) => {
315
+ setIsDelConfirmOpen ( false ) ;
316
+ } }
317
+ />
318
+ ) : null }
265
319
</ PageLayout >
266
320
</ Fragment >
267
321
) ;
0 commit comments