1- import { Dialog , DialogProps } from '@mui/material' ;
1+ import React , { useContext , useEffect } from 'react' ;
2+
23import {
34 AlertRuleConfigSchema ,
45 useCreateAlertRuleApiV1MonitorsMonitorIdAlertRulesPost ,
@@ -8,11 +9,17 @@ import {
89 useUpdateAlertApiV1AlertRulesAlertRuleIdPut ,
910 useUpdateMonitorApiV1MonitorsMonitorIdPut
1011} from 'api/generated' ;
11- import { Loader } from 'components/Loader' ;
12- import React , { useContext , useEffect } from 'react' ;
13- import { AlertRuleDialogContent } from './AlertRuleDialogContent' ;
12+
13+ import { AlertRuleDialogContent } from './components/AlertRuleDialogContent' ;
1414import { AlertRuleDialogContext } from './AlertRuleDialogContext' ;
15- import { DialogTopBar } from './DialogTopBar' ;
15+
16+ import { DialogProps } from '@mui/material' ;
17+
18+ import { ActionDialogHeader } from 'components/base/Dialog/ActionDialog/ActionDialogHeader' ;
19+ import { Loader } from 'components/Loader' ;
20+
21+ import { StyledDialog } from './AlertRuleDialog.styles' ;
22+ import { constants } from './alertRuleDialog.constants' ;
1623
1724interface AlertRuleDialogProps extends Omit < DialogProps , 'onClose' > {
1825 alertRuleId ?: AlertRuleConfigSchema [ 'id' ] ;
@@ -21,11 +28,14 @@ interface AlertRuleDialogProps extends Omit<DialogProps, 'onClose'> {
2128}
2229
2330export const AlertRuleDialog = ( { alertRuleId = 0 , onClose, startingStep, ...props } : AlertRuleDialogProps ) => {
31+ const { setAlertRule, setMonitor, resetState, monitor, alertRule } = useContext ( AlertRuleDialogContext ) ;
32+
2433 const { data : fetchedAlertRule , isLoading : isAlertRuleLoading } =
2534 useGetAlertRuleApiV1AlertRulesAlertRuleIdGet ( alertRuleId ) ;
2635 const { data : fetchedMonitor , isLoading : isMonitorLoading } = useGetMonitorApiV1MonitorsMonitorIdGet (
2736 fetchedAlertRule ?. monitor_id || 0
2837 ) ;
38+
2939 const { mutateAsync : createMonitor , isLoading : isCreateMonitorLoading } =
3040 useCreateMonitorApiV1ChecksCheckIdMonitorsPost ( ) ;
3141 const { mutateAsync : createAlertRule , isLoading : isCreateAlertRuleLoading } =
@@ -34,40 +44,33 @@ export const AlertRuleDialog = ({ alertRuleId = 0, onClose, startingStep, ...pro
3444 const { mutateAsync : updateMonitor , isLoading : isUpdateMonitorLoading } = useUpdateMonitorApiV1MonitorsMonitorIdPut ( ) ;
3545 const { mutateAsync : updateAlertRule , isLoading : isUpdateAlertRuleLoading } =
3646 useUpdateAlertApiV1AlertRulesAlertRuleIdPut ( ) ;
37- const { setAlertRule, setMonitor, resetState, monitor, alertRule } = useContext ( AlertRuleDialogContext ) ;
3847
3948 useEffect ( ( ) => {
40- if ( fetchedAlertRule ) {
41- setAlertRule ( fetchedAlertRule ) ;
42- }
43- if ( fetchedMonitor ) {
44- setMonitor ( fetchedMonitor ) ;
45- }
46- } , [ fetchedAlertRule , fetchedMonitor , setAlertRule , setMonitor ] ) ;
49+ if ( fetchedAlertRule ) setAlertRule ( fetchedAlertRule ) ;
50+ } , [ fetchedAlertRule , setAlertRule ] ) ;
51+
52+ useEffect ( ( ) => {
53+ if ( fetchedMonitor ) setMonitor ( fetchedMonitor ) ;
54+ } , [ fetchedMonitor , setMonitor ] ) ;
4755
4856 const handleClose = ( ) => {
4957 onClose ( false ) ;
5058 resetState ( ) ;
5159 } ;
5260
5361 const handleComplete = async ( ) => {
54- // Edit mode
5562 if ( alertRuleId !== 0 ) {
5663 const { id : monitorId , ...editedMonitor } = monitor ;
5764
5865 await Promise . all ( [
5966 updateMonitor ( { monitorId, data : editedMonitor } ) ,
6067 updateAlertRule ( { alertRuleId, data : alertRule } )
6168 ] ) ;
62-
63- // trackAddEditRuleSavedSuccessfully(monitor);
6469 } else {
6570 const { check, ...addedMonitor } = monitor ;
6671 const { id : monitorId } = await createMonitor ( { checkId : check . id , data : addedMonitor } ) ;
6772
6873 await createAlertRule ( { monitorId, data : alertRule } ) ;
69-
70- // trackAddEditRuleSavedSuccessfully(monitor);
7174 }
7275
7376 onClose ( true ) ;
@@ -80,23 +83,17 @@ export const AlertRuleDialog = ({ alertRuleId = 0, onClose, startingStep, ...pro
8083 isCreateAlertRuleLoading ||
8184 isUpdateMonitorLoading ||
8285 isUpdateAlertRuleLoading ;
86+
8387 return (
84- < Dialog
85- fullWidth = { true }
86- maxWidth = { false }
87- // TransitionComponent={Transition}
88- onClose = { ( ) => handleClose ( ) }
89- { ...props }
90- sx = { { '& .MuiDialog-paper' : { p : '0 40px' } } }
91- >
88+ < StyledDialog onClose = { handleClose } { ...props } >
9289 { isLoading ? (
9390 < Loader />
9491 ) : (
9592 < >
96- < DialogTopBar handleClose = { handleClose } />
93+ < ActionDialogHeader title = { constants . dialogHeader ( monitor ?. name ) } onClose = { handleClose } />
9794 < AlertRuleDialogContent startingStep = { startingStep } handleComplete = { handleComplete } />
9895 </ >
9996 ) }
100- </ Dialog >
97+ </ StyledDialog >
10198 ) ;
10299} ;
0 commit comments