From ea1c4759330355e322a43d041eeb4b8f4e91b93f Mon Sep 17 00:00:00 2001 From: utkarsh-tf141 Date: Sun, 11 Feb 2024 01:48:58 +0530 Subject: [PATCH 1/2] Random HR auth added --- sections/HRContactDetails.tsx | 69 +++++++++++++++-------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/sections/HRContactDetails.tsx b/sections/HRContactDetails.tsx index 2e485d5e..7dcb7fcf 100644 --- a/sections/HRContactDetails.tsx +++ b/sections/HRContactDetails.tsx @@ -1,18 +1,9 @@ import AddIcon from "@mui/icons-material/Add"; import DeleteIcon from "@mui/icons-material/Delete"; -import { - Box, - Button, - IconButton, - Modal, - Stack, - TextField, - Tooltip, -} from "@mui/material"; +import { Box, Button, IconButton, Modal, Stack, Tooltip } from "@mui/material"; import { GridColDef } from "@mui/x-data-grid"; import { useRouter } from "next/router"; import React, { useEffect, useState } from "react"; -import { useForm } from "react-hook-form"; import DataGrid from "@components/DataGrid"; import addCompanyRequest, { HR } from "@callbacks/admin/company/company"; @@ -70,26 +61,9 @@ function DeleteHR(props: { id: string }) { ); } -function AuthHR(props: { id: string; name: string }) { - const { - register, - handleSubmit, - formState: { errors }, - reset, - } = useForm(); +function AuthHR(props: { id: string; Name: string }) { const { token } = useStore(); - const det = props; - - const handleAuthHR = (data: HRAuthResponse) => { - const authHR = async () => { - const finData = { ...data, user_id: det.id, name: det.name }; - const response = await HRAuth.post(token, finData); - if (response) { - reset({ password: "" }); - } - }; - authHR(); - }; + const { id, Name } = props; const [openAuthHR, setOpenAuthHR] = useState(false); const handleOpenAuthHR = () => { setOpenAuthHR(true); @@ -97,6 +71,30 @@ function AuthHR(props: { id: string; name: string }) { const handleCloseAuthHR = () => { setOpenAuthHR(false); }; + const handleSubmit = () => { + const authHR = async () => { + const randomPwd = generateRandomPassword(); + const newPwd: HRAuthResponse = { password: randomPwd }; + const finData = { ...newPwd, user_id: id, name: Name }; + let response = await HRAuth.post(token, finData); + if (response) { + handleCloseAuthHR(); + } + }; + authHR(); + }; + + function generateRandomPassword(length = 12) { + const charset = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{}|;:,<>?"; + let password = ""; + for (let i = 0; i < length; i += 1) { + const randomIndex = Math.floor(Math.random() * charset.length); + password += charset[randomIndex]; + } + return password; + } + return (
@@ -106,19 +104,10 @@ function AuthHR(props: { id: string; name: string }) {

Enter New Password

- @@ -182,7 +171,7 @@ const HRcotactDetailsColumns: GridColDef[] = [ field: "button2", headerName: "Send Authorization Mail", renderCell: (params) => ( - + ), width: 100, }, From ba1879910c897ba54570308007ad97befb0d2ecb Mon Sep 17 00:00:00 2001 From: utkarsh-tf141 Date: Sun, 11 Feb 2024 01:54:31 +0530 Subject: [PATCH 2/2] minor changes --- sections/HRContactDetails.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sections/HRContactDetails.tsx b/sections/HRContactDetails.tsx index 7dcb7fcf..f00d93cc 100644 --- a/sections/HRContactDetails.tsx +++ b/sections/HRContactDetails.tsx @@ -103,13 +103,13 @@ function AuthHR(props: { id: string; Name: string }) { -

Enter New Password

+

Generate New Password