Compare commits

...

10 Commits

7 changed files with 296 additions and 249 deletions

View File

@ -34,6 +34,7 @@ export const ReportTask = ({ report, closeModal, refetch }) => {
...data, ...data,
id: report?.id, id: report?.id,
reportedDate: new Date().toISOString(), reportedDate: new Date().toISOString(),
checkList:[]
}; };
let response = await TasksRepository.reportTsak(reportData); let response = await TasksRepository.reportTsak(reportData);
@ -116,6 +117,17 @@ export const ReportTask = ({ report, closeModal, refetch }) => {
</label> </label>
</div> </div>
</div> </div>
<div class="mb-1 row text-start">
<label for="html5-email-input" class="col-md-4 col-form-label">
Planned :
</label>
<div class="col-md-8 text-start text-wrap">
<label class=" col-form-label">
{report?.plannedTask
}
</label>
</div>
</div>
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
<div class="mb-1 row text-start"> <div class="mb-1 row text-start">
<label for="html5-email-input" class="col-md-4 col-form-label"> <label for="html5-email-input" class="col-md-4 col-form-label">

View File

@ -4,7 +4,7 @@ const EmployeeNav = ({ onPillClick, activePill }) => {
return ( return (
<div className="col-md-12"> <div className="col-md-12">
<div className="nav-align-top "> <div className="nav-align-top ">
<ul className="nav nav-pills flex-column flex-sm-row mb-6"> <ul className="nav nav-tabs">
<li className="nav-item"> <li className="nav-item">
<a <a
className={`nav-link py-1 px-2 small ${activePill === "account" ? "active" : ""}`} className={`nav-link py-1 px-2 small ${activePill === "account" ? "active" : ""}`}

View File

@ -39,21 +39,15 @@ const ManageEmployee = () => {
Email: z Email: z
.string() .string()
.optional() .optional()
.refine( .refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), {
(val) =>
!val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val),
{
message: "Invalid email format", message: "Invalid email format",
} })
)
.refine( .refine(
(val) => { (val) => {
if (!val) return true; if (!val) return true;
const [local, domain] = val.split("@"); const [local, domain] = val.split("@");
return ( return (
val.length <= 320 && val.length <= 320 && local?.length <= 64 && domain?.length <= 255
local?.length <= 64 &&
domain?.length <= 255
); );
}, },
{ {
@ -92,7 +86,10 @@ const ManageEmployee = () => {
.regex(mobileNumberRegex, { message: "Invalid phone number " }), .regex(mobileNumberRegex, { message: "Invalid phone number " }),
EmergencyContactPerson: z EmergencyContactPerson: z
.string() .string()
.min(1, { message: "Emergency Contact Person is required" }), .min(1, { message: "Emergency Contact Person is required" })
.regex(/^[A-Za-z\s]+$/, {
message: "Emergency Contact Person must contain only letters",
}),
AadharNumber: z AadharNumber: z
.string() .string()
.regex(/^\d{12}$/, "Aadhar card must be exactly 12 digits long") .regex(/^\d{12}$/, "Aadhar card must be exactly 12 digits long")
@ -444,7 +441,9 @@ const ManageEmployee = () => {
)} )}
</div> </div>
<div className="col-sm-6"> <div className="col-sm-6">
<div className="form-text text-start">Permanent Address</div> <div className="form-text text-start">
Permanent Address
</div>
<textarea <textarea
id="PermanentAddress" id="PermanentAddress"

View File

@ -1,28 +1,28 @@
import React,{useEffect, useState} from 'react' import React, { useEffect, useState } from "react";
import useMaster from '../../hooks/masterHook/useMaster' import useMaster from "../../hooks/masterHook/useMaster";
import { useForm } from 'react-hook-form'; import { useForm } from "react-hook-form";
import { z } from 'zod'; import { z } from "zod";
import { zodResolver } from '@hookform/resolvers/zod'; import { zodResolver } from "@hookform/resolvers/zod";
import { RolesRepository } from '../../repositories/MastersRepository'; import { RolesRepository } from "../../repositories/MastersRepository";
import { useEmployeeRoles } from '../../hooks/useEmployees'; import { useEmployeeRoles } from "../../hooks/useEmployees";
import {useDispatch} from 'react-redux'; import { useDispatch } from "react-redux";
import {changeMaster} from '../../slices/localVariablesSlice'; import { changeMaster } from "../../slices/localVariablesSlice";
import showToast from '../../services/toastService'; import showToast from "../../services/toastService";
const formSchema = z.object({ const formSchema = z.object({
selectedRole: z.record(z.boolean()).refine((data) => { selectedRole: z.record(z.boolean()).refine(
return Object.values(data).some(value => value === true); (data) => {
}, { return Object.values(data).some((value) => value === true);
},
{
message: "At least one checkbox must be selected.", message: "At least one checkbox must be selected.",
}), }
),
}); });
const ManageRole = ({ employeeId, onClosed }) => { const ManageRole = ({ employeeId, onClosed }) => {
const disptach = useDispatch();
const disptach = useDispatch() disptach(changeMaster("Application Role"));
disptach(changeMaster("Role"))
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { employeeRoles, loading } = useEmployeeRoles(employeeId); const { employeeRoles, loading } = useEmployeeRoles(employeeId);
const { data, loading: roleLoading } = useMaster(); const { data, loading: roleLoading } = useMaster();
@ -30,7 +30,9 @@ const ManageRole = ({employeeId,onClosed}) => {
const buildDefaultRoles = () => { const buildDefaultRoles = () => {
const defaults = {}; const defaults = {};
data.forEach((role) => { data.forEach((role) => {
const isRoleEnabled = employeeRoles?.data?.some((empRole) => empRole.roleId === role.id); const isRoleEnabled = employeeRoles?.data?.some(
(empRole) => empRole.roleId === role.id
);
defaults[role.id] = isRoleEnabled; defaults[role.id] = isRoleEnabled;
}); });
@ -46,16 +48,19 @@ const ManageRole = ({employeeId,onClosed}) => {
} }
}, [employeeRoles, data]); }, [employeeRoles, data]);
const { register, handleSubmit, formState: { errors }, reset } = useForm({ const {
register,
handleSubmit,
formState: { errors },
reset,
} = useForm({
resolver: zodResolver(formSchema), resolver: zodResolver(formSchema),
defaultValues: { defaultValues: {
selectedRole: initialRoles, selectedRole: initialRoles,
}, },
}); });
useEffect(() => {
useEffect( () =>
{
if (Object.keys(initialRoles).length > 0) { if (Object.keys(initialRoles).length > 0) {
reset({ reset({
selectedRole: initialRoles, selectedRole: initialRoles,
@ -64,7 +69,7 @@ const ManageRole = ({employeeId,onClosed}) => {
}, [initialRoles, reset]); }, [initialRoles, reset]);
const onSubmit = (formdata) => { const onSubmit = (formdata) => {
setIsLoading(true) setIsLoading(true);
const result = []; const result = [];
for (const [roleId, isEnabled] of Object.entries(formdata.selectedRole)) { for (const [roleId, isEnabled] of Object.entries(formdata.selectedRole)) {
if (isEnabled) { if (isEnabled) {
@ -75,23 +80,29 @@ const ManageRole = ({employeeId,onClosed}) => {
}); });
} }
} }
RolesRepository.createEmployeeRoles( result ).then( ( resp ) => RolesRepository.createEmployeeRoles(result)
{ .then((resp) => {
showToast( "Role assigned successfully", "success" ) showToast("Role assigned successfully", "success");
setIsLoading(false) setIsLoading(false);
onClosed() onClosed();
}).catch((err)=>{
console.log( err )
setIsLoading(false)
showToast(err.message,"error")
}) })
setIsLoading(false) .catch((err) => {
console.log(err);
setIsLoading(false);
showToast(err.message, "error");
});
setIsLoading(false);
}; };
console.log(data)
return ( return (
<div
<div className={`modal fade `} id="managerole-modal" tabIndex="-1" aria-hidden="true" > className={`modal fade `}
id="managerole-modal"
tabIndex="-1"
aria-hidden="true"
>
<div className="modal-dialog modal-simple modal-md d-flex align-items-center justify-content-center"> <div className="modal-dialog modal-simple modal-md d-flex align-items-center justify-content-center">
<div className="modal-content "> <div className="modal-content ">
<div className="modal-body"> <div className="modal-body">
@ -100,20 +111,19 @@ const ManageRole = ({employeeId,onClosed}) => {
className="btn-close" className="btn-close"
data-bs-dismiss="modal" data-bs-dismiss="modal"
aria-label="Close" aria-label="Close"
></button> ></button>
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
<div className='text-start my-0'> <div className="text-start my-0">
<p className='lead'>Select Roles</p> <p className="lead">Select Roles</p>
</div> </div>
<div
<div className='d-flex flex-wrap justify-content-between align-items-center pb-5 ' style={{maxHeight: "70vh", overflowY: "scroll"}} > className="d-flex flex-wrap justify-content-between align-items-center pb-5 "
style={{ maxHeight: "70vh", overflowY: "scroll" }}
>
{(loading || roleLoading) && <p>Loading...</p>} {(loading || roleLoading) && <p>Loading...</p>}
{data && data.map((item) => ( {data &&
data.map((item) => (
<div className="col-md-6 col-lg-4 mb-4" key={item.id}> <div className="col-md-6 col-lg-4 mb-4" key={item.id}>
<div className="form-check ms-2 text-start"> <div className="form-check ms-2 text-start">
<input <input
@ -121,28 +131,30 @@ const ManageRole = ({employeeId,onClosed}) => {
type="checkbox" type="checkbox"
id={item.id} id={item.id}
{...register(`selectedRole.${item.id}`, { {...register(`selectedRole.${item.id}`, {
value: initialRoles[item.id] || false value: initialRoles[item.id] || false,
})} })}
/> />
<label className="form-check-label text-bold" htmlFor={item.id}><small>{item.role || "--"}</small></label> <label
className="form-check-label text-bold"
htmlFor={item.id}
>
<small>{item.role || "--"}</small>
</label>
</div> </div>
</div> </div>
))} ))}
</div> </div>
{errors.selected && <div className="text-center">{errors.selected.message}</div>} {errors.selected && (
<div className="text-center">{errors.selected.message}</div>
)}
<div className="col-12 text-center"> <div className="col-12 text-center">
<button type="submit" className="btn btn-primary me-3"> <button type="submit" className="btn btn-sm btn-primary me-3">
{isLoading ? "Please Wait" : "Submit"} {isLoading ? "Please Wait" : "Submit"}
</button> </button>
<button <button
type="reset" type="reset"
className="btn btn-label-secondary" className="btn btn-sm btn-label-secondary"
data-bs-dismiss="modal" data-bs-dismiss="modal"
aria-label="Close" aria-label="Close"
> >
@ -154,9 +166,7 @@ const ManageRole = ({employeeId,onClosed}) => {
</div> </div>
</div> </div>
</div> </div>
) );
} };
export default ManageRole; export default ManageRole;

View File

@ -6,9 +6,8 @@ import {changeMaster} from "../../slices/localVariablesSlice";
import useMaster from "../../hooks/masterHook/useMaster"; import useMaster from "../../hooks/masterHook/useMaster";
import {useProfile} from "../../hooks/useProfile"; import {useProfile} from "../../hooks/useProfile";
import {useNavigate} from "react-router-dom"; import {useNavigate} from "react-router-dom";
import Avatar from "../../components/common/Avatar";
const Header = () => const Header = () =>{
{
const {profile} = useProfile() const {profile} = useProfile()
const dispatch = useDispatch( changeMaster( "Job Role" ) ) const dispatch = useDispatch( changeMaster( "Job Role" ) )
const {data, loading} = useMaster() const {data, loading} = useMaster()
@ -88,11 +87,9 @@ const Header = () =>
data-bs-toggle="dropdown" data-bs-toggle="dropdown"
> >
<div className="avatar avatar-online"> <div className="avatar avatar-online">
<img <Avatar
src="../assets/img/avatars/00.jpg" firstName={`${profile?.employeeInfo?.firstName}`}
className="w-px-40 h-auto rounded-circle" lastName={`${profile?.employeeInfo?.lastName}`}
alt="avatar-image"
aria-label="Avatar Image"
/> />
</div> </div>
</a> </a>
@ -106,11 +103,9 @@ const Header = () =>
<div className="d-flex"> <div className="d-flex">
<div className="flex-shrink-0 me-3"> <div className="flex-shrink-0 me-3">
<div className="avatar avatar-online"> <div className="avatar avatar-online">
<img <Avatar
src="../assets/img/avatars/00.jpg" firstName={`${profile?.employeeInfo?.firstName}`}
className="w-px-40 h-auto rounded-circle" lastName={`${profile?.employeeInfo?.lastName}`}
alt="avatar-image"
aria-label="Avatar Image"
/> />
</div> </div>
</div> </div>

View File

@ -1,6 +1,22 @@
import React from "react"; import React, { useState, useEffect } from "react";
// A simple hash function to generate a deterministic value from the name
function hashString(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = (hash << 5) - hash + char;
}
return hash;
}
const Avatar = ({ firstName, lastName, size='sm' }) => { const Avatar = ({ firstName, lastName, size='sm' }) => {
// Combine firstName and lastName to create a unique string for hashing
const fullName = `${firstName} ${lastName}`;
const [bgClass, setBgClass] = useState("");
// Function to generate the avatar text
function generateAvatarText(firstName, lastName) { function generateAvatarText(firstName, lastName) {
if (!firstName) return ""; if (!firstName) return "";
if (!lastName || lastName.trim() === "") { if (!lastName || lastName.trim() === "") {
@ -9,7 +25,8 @@ const Avatar = ({ firstName, lastName, size='sm' }) => {
return `${firstName[0]}${lastName[0]}`.toUpperCase(); return `${firstName[0]}${lastName[0]}`.toUpperCase();
} }
function getRandomBootstrapBgClass() { // Function to map the hash value to a Bootstrap background class
function getBgClassFromHash(hash) {
const bgClasses = [ const bgClasses = [
"bg-primary", "bg-primary",
"bg-secondary", "bg-secondary",
@ -21,21 +38,27 @@ const Avatar = ({ firstName, lastName, size='sm' }) => {
"text-light", "text-light",
]; ];
const randomIndex = Math.floor(Math.random() * bgClasses.length); // Use the hash value to pick a background color from the array
return bgClasses[randomIndex]; const index = Math.abs(hash % bgClasses.length);
return bgClasses[index];
} }
useEffect(() => {
// Generate the hash from the full name and map it to a background class
const hash = hashString(fullName);
setBgClass(getBgClassFromHash(hash));
}, [fullName]); // Re-run if the fullName changes
return ( return (
<>
<div className="avatar-wrapper p-1"> <div className="avatar-wrapper p-1">
<div className={`avatar avatar-${size} me-2`}> <div className={`avatar avatar-${size} me-2`}>
<span <span
className={`avatar-initial rounded-circle ${getRandomBootstrapBgClass()}`} className={`avatar-initial rounded-circle ${bgClass}`}
> >
{generateAvatarText(firstName, lastName)} {generateAvatarText(firstName, lastName)}
</span> </span>
</div> </div>
</div> </div>
</>
); );
}; };

View File

@ -9,7 +9,8 @@ import { useEmployeeProfile, useEmployees, useEmployeesByProject } from "../../h
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import EmployeeRepository from "../../repositories/EmployeeRepository"; import EmployeeRepository from "../../repositories/EmployeeRepository";
import { ComingSoonPage } from "../Misc/ComingSoonPage"; import { ComingSoonPage } from "../Misc/ComingSoonPage";
import { useNavigate } from "react-router-dom";
import Avatar from "../../components/common/Avatar";
const EmployeeProfile = () => { const EmployeeProfile = () => {
const projectID = useSelector((store)=>store.localVariables.projectId) const projectID = useSelector((store)=>store.localVariables.projectId)
@ -50,7 +51,7 @@ const EmployeeProfile = () => {
} }
}, [employeeId]); }, [employeeId]);
const navigate = useNavigate();
const renderContent = () => { const renderContent = () => {
if (loading) return <div>Loading</div>; if (loading) return <div>Loading</div>;
switch (activePill) { switch (activePill) {
@ -110,62 +111,69 @@ const EmployeeProfile = () => {
<div className="card-body"> <div className="card-body">
<div className="d-flex flex-row flex-lg-column"> <div className="d-flex flex-row flex-lg-column">
<div className="d-flex flex-column justify-content-center align-items-center text-center"> <div className="d-flex flex-column justify-content-center align-items-center text-center">
<img <Avatar
src={`../../../public/img/avatars/${currentEmployee.gender}.jpg`} firstName={`${currentEmployee?.firstName}`}
alt="user-avatar" lastName={`${currentEmployee?.lastName}`}
className="d-block rounded" size={"lg"}
height="100"
width="100"
aria-label="Account image"
id="uploadedAvatar"
/> />
<div className="py-2"> <div className="py-2">
<p className="h6">{`${currentEmployee?.firstName} ${currentEmployee?.lastName}`}</p> <p className="h6">{`${currentEmployee?.firstName} ${currentEmployee?.lastName}`}</p>
</div> </div>
<hr className="my-2" />
</div> </div>
<div className="w-100 d-flex flex-row flex-sm-column justify-content-sm-start justify-content-around"> <div className="w-100 d-flex flex-column justify-content-start">
<div className="text-wrap"> <div className="mt-3 w-100">
<small className="card-text text-uppercase text-muted small">Contacts</small> <h6 className="mb-2 text-muted text-start">Employee Info</h6>
<ul className="list-unstyled my-3 py-1"> <table className="table table-borderless mb-3">
<tbody>
<tr>
<td className="fw-medium text-start">Email:</td>
<td className="text-start">{currentEmployee?.email || <em>NA</em>}</td>
</tr>
<tr>
<td className="fw-medium text-start">Phone Number:</td>
<td className="text-start">{currentEmployee?.phoneNumber || <em>NA</em>}</td>
</tr>
<tr>
<td className="fw-medium text-start">Emergency Contact Person:</td>
<td className="text-start">{currentEmployee?.emergencyContactPerson || <em>NA</em>}</td>
</tr>
<tr>
<td className="fw-medium text-start">Emergency Contact Number:</td>
<td className="text-start">{currentEmployee?.emergencyPhoneNumber || <em>NA</em>}</td>
</tr>
<li className="d-flex align-items-center mb-4"> <tr>
<i className="bx bx-phone"></i> <td className="fw-medium text-start">Gender:</td>
<span className="fw-medium mx-2">Contact Number:</span> <td className="text-start">{currentEmployee?.gender || <em>NA</em>}</td>
<span className={`${currentEmployee?.emergencyPhoneNumber ? "" : "text-muted"}`}> </tr>
{currentEmployee?.emergencyPhoneNumber || <em>NA</em>} <tr>
</span> <td className="fw-medium text-start">Birth Date:</td>
</li> <td className="text-start">{currentEmployee?.birthDate ? new Date(currentEmployee.birthDate).toLocaleDateString() : <em>NA</em>}</td>
<li className="d-flex align-items-center mb-4 text-start"> </tr>
<i className="bx bx-envelope"></i>
<span className="fw-medium mx-2">Email:</span>
<span className={`text-break text-wrap ${currentEmployee?.email ? "" : "text-muted"}`}>
{currentEmployee?.email || <em className="muted">NA</em>}
</span>
</li>
<li className="d-flex align-items-center mb-4">
<i className="bx bx-user"></i>
<span className="fw-medium mx-2">Contact Person:</span>
<span className="">
{currentEmployee?.emergencyContactPerson}
</span>
</li>
<li className="d-flex align-items-center text-wrap ">
<i className="bx bx-flag"></i>
<span className="fw-medium mx-2">Address:</span>
</li>
<li className="d-flex align-items-start test-start mb-2">
<span className={`${currentEmployee?.permanentAddress ? "" : "ms-4"}`}>
{currentEmployee?.permanentAddress}
</span>
</li>
</ul> <tr>
</div> <td className="fw-medium text-start">Joining Date:</td>
<td className="text-start">{currentEmployee?.joiningDate ? new Date(currentEmployee.joiningDate).toLocaleDateString() : <em>NA</em>}</td>
</tr>
<tr>
<td className="fw-medium text-start">Job Role:</td>
<td className="text-start">{currentEmployee?.jobRole || <em>NA</em>}</td>
</tr>
<tr>
<td className="fw-medium text-start">Address:</td>
<td className="text-start">{currentEmployee?.currentAddress || <em>NA</em>}</td>
</tr>
</tbody>
</table>
</div>
<button className="btn btn-primary btn-block" onClick={() => navigate(`/employee/manage/${currentEmployee?.id}`)}>
Edit Profile
</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>