Open rikukissa opened 3 months ago
@SyedaAfrida we will need to modify the Farajaland configuration to make sure this is consistently tested.
A proposal to generalize this for MOSIP as well:
{
name: 'fetchNUI',
type: 'HTTP',
custom: true,
options: {
url: '/api/v1/nui',
method: 'GET',
headers: {
authorization: 'Bearer {$user.token}'
},
body: {
nonce: '$form.redirectNIN'
}
}
}
[ ] Create a dummy BUTTON only used for triggering the fetch and showing it's status
{
name: 'dummyButton',
type: 'BUTTON',
custom: true,
validator: [],
options: {
trigger: 'fetchNUI'
},
conditionals: [
{
action: 'disable',
expression: '$form.fetchNUI?.data'
},
{
action: 'disable',
expression: '$form.fetchNUI?.error'
}
],
label: {
defaultMessage: 'Generate NUI',
description: 'Label for form field: First names',
id: 'form.field.label.nui'
}
},
[ ] Create a REDIRECT_BUTTON that redirects the user to some URL, and then on the way back, it can trigger an HTTP
{
"name": "redirectNIN",
"type": "REDIRECT_BUTTON",
"custom": true,
"options": {
"trigger": "fetchNUI",
"url": "https://mosip-mediator.farajaland.opencrvs.org",
},
"label": {
"defaultMessage": "Redirect to NIN",
"description": "Label for redirect button",
"id": "form.field.label.redirectNIN"
},
conditionals: [
{
action: 'disable',
expression: 'true'
},
{
action: 'hide',
expression: '$form.redirectNIN' // this value is populated using a query parameter `?%24form.redirectNIN=...` where %24 is $
}
]
}
Let's take this ticket into account as well https://github.com/opencrvs/opencrvs-core/issues/5987
An example of country configuration:
{
name: 'fetchNUI',
type: 'HTTP',
hideInPreview: true,
custom: true,
label: { id: 'form.label.empty', defaultMessage: ' ' },
validator: [],
options: {
url: '/api/countryconfig/nui-demo',
method: 'GET'
}
},
// {
// name: 'redirect',
// type: 'REDIRECT',
// custom: true,
// label: { id: 'form.label.empty', defaultMessage: ' ' },
// validator: [],
// initialValue: '',
// conditionals: [
// { action: 'hide', expression: '!$form.fetchNUI?.data' }
// ],
// options: {
// url: '/some-route?data=${$form.fetchNUI?.data}'
// }
// },
{
name: 'iD',
type: 'TEXT',
label: formMessageDescriptors.iDTypeNationalID,
required: true,
custom: true,
initialValue: {
expression: '$form.fetchNUI?.data',
dependsOn: ['fetchNUI']
},
maxLength: 10,
conditionals: [
{
action: 'hide',
expression:
'!$form.fetchNUI?.data || !window.navigator.onLine'
},
{
action: 'disable',
expression: '$form.fetchNUI?.data'
}
],
validator: [],
mapping: {
template: {
fieldName: 'childNID',
operation: 'identityToFieldTransformer',
parameters: ['id', 'NATIONAL_ID']
},
mutation: {
operation: 'fieldToIdentityTransformer',
parameters: ['id', 'NATIONAL_ID']
},
query: {
operation: 'identityToFieldTransformer',
parameters: ['id', 'NATIONAL_ID']
}
}
},
{
name: 'dummyButton',
type: 'BUTTON',
custom: true,
hideInPreview: true,
validator: [],
options: {
trigger: 'fetchNUI',
shouldHandleLoadingState: true
},
conditionals: [
{
action: 'hide',
expression: '$form.fetchNUI?.data'
},
{
action: 'disable',
expression: '$form.fetchNUI?.error'
},
{
action: 'disable',
expression: '!window.navigator.onLine'
}
],
label: formMessageDescriptors.iDTypeNationalID,
buttonLabel: {
defaultMessage: 'Generate NUI',
description: 'Label for form field: Generate NUI',
id: 'form.field.label.generateNUI'
},
icon: 'UserCircle',
loadingLabel: {
defaultMessage: 'Generating...',
description: 'Label for form field: Generate NUI',
id: 'form.field.label.generatingNUI'
}
},
{
name: 'iDManual',
type: 'TEXT',
label: {
id: 'form.field.label.idManual',
defaultMessage: 'Enter national ID manually'
},
required: true,
custom: true,
initialValue: '',
maxLength: 10,
conditionals: [
{
action: 'hide',
expression: 'window.navigator.onLine'
}
],
validator: [],
mapping: {
template: {
fieldName: 'childNIDManual',
operation: 'identityToFieldTransformer',
parameters: ['id', 'NATIONAL_ID']
},
mutation: {
operation: 'fieldToIdentityTransformer',
parameters: ['id', 'NATIONAL_ID']
},
query: {
operation: 'identityToFieldTransformer',
parameters: ['id', 'NATIONAL_ID']
}
}
}
Description
In all of its simplicity, this form input is a button, which when pressed, creates an HTTP request and returns the value back to the form. This input is meant to be a very low-level, generic building block, not many abstraction levels from a pure
fetch
call. As such, it can be used for countless use cases. The field can form HTTP payloads using values from other form fields. Other form fields can again read the HTTP return values from this field.The architectural steer for building this is that adding it should be low-risk and disrupt existing code as little as possible.
Example usage of the new
In this example, there is a button in the form that generates an NUI (National Unique Identifier) when pressed. Button is disabled after it has been pressed once. There is a disabled text field below the button in where the resulting value is shown.
Note that while researching this, I started a branch for this in core
Dev tasks
/api/countryconfig/
to country config. We add this to discourage countries from making direct requests from browser to country config, which will be sunset in the future.condition[].expression
is evaluated, provide$values
,$form
with the currentvalues
object.$form
should always refer to Formik form values and$values
should always refer the draft.