diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index 69c57a52..ffaac1b5 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -229,7 +229,19 @@ const CommonUserModal: React.FC = ({ const formData = data.formData; console.log("Form data submitted:", formData); const schemaProperties = schema.properties; - const result = generateUsernameAndPassword(selectedStateCode, userType); + + console.log(formData['year of joining scp']) + let result; + if(formData['year of joining scp']) + { + result = generateUsernameAndPassword(selectedStateCode, userType, formData['year of joining scp']); + + } + else + { + result = generateUsernameAndPassword(selectedStateCode, userType); + + } if (result !== null) { const { username, password } = result; diff --git a/src/components/UserTable.tsx b/src/components/UserTable.tsx index 9670227c..864cd533 100644 --- a/src/components/UserTable.tsx +++ b/src/components/UserTable.tsx @@ -538,9 +538,9 @@ router.replace({ return initialFormData; }; const handleEdit = async (rowData: any) => { - if (submitValue) { - setSubmitValue(false); - } + + submitValue ? setSubmitValue(false) : setSubmitValue(true); + console.log("Edit row:", rowData); try { diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index 391df1ee..a31a0136 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -65,7 +65,10 @@ export const getDeviceId = () => { export const generateUsernameAndPassword = ( stateCode: string, - role: string + role: string, + yearOfJoining?: string, + + ) => { const currentYear = new Date().getFullYear().toString().slice(-2); // Last two digits of the current year const randomNum = Math.floor(10000 + Math.random() * 90000).toString(); //NOSONAR @@ -80,9 +83,10 @@ export const generateUsernameAndPassword = ( console.warn(`Unknown role: ${role}`); // Log a warning for unknown roles return null; // Return null or handle as needed } - + const yearSuffix = + yearOfJoining ? yearOfJoining?.slice(-2) : currentYear; const prefix = rolePrefixes[role]; - const username = `${prefix}${stateCode}${currentYear}${randomNum}`; + const username = `${prefix}${stateCode}${yearSuffix}${randomNum}`; return { username, password: randomNum }; };