Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pfm 5312, integrated aadhaar while modification #243

Open
wants to merge 8 commits into
base: MUKTA-v2.1-Develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import ViewOrganisation from "./pages/employee/Organisation/ViewOrganisation";
import TransferCodeTable from "./components/TransferCodeTable";
import MastersResponse from "./components/MastersResponse";

import AadharValidationComponent from "./components/AadharValidationComponent";

export const MastersModule = ({ stateCode, userType, tenants }) => {

const { path, url } = useRouteMatch();
Expand Down Expand Up @@ -59,7 +61,9 @@ const componentsToRegister = {
SearchOrganisation,
ViewOrganisation,
TransferCodeTable,
MastersResponse
MastersResponse,

AadharValidationComponent
};

export const initMastersComponents = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { Button, TextInput } from '@egovernments/digit-ui-react-components';
import React, { useState, useEffect } from 'react';

const AadharValidationComponent = ({ data, setValue }) => {
const [aadharNumber, setAadharNumber] = useState('');
const [validationResult, setValidationResult] = useState('');
const [showValidateButton, setShowValidateButton] = useState(true);
const [showSuccessMessage, setShowSuccessMessage] = useState(false);
const [isVerified, setIsVerified] = useState(data.basicDetails_isVerified);


useEffect(() => {
setAadharNumber(data.basicDetails_aadhar);
}, [data.basicDetails_aadhar]);

useEffect(() => {
setIsVerified(data.basicDetails_isVerified);
}, [data.basicDetails_isVerified]);

useEffect(() => {
setIsVerified(data.basicDetails_aadhaarResponse);
}, [data.basicDetails_aadhaarResponse]);

const handleAadharChange = (event) => {
const newValue = event.target.value;
setAadharNumber(newValue);
setShowValidateButton(true);
setShowSuccessMessage(false);
setValue("basicDetails_aadhar", newValue);
};

const handleValidateClick = async () => {
try {
const requestBody = {
uid: aadharNumber,
uidType: "A",
consent: "Y",
subAuaCode: "0002590000",
txn: "",
isPI: "y",
isBio: "n",
isOTP: "n",
bioType: "n",
name: data.basicDetails_wageSeekerName,
dob: "",
gender: "",
rdInfo: "",
rdData: "",
otpValue: ""
};

const response = await fetch('http://164.100.141.79/authekycv4/api/authenticate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});

const responseData = await response.json();

if (responseData.status === "SUCCESS") {
setShowSuccessMessage(true);
setValue("basicDetails_isVerified", true);
setValue("basicDetails_aadhaarResponse", JSON.stringify(responseData));
setIsVerified(true);
} else if (responseData.status === "ERROR") {
setShowSuccessMessage(false);
setShowValidateButton(false);
setValue("basicDetails_isVerified", false);
setIsVerified(false);
} else {
setValidationResult('Unknown error occurred.');
setIsVerified(false);
}
setValue("isVerified", isVerified);
} catch (error) {
setValidationResult('An error occurred while validating Aadhaar.');
setIsVerified(false);
setValue("isVerified", isVerified);
}
};

if (data.basicDetails_doc.name === "Aadhaar") {
return (
<div style={{ display: 'flex' }}>
<TextInput
type="text"
value={aadharNumber}
onChange={handleAadharChange}
placeholder="Identity Number"
style={{
border: '1px solid black',
padding: '5px'
}}
disabled={false}
/>
{showSuccessMessage ? (
<div style={{ backgroundColor: '#BAD6C9', display: 'flex', alignItems: 'center', marginLeft: '20px', marginBottom: '25px', borderRadius: '5px' }}>
<div style={{ backgroundColor: '#00703C', borderRadius: '50%', width: '20px', height: '20px', display: 'flex', justifyContent: 'center', alignItems: 'center', marginLeft: '5px' }}>
<span style={{ color: 'white', fontWeight: 'bold' }}>&#10004;</span>
</div>
<span style={{ color: '#00703C', fontWeight: 'bold', whiteSpace: 'nowrap', padding: '5px' }}>Aadhaar validated successfully!</span>
</div>
) : showValidateButton ? (
<Button
label={"Validate"}
variation="secondary"
onButtonClick={handleValidateClick}
type="button"
style={{
marginLeft: '20px',
marginBottom: '25px'
}}
/>
) : (
<div style={{ backgroundColor: '#EFC7C1', display: 'flex', alignItems: 'center', marginLeft: '20px', marginBottom: '25px', borderRadius: '5px' }}>
<div style={{ backgroundColor: '#D63E26', borderRadius: '50%', width: '20px', height: '20px', display: 'flex', justifyContent: 'center', alignItems: 'center', marginLeft: '5px' }}>
<span style={{ color: '#EAAFA6', fontWeight: 'bold' }}>!</span>
</div>
<span style={{ color: '#D63E26', fontWeight: 'bold', whiteSpace: 'nowrap' }}>&nbsp;Aadhaar validation failed!</span>
</div>
)}

<div>{validationResult}</div>
</div>
);
}

if (data.basicDetails_doc.name === "AADHAAR"){
return (
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
<TextInput
type="text"
value={aadharNumber}
onChange={handleAadharChange}
placeholder="Identity Number"
disabled={true}
/>
<div>{validationResult}</div>
</div>
);
}
return (
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
<TextInput
type="text"
value={aadharNumber}
onChange={handleAadharChange}
placeholder="Identity Number"
disabled={false}
/>
<div>{validationResult}</div>
</div>
);
};

export default AadharValidationComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,63 @@ export const CreateWageSeekerConfig = {
}
},
{
label: "ES_COMMON_AADHAR",
label: "WAGE_SEEKER_IDENTITY_DOCUMENT_LABEL",
isMandatory: false,
key: "basicDetails_doc",
type: "radioordropdown",
disable: false,
populators: {
name: "basicDetails_doc",
optionsKey: "name",
options: [ // These options are hardcoded, need to integrate with mdms once the new env is up
{ code: "AADHAAR", name: "Aadhaar", active:true},
{ code: "ELECTION_PHOTO", name: "Election Photo Identity Card (EPIC)", active: true},
{ code: "DRIVING_LICENSE", name: "Driving License", active: true},
{ code: "RATION_CARD", name: "Ration Card under TDPS", active: true},
],
error: "WORKS_REQUIRED_ERR",
optionsCustomStyle : {
top : "2.3rem"
}
}
},
{
label: "WAGE_SEEKER_IDENTITY_NUMBER_LABEL",
isMandatory: true,
key: "basicDetails_aadhar",
type: "text",
disable: false,
type: "component",
component: "AadharValidationComponent",
disable: true,
preProcess : {
updateDependent : ["populators.customStyle.pointerEvents", "populators.customClass"]
convertStringToRegEx : ["populators.validation.pattern"]
Lokendra-egov marked this conversation as resolved.
Show resolved Hide resolved
},
populators: {
name: "basicDetails_aadhar",
error: "WORKS_REQUIRED_ERR",
customStyle : {
pointerEvents : "auto"
},
customClass : "field-value-no-border"
name: "basicDetails_aadhar",
error: "WORKS_REQUIRED_ERR"
}
},
{
label: "IS_AADHAAR_VERIFIED",
key: "basicDetails_isVerified",
type: "text",
disable: true,
populators: {
name: "basicDetails_isVerified",
customStyle: {
display: "none"
}
}
},
{
"label": "AADHAAR_RESPONSE",
"key": "basicDetails_aadhaarResponse",
"type": "text",
"disable": true,
"populators": {
"name": "basicDetails_aadhaarResponse",
"customStyle": {
"display": "none"
}
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export const updateWageSeekerFormDefaultValues = async ({configs, isModify, sess
if(isModify) {
configs.defaultValues.basicDetails_wageSeekerId = individual?.individualId ? individual?.individualId : ""
}
configs.defaultValues.basicDetails_aadhar = adhaar ? adhaar?.identifierId : ""
configs.defaultValues.basicDetails_aadhar = individual?.identifiers?.length ? individual?.identifiers[0].identifierId : ""
configs.defaultValues.basicDetails_doc = individual?.identifiers?.length ? { code: individual?.identifiers[0].identifierType, name: individual?.identifiers[0].identifierType, active: true } : ""
configs.defaultValues.basicDetails_isVerified = individual?.additionalFields?.fields?.is_aadhaar_verified ? individual?.additionalFields?.fields?.is_aadhaar_verified : false
configs.defaultValues.basicDetails_aadhaarResponse = individual?.additionalFields?.fields?.basicDetails_aadhaarResponse ? individual?.additionalFields?.fields?.basicDetails_aadhaarResponse : "null"
Lokendra-egov marked this conversation as resolved.
Show resolved Hide resolved
configs.defaultValues.basicDetails_wageSeekerName = individual?.name?.givenName ? individual?.name?.givenName : ""
configs.defaultValues.basicDetails_fatherHusbandName = individual?.fatherName ? individual?.fatherName : ""
configs.defaultValues.basicDetails_relationShip = individual?.relationship ? { code: individual?.relationship, name: `COMMON_MASTERS_RELATIONSHIP_${individual?.relationship}`, active: true } : ""
Expand Down Expand Up @@ -95,6 +98,8 @@ const getSkillsToUpdate = (formData, wageSeekerDataFromAPI) => {
export const getWageSeekerUpdatePayload = ({formData, wageSeekerDataFromAPI, tenantId, isModify}) => {
let Individual = {}

const currentEpochTime = Math.floor(new Date().getTime() / 1000);

Individual.tenantId = tenantId
Individual.name = {
givenName: formData?.basicDetails_wageSeekerName
Expand All @@ -112,7 +117,20 @@ export const getWageSeekerUpdatePayload = ({formData, wageSeekerDataFromAPI, ten
fields: [{
key: "SOCIAL_CATEGORY",
value: formData?.basicDetails_socialCategory?.code
}]
},
{
key: "is_aadhaar_verified",
value: formData?.basicDetails_isVerified
},
{
key: "modification_time",
value: currentEpochTime // Add the current epoch time as the value
},
{
key: "aadhaar_response",
value: formData?.basicDetails_aadhaarResponse
}
]
}
}

Expand Down Expand Up @@ -168,6 +186,8 @@ export const getWageSeekerUpdatePayload = ({formData, wageSeekerDataFromAPI, ten
Individual.rowVersion = wageSeekerDataFromAPI?.individual?.rowVersion
//here set the identifiers on Individual object
Individual.identifiers = wageSeekerDataFromAPI?.individual?.identifiers
Individual.identifiers[0].identifierId = formData.basicDetails_aadhar
Individual.identifiers[0].identifierType = formData.basicDetails_doc.name
}

return {
Expand Down