1
1
import React , { useState } from 'react'
2
2
import { CButton , CCallout , CCol , CForm , CRow , CSpinner , CTooltip } from '@coreui/react'
3
3
import { useSelector } from 'react-redux'
4
- import { Field , Form } from 'react-final-form'
4
+ import { Field , Form , FormSpy } from 'react-final-form'
5
5
import { RFFCFormSwitch } from 'src/components/forms'
6
6
import {
7
7
useGenericGetRequestQuery ,
@@ -25,8 +25,18 @@ const alertsList = [
25
25
'Alert on tenants without a Conditional Access policy, while having Conditional Access licensing available.' ,
26
26
} ,
27
27
{ name : 'AdminPassword' , label : 'Alert on changed admin Passwords' } ,
28
- { name : 'QuotaUsed' , label : 'Alert on 90% mailbox quota used' } ,
29
- { name : 'SharePointQuota' , label : 'Alert on 90% SharePoint quota used' } ,
28
+ {
29
+ name : 'QuotaUsed' ,
30
+ label : 'Alert on % mailbox quota used' ,
31
+ requiresInput : true ,
32
+ inputLabel : 'Enter quota percentage' ,
33
+ } ,
34
+ {
35
+ name : 'SharePointQuota' ,
36
+ label : 'Alert on % SharePoint quota used' ,
37
+ requiresInput : true ,
38
+ inputLabel : 'Enter quota percentage' ,
39
+ } ,
30
40
{ name : 'ExpiringLicenses' , label : 'Alert on licenses expiring in 30 days' } ,
31
41
{ name : 'SecDefaultsUpsell' , label : 'Alert on Security Defaults automatic enablement' } ,
32
42
{
@@ -121,7 +131,7 @@ const ListClassicAlerts = () => {
121
131
const [ genericPostRequest , postResults ] = useLazyGenericPostRequestQuery ( )
122
132
const onSubmit = ( values ) => {
123
133
Object . keys ( values ) . filter ( function ( x ) {
124
- if ( values [ x ] === null ) {
134
+ if ( values [ x ] === null || values [ x ] === 0 ) {
125
135
delete values [ x ]
126
136
}
127
137
return null
@@ -201,11 +211,27 @@ const ListClassicAlerts = () => {
201
211
< hr />
202
212
{ alertsList . map ( ( alert , index ) => (
203
213
< CCol key = { alert . name } md = "6" >
204
- < RFFCFormSwitch
205
- name = { alert . name }
206
- label = { alert . label }
207
- sublabel = { getLabel ( alert . name ) }
208
- />
214
+ < RFFCFormSwitch name = { alert . name } label = { alert . label } />
215
+ { alert . requiresInput && (
216
+ < FormSpy subscription = { { values : true } } >
217
+ { ( { values } ) => {
218
+ // Check if the switch for this alert is turned on before showing the input
219
+ if ( values [ alert . name ] ) {
220
+ return (
221
+ < Field
222
+ name = { `${ alert . name } Quota` } // Unique name for the input field
223
+ component = "input"
224
+ type = "number"
225
+ placeholder = { alert . inputLabel }
226
+ initialValue = { alert . defaultValue } // Set the initial value
227
+ parse = { ( value ) => Number ( value ) } // Ensure value is a number
228
+ />
229
+ )
230
+ }
231
+ return null
232
+ } }
233
+ </ FormSpy >
234
+ ) }
209
235
</ CCol >
210
236
) ) }
211
237
</ CRow >
0 commit comments