@@ -14,6 +14,7 @@ import type {
1414 Directive ,
1515 IncidentAgentEvent
1616} from "../../../redux/services/types" ;
17+ import { CancelConfirmation } from "../../common/CancelConfirmation" ;
1718import { SortIcon } from "../../common/icons/16px/SortIcon" ;
1819import { TrashBinIcon } from "../../common/icons/16px/TrashBinIcon" ;
1920import { Direction } from "../../common/icons/types" ;
@@ -52,6 +53,7 @@ const mockData: Directive[] = [
5253] ;
5354
5455// TODO: remove
56+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5557const mockEventsData : IncidentAgentEvent [ ] = [
5658 {
5759 agent_name : "incident_entry" ,
@@ -105,15 +107,23 @@ const mockEventsData: IncidentAgentEvent[] = [
105107 }
106108] ;
107109
110+ const REFRESH_INTERVAL = 10 * 1000 ; // in milliseconds
111+
108112const columnHelper = createColumnHelper < ExtendedDirective > ( ) ;
109113
110114export const IncidentDirectives = ( ) => {
111115 const [ searchInputValue , setSearchInputValue ] = useState ( "" ) ;
112116 const [ selectedConditions , setSelectedConditions ] = useState < string [ ] > ( [ ] ) ;
117+ const [ directiveToDelete , setDirectiveToDelete ] = useState < string > ( ) ;
113118
114- const { data } = useGetIncidentAgentDirectivesQuery ( {
115- search_term : searchInputValue
116- } ) ;
119+ const { data } = useGetIncidentAgentDirectivesQuery (
120+ {
121+ search_term : searchInputValue || undefined
122+ } ,
123+ {
124+ pollingInterval : REFRESH_INTERVAL
125+ }
126+ ) ;
117127
118128 const [ deleteIncidentAgentDirective ] =
119129 useDeleteIncidentAgentDirectiveMutation ( ) ;
@@ -128,6 +138,19 @@ export const IncidentDirectives = () => {
128138 ) ;
129139 } ;
130140
141+ const handleDeleteDirectiveDialogConfirm = ( ) => {
142+ if ( directiveToDelete ) {
143+ void deleteIncidentAgentDirective ( {
144+ id : directiveToDelete
145+ } ) ;
146+ }
147+ setDirectiveToDelete ( undefined ) ;
148+ } ;
149+
150+ const handleDeleteDirectiveDialogClose = ( ) => {
151+ setDirectiveToDelete ( undefined ) ;
152+ } ;
153+
131154 const handleMessageSend = ( ) => {
132155 // TODO: implement
133156 } ;
@@ -254,9 +277,7 @@ export const IncidentDirectives = () => {
254277 const value = info . getValue ( ) ;
255278
256279 const handleDeleteMenuItemClick = ( ) => {
257- void deleteIncidentAgentDirective ( {
258- id : value . id
259- } ) ;
280+ setDirectiveToDelete ( value . id ) ;
260281 } ;
261282
262283 const items : MenuItem [ ] = [
@@ -376,8 +397,7 @@ export const IncidentDirectives = () => {
376397 </ s . Table >
377398 </ s . TableContainer >
378399 < s . StyledAgentChat
379- // TODO: remove mock data
380- data = { mockEventsData }
400+ data = { [ ] }
381401 isDataLoading = { false }
382402 onMessageSend = { handleMessageSend }
383403 isMessageSending = { false }
@@ -396,6 +416,16 @@ export const IncidentDirectives = () => {
396416 )
397417 }
398418 />
419+ { directiveToDelete && (
420+ < s . StyledOverlay >
421+ < CancelConfirmation
422+ header = { "Delete directive" }
423+ description = { "Are you sure you want to delete this directive?" }
424+ onClose = { handleDeleteDirectiveDialogClose }
425+ onConfirm = { handleDeleteDirectiveDialogConfirm }
426+ />
427+ </ s . StyledOverlay >
428+ ) }
399429 </ s . Container >
400430 ) ;
401431} ;
0 commit comments