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,62 @@ 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 "
181
+ label = "Configuration name"
180
182
data-testid = "add-smtp-configuration-name"
181
183
ref = { ( node ) => ( this . _configName = node ) }
182
- className = "form__input"
183
- type = "text"
184
- name = "configName"
185
184
value = { this . state . form . configName }
186
185
onChange = { this . handleInputChange }
187
- onBlur = { this . handleBlur }
186
+ handleOnBlur = { this . handleBlur }
188
187
placeholder = "Configuration name"
189
188
autoFocus = { true }
190
189
tabIndex = { 1 }
191
- required
190
+ isRequiredField = { true }
191
+ error = { ! this . state . isValid . configName && REQUIRED_FIELD_MSG }
192
192
/>
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
193
</ label >
202
194
< label className = "form__row" >
203
- < span className = "form__label" > SMTP Host*</ span >
204
- < input
195
+ < CustomInput
205
196
data-testid = "add-smtp-host"
206
- className = "form__input"
207
- type = "text"
197
+ label = "SMTP Host"
208
198
name = "host"
209
199
value = { this . state . form . host }
210
200
onChange = { this . handleInputChange }
211
- onBlur = { this . handleBlur }
201
+ handleOnBlur = { this . handleBlur }
212
202
placeholder = "Eg. smtp.gmail.com"
213
203
tabIndex = { 2 }
214
- required
204
+ isRequiredField = { true }
205
+ error = { ! this . state . isValid . host && REQUIRED_FIELD_MSG }
215
206
/>
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
207
</ label >
225
208
< label className = "form__row" >
226
- < span className = "form__label" > SMTP Port* </ span >
227
- < input
209
+ < CustomInput
210
+ label = "SMTP Port"
228
211
data-testid = "add-smtp-port"
229
- className = "form__input"
230
- type = "text"
231
212
name = "port"
232
213
value = { this . state . form . port }
233
214
onChange = { this . handleInputChange }
234
- onBlur = { this . handleBlur }
215
+ handleOnBlur = { this . handleBlur }
235
216
placeholder = "Enter SMTP port"
236
217
tabIndex = { 3 }
237
- required
218
+ isRequiredField = { true }
219
+ error = { ! this . state . isValid . port && REQUIRED_FIELD_MSG }
238
220
/>
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
221
</ label >
248
222
< div className = "form__row" >
249
- < label htmlFor = "" className = "form__label" >
250
- SMTP Username*
251
- </ label >
252
- < input
223
+ < CustomInput
224
+ label = "SMTP Username"
253
225
data-testid = "add-smtp-username"
254
- className = "form__input"
255
- type = "text"
256
226
name = "authUser"
257
227
value = { this . state . form . authUser }
258
228
onChange = { this . handleInputChange }
259
- onBlur = { this . handleBlur }
229
+ handleOnBlur = { this . handleBlur }
260
230
placeholder = "Enter SMTP username"
261
231
tabIndex = { 3 }
262
- required
232
+ isRequiredField = { true }
233
+ error = { ! this . state . isValid . authUser && REQUIRED_FIELD_MSG }
263
234
/>
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
235
</ div >
273
236
< div className = "form__row smtp-protected-input" >
274
237
< ProtectedInput
@@ -283,28 +246,19 @@ export class SMTPConfigModal extends Component<SMTPConfigModalProps, SMTPConfigM
283
246
/>
284
247
</ div >
285
248
< label className = "form__row" >
286
- < span className = "form__label" > Send email from* </ span >
287
- < input
249
+ < CustomInput
250
+ label = "Send email from"
288
251
data-testid = "add-smtp-send-email"
289
- className = "form__input"
290
252
type = "email"
291
253
name = "fromEmail"
292
254
value = { this . state . form . fromEmail }
293
255
onChange = { this . handleInputChange }
294
- onBlur = { this . handleBlur }
256
+ handleOnBlur = { this . handleBlur }
295
257
placeholder = "Email"
296
258
tabIndex = { 5 }
297
- required
259
+ isRequiredField = { true }
260
+ error = { ! this . state . isValid . fromEmail && REQUIRED_FIELD_MSG }
298
261
/>
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
262
</ label >
309
263
</ div >
310
264
< div className = "form__button-group-bottom flexbox flex-justify" >
0 commit comments