Skip to content

Commit 4733b7c

Browse files
feat: esignet UI forms (#68)
* feat(esignet): add authenticating loader * feat: set verified status authenticated after esignet successful redirection * fix: loading label * fix: rename loader field name
1 parent b1e5531 commit 4733b7c

File tree

1 file changed

+76
-8
lines changed

1 file changed

+76
-8
lines changed

packages/country-config/src/forms.ts

+76-8
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,15 @@ interface ESignetConfig {
198198
fieldName: string;
199199
mosipAPIUserInfoUrl: string;
200200
};
201+
loaderFieldName?: string;
201202
}
202203

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+
) => {
204210
const fieldName = "verified";
205211
const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
206212
return {
@@ -213,10 +219,15 @@ export const verified = (event: string, sectionId: string, mapping: any) => {
213219
id: "form.field.label.empty",
214220
defaultMessage: "",
215221
},
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+
},
220231
validator: [],
221232
mapping,
222233
};
@@ -226,10 +237,12 @@ function capitalize(str: string) {
226237
return str.charAt(0).toUpperCase() + str.slice(1);
227238
}
228239

240+
type VerificationStatus = "verified" | "failed" | "authenticated";
241+
229242
export const idVerificationBanner = (
230243
event: string,
231244
sectionId: string,
232-
status: "verified" | "failed" | "authenticated",
245+
status: VerificationStatus,
233246
) => {
234247
const fieldName = "verified";
235248
const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
@@ -255,6 +268,41 @@ export const idVerificationBanner = (
255268
};
256269
};
257270

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+
258306
export const getInitialValueFromIDReader = (fieldNameInReader: string) => ({
259307
dependsOn: ["idReader", "esignetCallback"],
260308
expression: `$form?.idReader?.${fieldNameInReader} || $form?.esignetCallback?.data?.${fieldNameInReader} || ""`,
@@ -276,7 +324,7 @@ export const idReaderFields = (
276324
conditionals.concat({
277325
action: "hide",
278326
expression:
279-
"$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed'",
327+
"$form?.verified === 'verified' || $form?.verified === 'authenticated' || $form?.verified === 'failed' || !!$form?.esignetCallback?.loading",
280328
}),
281329
readers,
282330
),
@@ -298,6 +346,25 @@ export const idReaderFields = (
298346
openIdProviderClientId: esignetConfig.openIdProviderClientId,
299347
}),
300348
);
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+
];
301368
}
302369
return [
303370
...fields,
@@ -308,9 +375,10 @@ export const idVerificationFields = (
308375
event: string,
309376
sectionId: string,
310377
mapping: any,
378+
esignetConfig?: ESignetConfig,
311379
) => {
312380
return [
313-
verified(event, sectionId, mapping),
381+
verified(event, sectionId, mapping, esignetConfig),
314382
idVerificationBanner(event, sectionId, "verified"),
315383
idVerificationBanner(event, sectionId, "failed"),
316384
idVerificationBanner(event, sectionId, "authenticated"),

0 commit comments

Comments
 (0)