@@ -174,46 +174,67 @@ function FileTemplate({ match, selectedAsset = {}, displayingInModal, onClose })
174
174
setMonitoringDetails ( ( prev ) => ( { ...prev , landingZonePath } ) ) ;
175
175
} ;
176
176
177
+ const validateForms = async ( ) => {
178
+ let validationError = null ;
179
+ let formData = { } ;
180
+
181
+ try {
182
+ formData = await form . validateFields ( ) ;
183
+ } catch ( err ) {
184
+ validationError = err ;
185
+ }
186
+
187
+ return { validationError, formData } ;
188
+ } ;
189
+
177
190
//Save file template
178
191
const saveFileTemplate = async ( ) => {
179
- await form . validateFields ( ) ;
180
- const {
181
- title,
182
- cluster,
183
- fileNamePattern,
184
- searchString,
185
- description,
186
- setFileMonitoring,
187
- landingZone,
188
- machine,
189
- dirToMonitor,
190
- shouldMonitorSubDirs,
191
- } = form . getFieldsValue ( ) ;
192
- const url = `/api/fileTemplate/read/saveFileTemplate` ;
193
- const body = JSON . stringify ( {
194
- title,
195
- assetId,
196
- groupId,
197
- cluster,
198
- description,
199
- searchString,
200
- fileNamePattern,
201
- fileLayoutData : layoutData ,
202
- application_id : applicationId ,
203
- sampleLayoutFile : sampleFileForLayout ,
204
- metaData : {
205
- isAssociated : true ,
206
- fileMonitoringTemplate : setFileMonitoring ,
192
+ try {
193
+ const data = await validateForms ( ) ;
194
+
195
+ if ( data . validationError ?. errorFields ) {
196
+ throw new Error ( 'Validation failed, please check form fields again.' ) ;
197
+ }
198
+
199
+ const {
200
+ title,
201
+ cluster,
202
+ fileNamePattern,
203
+ searchString,
204
+ description,
205
+ setFileMonitoring,
207
206
landingZone,
208
207
machine,
209
- lzPath : landingZoneMonitoringDetails . landingZonePath ,
210
- directory : dirToMonitor ,
211
- monitorSubDirs : shouldMonitorSubDirs ,
212
- licenses : selectedLicenses ,
213
- } ,
214
- } ) ;
215
- try {
208
+ dirToMonitor,
209
+ shouldMonitorSubDirs,
210
+ } = form . getFieldsValue ( ) ;
211
+
212
+ const url = `/api/fileTemplate/read/saveFileTemplate` ;
213
+ const body = JSON . stringify ( {
214
+ title,
215
+ assetId,
216
+ groupId,
217
+ cluster,
218
+ description,
219
+ searchString,
220
+ fileNamePattern,
221
+ fileLayoutData : layoutData ,
222
+ application_id : applicationId ,
223
+ sampleLayoutFile : sampleFileForLayout ,
224
+ metaData : {
225
+ isAssociated : true ,
226
+ fileMonitoringTemplate : setFileMonitoring ,
227
+ landingZone,
228
+ machine,
229
+ lzPath : landingZoneMonitoringDetails . landingZonePath ,
230
+ directory : dirToMonitor ,
231
+ monitorSubDirs : shouldMonitorSubDirs ,
232
+ licenses : selectedLicenses ,
233
+ } ,
234
+ } ) ;
235
+
216
236
const response = await fetch ( url , { headers : authHeader ( ) , method : 'POST' , body } ) ;
237
+
217
238
if ( ! response . ok ) throw Error ( 'Unable to save template' ) ;
218
239
message . success ( 'Template Saved' ) ;
219
240
@@ -231,6 +252,7 @@ function FileTemplate({ match, selectedAsset = {}, displayingInModal, onClose })
231
252
history . push ( `/${ application . applicationId } /assets` ) ;
232
253
}
233
254
} catch ( err ) {
255
+ console . log ( err ) ;
234
256
message . error ( err . message ) ;
235
257
}
236
258
} ;
0 commit comments