diff --git a/sections/HRContactDetails.tsx b/sections/HRContactDetails.tsx index 2e485d5e..f00d93cc 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 (
@@ -105,22 +103,13 @@ function AuthHR(props: { id: string; name: string }) { -

Enter New Password

- +

Generate New Password

@@ -182,7 +171,7 @@ const HRcotactDetailsColumns: GridColDef[] = [ field: "button2", headerName: "Send Authorization Mail", renderCell: (params) => ( - + ), width: 100, },