1
- import { useEffect , useMemo } from 'react' ;
1
+ import { useCallback , useEffect , useMemo } from 'react' ;
2
2
import styled from '@emotion/styled' ;
3
3
4
4
import { fetchOrgMembers } from 'sentry/actionCreators/members' ;
@@ -22,8 +22,11 @@ import {FILTER_MATCH_OPTIONS} from 'sentry/views/automations/components/actionFi
22
22
import ActionNodeList from 'sentry/views/automations/components/actionNodeList' ;
23
23
import { AutomationBuilderConflictContext } from 'sentry/views/automations/components/automationBuilderConflictContext' ;
24
24
import { useAutomationBuilderContext } from 'sentry/views/automations/components/automationBuilderContext' ;
25
+ import { useAutomationBuilderErrorContext } from 'sentry/views/automations/components/automationBuilderErrorContext' ;
26
+ import { validateActions } from 'sentry/views/automations/components/automationFormData' ;
25
27
import DataConditionNodeList from 'sentry/views/automations/components/dataConditionNodeList' ;
26
28
import { TRIGGER_MATCH_OPTIONS } from 'sentry/views/automations/components/triggers/constants' ;
29
+ import { useSendTestNotification } from 'sentry/views/automations/hooks' ;
27
30
import { findConflictingConditions } from 'sentry/views/automations/hooks/utils' ;
28
31
29
32
export default function AutomationBuilder ( ) {
@@ -114,6 +117,26 @@ interface ActionFilterBlockProps {
114
117
115
118
function ActionFilterBlock ( { actionFilter} : ActionFilterBlockProps ) {
116
119
const { actions} = useAutomationBuilderContext ( ) ;
120
+ const { mutateAsync : sendTestNotification } = useSendTestNotification ( ) ;
121
+ const { errors, setErrors} = useAutomationBuilderErrorContext ( ) ;
122
+
123
+ const handleSendTestNotification = useCallback ( async ( ) => {
124
+ const actionFilterActions = actionFilter . actions || [ ] ;
125
+
126
+ // Validate actions before sending test notification
127
+ const actionErrors = validateActions ( { actions : actionFilterActions } ) ;
128
+ setErrors ( { ...errors , ...actionErrors } ) ;
129
+
130
+ // Only send test notification if there are no validation errors
131
+ if ( Object . keys ( actionErrors ) . length === 0 ) {
132
+ await sendTestNotification (
133
+ actionFilterActions . map ( action => {
134
+ const { id : _id , ...actionWithoutId } = action ;
135
+ return actionWithoutId ;
136
+ } )
137
+ ) ;
138
+ }
139
+ } , [ actionFilter . actions , sendTestNotification , errors , setErrors ] ) ;
117
140
118
141
return (
119
142
< IfThenWrapper >
@@ -188,7 +211,13 @@ function ActionFilterBlock({actionFilter}: ActionFilterBlockProps) {
188
211
/>
189
212
</ Step >
190
213
< span >
191
- < Button icon = { < IconMail /> } > { t ( 'Send Test Notification' ) } </ Button >
214
+ < Button
215
+ icon = { < IconMail /> }
216
+ onClick = { handleSendTestNotification }
217
+ disabled = { ! actionFilter . actions ?. length }
218
+ >
219
+ { t ( 'Send Test Notification' ) }
220
+ </ Button >
192
221
</ span >
193
222
</ IfThenWrapper >
194
223
) ;
0 commit comments