Skip to content

Commit

Permalink
Merge pull request #221 from AkshataKatwal16/admin
Browse files Browse the repository at this point in the history
Issue feat: update username of created user according to year of joining
  • Loading branch information
itsvick authored Sep 20, 2024
2 parents bcda7fd + 0b91801 commit 2416f93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/components/CommonUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,19 @@ const CommonUserModal: React.FC<UserModalProps> = ({
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;

Expand Down
6 changes: 3 additions & 3 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 };
};
Expand Down

0 comments on commit 2416f93

Please sign in to comment.