1
1
import React , { Component } from 'react'
2
2
import { validateEmail } from '../common'
3
- import { showError , Progressing , Checkbox , Drawer } from '@devtron-labs/devtron-fe-common-lib'
3
+ import { showError , Progressing , Checkbox , Drawer , CustomInput } from '@devtron-labs/devtron-fe-common-lib'
4
4
import { getSMTPConfiguration , saveEmailConfiguration } from './notifications.service'
5
5
import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
6
6
import { ReactComponent as Error } from '../../assets/icons/ic-warning.svg'
7
7
import { toast } from 'react-toastify'
8
8
import { ViewType } from '../../config/constants'
9
9
import { ProtectedInput } from '../globalConfigurations/GlobalConfiguration'
10
10
import { SMTPConfigModalProps , SMTPConfigModalState } from './types'
11
+ import { REQUIRED_FIELD_MSG } from '../../config/constantMessaging'
11
12
12
13
export class SMTPConfigModal extends Component < SMTPConfigModalProps , SMTPConfigModalState > {
13
14
_configName
@@ -175,100 +176,64 @@ export class SMTPConfigModal extends Component<SMTPConfigModalProps, SMTPConfigM
175
176
< >
176
177
< div className = "m-20" style = { { height : 'calc(100vh - 160px' } } >
177
178
< label className = "form__row" >
178
- < span className = "form__label" > Configuration Name* </ span >
179
- < input
179
+ < CustomInput
180
+ name = "configName "
180
181
data-testid = "add-smtp-configuration-name"
181
182
ref = { ( node ) => ( this . _configName = node ) }
182
- className = "form__input"
183
- type = "text"
184
- name = "configName"
185
183
value = { this . state . form . configName }
186
184
onChange = { this . handleInputChange }
187
- onBlur = { this . handleBlur }
185
+ handleOnBlur = { this . handleBlur }
188
186
placeholder = "Configuration name"
189
187
autoFocus = { true }
190
188
tabIndex = { 1 }
191
- required
189
+ isRequiredField = { true }
190
+ error = { ! this . state . isValid . configName && REQUIRED_FIELD_MSG }
192
191
/>
193
- < span className = "form__error" >
194
- { ! this . state . isValid . configName ? (
195
- < >
196
- < Error className = "form__icon form__icon--error" />
197
- This is a required field < br />
198
- </ >
199
- ) : null }
200
- </ span >
201
192
</ label >
202
193
< label className = "form__row" >
203
- < span className = "form__label" > SMTP Host*</ span >
204
- < input
194
+ < CustomInput
205
195
data-testid = "add-smtp-host"
206
- className = "form__input"
207
- type = "text"
196
+ label = "SMTP Host"
208
197
name = "host"
209
198
value = { this . state . form . host }
210
199
onChange = { this . handleInputChange }
211
- onBlur = { this . handleBlur }
200
+ handleOnBlur = { this . handleBlur }
212
201
placeholder = "Eg. smtp.gmail.com"
213
202
tabIndex = { 2 }
214
- required
203
+ isRequiredField = { true }
204
+ error = { ! this . state . isValid . host && REQUIRED_FIELD_MSG }
215
205
/>
216
- < span className = "form__error" >
217
- { ! this . state . isValid . host ? (
218
- < >
219
- < Error className = "form__icon form__icon--error" />
220
- This is a required field < br />
221
- </ >
222
- ) : null }
223
- </ span >
224
206
</ label >
225
207
< label className = "form__row" >
226
- < span className = "form__label" > SMTP Port* </ span >
227
- < input
208
+ < CustomInput
209
+ label = "SMTP Port"
228
210
data-testid = "add-smtp-port"
229
- className = "form__input"
230
- type = "text"
231
211
name = "port"
232
212
value = { this . state . form . port }
233
213
onChange = { this . handleInputChange }
234
- onBlur = { this . handleBlur }
214
+ handleOnBlur = { this . handleBlur }
235
215
placeholder = "Enter SMTP port"
236
216
tabIndex = { 3 }
237
- required
217
+ isRequiredField = { true }
218
+ error = { ! this . state . isValid . port && REQUIRED_FIELD_MSG }
238
219
/>
239
- < span className = "form__error" >
240
- { ! this . state . isValid . port ? (
241
- < >
242
- < Error className = "form__icon form__icon--error" />
243
- This is a required field < br />
244
- </ >
245
- ) : null }
246
- </ span >
247
220
</ label >
248
221
< div className = "form__row" >
249
222
< label htmlFor = "" className = "form__label" >
250
223
SMTP Username*
251
224
</ label >
252
- < input
225
+ < CustomInput
226
+ label = "SMTP Username"
253
227
data-testid = "add-smtp-username"
254
- className = "form__input"
255
- type = "text"
256
228
name = "authUser"
257
229
value = { this . state . form . authUser }
258
230
onChange = { this . handleInputChange }
259
- onBlur = { this . handleBlur }
231
+ handleOnBlur = { this . handleBlur }
260
232
placeholder = "Enter SMTP username"
261
233
tabIndex = { 3 }
262
- required
234
+ isRequiredField = { true }
235
+ error = { ! this . state . isValid . authUser && REQUIRED_FIELD_MSG }
263
236
/>
264
- < span className = "form__error" >
265
- { ! this . state . isValid . authUser ? (
266
- < >
267
- < Error className = "form__icon form__icon--error" />
268
- This is a required field < br />
269
- </ >
270
- ) : null }
271
- </ span >
272
237
</ div >
273
238
< div className = "form__row smtp-protected-input" >
274
239
< ProtectedInput
@@ -284,27 +249,18 @@ export class SMTPConfigModal extends Component<SMTPConfigModalProps, SMTPConfigM
284
249
</ div >
285
250
< label className = "form__row" >
286
251
< span className = "form__label" > Send email from*</ span >
287
- < input
252
+ < CustomInput
288
253
data-testid = "add-smtp-send-email"
289
- className = "form__input"
290
254
type = "email"
291
255
name = "fromEmail"
292
256
value = { this . state . form . fromEmail }
293
257
onChange = { this . handleInputChange }
294
- onBlur = { this . handleBlur }
258
+ handleOnBlur = { this . handleBlur }
295
259
placeholder = "Email"
296
260
tabIndex = { 5 }
297
- required
261
+ isRequiredField = { true }
262
+ error = { ! this . state . isValid . fromEmail && REQUIRED_FIELD_MSG }
298
263
/>
299
- < span className = "form__error" >
300
- { ! this . state . isValid . fromEmail ? (
301
- < >
302
- < Error className = "form__icon form__icon--error" />
303
- This is a required field
304
- < br />
305
- </ >
306
- ) : null }
307
- </ span >
308
264
</ label >
309
265
</ div >
310
266
< div className = "form__button-group-bottom flexbox flex-justify" >
0 commit comments