@@ -54,6 +54,11 @@ export const esignet = (
54
54
expression : "!!$form.redirectCallbackFetch" ,
55
55
} ,
56
56
] ,
57
+ mapping : {
58
+ mutation : {
59
+ operation : "ignoreFieldTransformer" ,
60
+ } ,
61
+ } ,
57
62
options : {
58
63
url : url . toString ( ) ,
59
64
callback : {
@@ -103,6 +108,11 @@ export const esignetCallback = ({
103
108
} ,
104
109
validator : [ ] ,
105
110
hideInPreview : true ,
111
+ mapping : {
112
+ mutation : {
113
+ operation : "ignoreFieldTransformer" ,
114
+ } ,
115
+ } ,
106
116
options : {
107
117
url : mosipAPIUserInfoUrl ,
108
118
headers : {
@@ -124,12 +134,6 @@ export const esignetHidden = () => {
124
134
} ;
125
135
} ;
126
136
127
- /**
128
- *
129
- * @description QR reader type definition (this field may not be supported in the latest release of OpenCRVS yet)
130
- *
131
- */
132
-
133
137
export const idReader = (
134
138
event : string ,
135
139
sectionId : string ,
@@ -198,9 +202,15 @@ interface ESignetConfig {
198
202
fieldName : string ;
199
203
mosipAPIUserInfoUrl : string ;
200
204
} ;
205
+ loaderFieldName ?: string ;
201
206
}
202
207
203
- export const verified = ( event : string , sectionId : string , mapping : any ) => {
208
+ export const verified = (
209
+ event : string ,
210
+ sectionId : string ,
211
+ mapping : any ,
212
+ esignetConfig ?: ESignetConfig ,
213
+ ) => {
204
214
const fieldName = "verified" ;
205
215
const fieldId = `${ event } .${ sectionId } .${ sectionId } -view-group.${ fieldName } ` ;
206
216
return {
@@ -213,10 +223,15 @@ export const verified = (event: string, sectionId: string, mapping: any) => {
213
223
id : "form.field.label.empty" ,
214
224
defaultMessage : "" ,
215
225
} ,
216
- initialValue : {
217
- dependsOn : [ "idReader" ] ,
218
- expression : 'Boolean($form?.idReader)? "pending":""' ,
219
- } ,
226
+ initialValue : esignetConfig
227
+ ? {
228
+ dependsOn : [ "idReader" , esignetConfig . callback . fieldName ] ,
229
+ expression : `Boolean($form?.idReader)? "pending": Boolean($form?.${ esignetConfig . callback . fieldName } ?.data)? "authenticated": ""` ,
230
+ }
231
+ : {
232
+ dependsOn : [ "idReader" ] ,
233
+ expression : 'Boolean($form?.idReader)? "pending":""' ,
234
+ } ,
220
235
validator : [ ] ,
221
236
mapping,
222
237
} ;
@@ -226,10 +241,13 @@ function capitalize(str: string) {
226
241
return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
227
242
}
228
243
244
+ type VerificationStatus = "verified" | "failed" | "authenticated" ;
245
+
229
246
export const idVerificationBanner = (
230
247
event : string ,
231
248
sectionId : string ,
232
- status : "verified" | "failed" | "authenticated" ,
249
+ status : VerificationStatus ,
250
+ conditionals : any [ ] = [ ] ,
233
251
) => {
234
252
const fieldName = "verified" ;
235
253
const fieldId = `${ event } .${ sectionId } .${ sectionId } -view-group.${ fieldName } ` ;
@@ -240,29 +258,64 @@ export const idVerificationBanner = (
240
258
hideInPreview : true ,
241
259
custom : true ,
242
260
bannerType : status ,
243
- idFieldName : "idReader" ,
261
+ idFieldName : status === "authenticated" ? "esignetCallback" : "idReader" ,
244
262
label : {
245
263
id : "form.field.label.empty" ,
246
264
defaultMessage : "" ,
247
265
} ,
248
266
validator : [ ] ,
249
- conditionals : [
267
+ conditionals : conditionals . concat ( [
250
268
{
251
269
action : "hide" ,
252
270
expression : `$form?.verified !== "${ status } "` ,
253
271
} ,
254
- ] ,
272
+ ] ) ,
255
273
} ;
256
274
} ;
257
275
276
+ export function esignetLoaderField ( {
277
+ event,
278
+ section,
279
+ fieldName,
280
+ esignetCallbackFieldName,
281
+ } : {
282
+ event : "birth" | "death" ;
283
+ section : "informant" | "mother" | "father" | "spouse" | "deceased" ;
284
+ fieldName : string ;
285
+ esignetCallbackFieldName : string ;
286
+ } ) {
287
+ const fieldId = `${ event } .${ section } .${ section } -view-group.${ fieldName } ` ;
288
+ return {
289
+ name : fieldName ,
290
+ type : "LOADER" ,
291
+ fieldId,
292
+ hideInPreview : true ,
293
+ custom : true ,
294
+ label : {
295
+ id : "form.field.label.idReader" ,
296
+ defaultMessage : "ID verification" ,
297
+ } ,
298
+ loadingText : {
299
+ id : "form.field.label.authenticating.nid" ,
300
+ defaultMessage : "Fetching the person's data from E-Signet" ,
301
+ } ,
302
+ conditionals : [
303
+ {
304
+ action : "hide" ,
305
+ expression : `!$form?.${ esignetCallbackFieldName } ?.loading` ,
306
+ } ,
307
+ ] ,
308
+ } ;
309
+ }
310
+
258
311
export const getInitialValueFromIDReader = ( fieldNameInReader : string ) => ( {
259
312
dependsOn : [ "idReader" , "esignetCallback" ] ,
260
313
expression : `$form?.idReader?.${ fieldNameInReader } || $form?.esignetCallback?.data?.${ fieldNameInReader } || ""` ,
261
314
} ) ;
262
315
263
316
export const idReaderFields = (
264
317
event : "birth" | "death" ,
265
- section : "informant" | "mother" | "father" ,
318
+ section : "informant" | "mother" | "father" | "spouse" | "deceased" ,
266
319
qrConfig : QRConfig ,
267
320
esignetConfig : ESignetConfig | undefined ,
268
321
verifiedCustomFieldMapping : any ,
@@ -276,7 +329,7 @@ export const idReaderFields = (
276
329
conditionals . concat ( {
277
330
action : "hide" ,
278
331
expression :
279
- "$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed'" ,
332
+ "$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed' || !!$form?.esignetCallback?.loading " ,
280
333
} ) ,
281
334
readers ,
282
335
) ,
@@ -298,21 +351,48 @@ export const idReaderFields = (
298
351
openIdProviderClientId : esignetConfig . openIdProviderClientId ,
299
352
} ) ,
300
353
) ;
354
+ if ( esignetConfig . loaderFieldName ) {
355
+ fields . push (
356
+ esignetLoaderField ( {
357
+ event,
358
+ section,
359
+ fieldName : esignetConfig . loaderFieldName ,
360
+ esignetCallbackFieldName : esignetConfig . callback . fieldName ,
361
+ } ) ,
362
+ ) ;
363
+ }
364
+ return [
365
+ ...fields ,
366
+ ...idVerificationFields (
367
+ event ,
368
+ section ,
369
+ verifiedCustomFieldMapping ,
370
+ conditionals ,
371
+ esignetConfig ,
372
+ ) ,
373
+ ] ;
301
374
}
302
375
return [
303
376
...fields ,
304
- ...idVerificationFields ( event , section , verifiedCustomFieldMapping ) ,
377
+ ...idVerificationFields (
378
+ event ,
379
+ section ,
380
+ verifiedCustomFieldMapping ,
381
+ conditionals ,
382
+ ) ,
305
383
] ;
306
384
} ;
307
385
export const idVerificationFields = (
308
386
event : string ,
309
387
sectionId : string ,
310
388
mapping : any ,
389
+ conditionals : any [ ] = [ ] ,
390
+ esignetConfig ?: ESignetConfig ,
311
391
) => {
312
392
return [
313
- verified ( event , sectionId , mapping ) ,
314
- idVerificationBanner ( event , sectionId , "verified" ) ,
315
- idVerificationBanner ( event , sectionId , "failed" ) ,
316
- idVerificationBanner ( event , sectionId , "authenticated" ) ,
393
+ verified ( event , sectionId , mapping , esignetConfig ) ,
394
+ idVerificationBanner ( event , sectionId , "verified" , conditionals ) ,
395
+ idVerificationBanner ( event , sectionId , "failed" , conditionals ) ,
396
+ idVerificationBanner ( event , sectionId , "authenticated" , conditionals ) ,
317
397
] ;
318
398
} ;
0 commit comments