@@ -198,9 +198,15 @@ interface ESignetConfig {
198
198
fieldName : string ;
199
199
mosipAPIUserInfoUrl : string ;
200
200
} ;
201
+ loaderFieldName ?: string ;
201
202
}
202
203
203
- export const verified = ( event : string , sectionId : string , mapping : any ) => {
204
+ export const verified = (
205
+ event : string ,
206
+ sectionId : string ,
207
+ mapping : any ,
208
+ esignetConfig ?: ESignetConfig ,
209
+ ) => {
204
210
const fieldName = "verified" ;
205
211
const fieldId = `${ event } .${ sectionId } .${ sectionId } -view-group.${ fieldName } ` ;
206
212
return {
@@ -213,10 +219,15 @@ export const verified = (event: string, sectionId: string, mapping: any) => {
213
219
id : "form.field.label.empty" ,
214
220
defaultMessage : "" ,
215
221
} ,
216
- initialValue : {
217
- dependsOn : [ "idReader" ] ,
218
- expression : 'Boolean($form?.idReader)? "pending":""' ,
219
- } ,
222
+ initialValue : esignetConfig
223
+ ? {
224
+ dependsOn : [ "idReader" , esignetConfig . callback . fieldName ] ,
225
+ expression : `Boolean($form?.idReader)? "pending": Boolean($form?.${ esignetConfig . callback . fieldName } ?.data)? "authenticated": ""` ,
226
+ }
227
+ : {
228
+ dependsOn : [ "idReader" ] ,
229
+ expression : 'Boolean($form?.idReader)? "pending":""' ,
230
+ } ,
220
231
validator : [ ] ,
221
232
mapping,
222
233
} ;
@@ -226,10 +237,12 @@ function capitalize(str: string) {
226
237
return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
227
238
}
228
239
240
+ type VerificationStatus = "verified" | "failed" | "authenticated" ;
241
+
229
242
export const idVerificationBanner = (
230
243
event : string ,
231
244
sectionId : string ,
232
- status : "verified" | "failed" | "authenticated" ,
245
+ status : VerificationStatus ,
233
246
) => {
234
247
const fieldName = "verified" ;
235
248
const fieldId = `${ event } .${ sectionId } .${ sectionId } -view-group.${ fieldName } ` ;
@@ -255,6 +268,41 @@ export const idVerificationBanner = (
255
268
} ;
256
269
} ;
257
270
271
+ export function esignetLoaderField ( {
272
+ event,
273
+ section,
274
+ fieldName,
275
+ esignetCallbackFieldName,
276
+ } : {
277
+ event : "birth" | "death" ;
278
+ section : "informant" | "mother" | "father" | "spouse" | "deceased" ;
279
+ fieldName : string ;
280
+ esignetCallbackFieldName : string ;
281
+ } ) {
282
+ const fieldId = `${ event } .${ section } .${ section } -view-group.${ fieldName } ` ;
283
+ return {
284
+ name : fieldName ,
285
+ type : "LOADER" ,
286
+ fieldId,
287
+ hideInPreview : true ,
288
+ custom : true ,
289
+ label : {
290
+ id : "form.field.label.idReader" ,
291
+ defaultMessage : "ID verification" ,
292
+ } ,
293
+ loadingText : {
294
+ id : "form.field.label.authenticating.nid" ,
295
+ defaultMessage : "Fetching the person's data from E-Signet" ,
296
+ } ,
297
+ conditionals : [
298
+ {
299
+ action : "hide" ,
300
+ expression : `!$form?.${ esignetCallbackFieldName } ?.loading` ,
301
+ } ,
302
+ ] ,
303
+ } ;
304
+ }
305
+
258
306
export const getInitialValueFromIDReader = ( fieldNameInReader : string ) => ( {
259
307
dependsOn : [ "idReader" , "esignetCallback" ] ,
260
308
expression : `$form?.idReader?.${ fieldNameInReader } || $form?.esignetCallback?.data?.${ fieldNameInReader } || ""` ,
@@ -276,7 +324,7 @@ export const idReaderFields = (
276
324
conditionals . concat ( {
277
325
action : "hide" ,
278
326
expression :
279
- "$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed'" ,
327
+ "$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed' || !!$form?.esignetCallback?.loading " ,
280
328
} ) ,
281
329
readers ,
282
330
) ,
@@ -298,6 +346,25 @@ export const idReaderFields = (
298
346
openIdProviderClientId : esignetConfig . openIdProviderClientId ,
299
347
} ) ,
300
348
) ;
349
+ if ( esignetConfig . loaderFieldName ) {
350
+ fields . push (
351
+ esignetLoaderField ( {
352
+ event,
353
+ section,
354
+ fieldName : esignetConfig . loaderFieldName ,
355
+ esignetCallbackFieldName : esignetConfig . callback . fieldName ,
356
+ } ) ,
357
+ ) ;
358
+ }
359
+ return [
360
+ ...fields ,
361
+ ...idVerificationFields (
362
+ event ,
363
+ section ,
364
+ verifiedCustomFieldMapping ,
365
+ esignetConfig ,
366
+ ) ,
367
+ ] ;
301
368
}
302
369
return [
303
370
...fields ,
@@ -308,9 +375,10 @@ export const idVerificationFields = (
308
375
event : string ,
309
376
sectionId : string ,
310
377
mapping : any ,
378
+ esignetConfig ?: ESignetConfig ,
311
379
) => {
312
380
return [
313
- verified ( event , sectionId , mapping ) ,
381
+ verified ( event , sectionId , mapping , esignetConfig ) ,
314
382
idVerificationBanner ( event , sectionId , "verified" ) ,
315
383
idVerificationBanner ( event , sectionId , "failed" ) ,
316
384
idVerificationBanner ( event , sectionId , "authenticated" ) ,
0 commit comments