added employee search box inside advance payment
This commit is contained in:
parent
196069b39a
commit
9c03303547
13
src/components/AdvancePayment/AdvancePaymentList.jsx
Normal file
13
src/components/AdvancePayment/AdvancePaymentList.jsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useEmployeesName } from '../../hooks/useEmployees'
|
||||||
|
|
||||||
|
const AdvancePaymentList = ({employeeId}) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='row'>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdvancePaymentList
|
||||||
@ -1,9 +1,11 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { useEmployeesName } from "../../hooks/useEmployees";
|
import { useEmployeesName } from "../../hooks/useEmployees";
|
||||||
import { useDebounce } from "../../utils/appUtils";
|
import { useDebounce } from "../../utils/appUtils";
|
||||||
import { useController } from "react-hook-form";
|
import { useController } from "react-hook-form";
|
||||||
import Avatar from "./Avatar";
|
import Avatar from "./Avatar";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EmployeeSearchInput = ({
|
const EmployeeSearchInput = ({
|
||||||
control,
|
control,
|
||||||
name,
|
name,
|
||||||
@ -18,6 +20,8 @@ const EmployeeSearchInput = ({
|
|||||||
|
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [showDropdown, setShowDropdown] = useState(false);
|
const [showDropdown, setShowDropdown] = useState(false);
|
||||||
|
const dropdownRef = useRef(null);
|
||||||
|
|
||||||
const debouncedSearch = useDebounce(search, 500);
|
const debouncedSearch = useDebounce(search, 500);
|
||||||
|
|
||||||
const { data: employees, isLoading } = useEmployeesName(
|
const { data: employees, isLoading } = useEmployeesName(
|
||||||
@ -30,62 +34,80 @@ const EmployeeSearchInput = ({
|
|||||||
if (value && employees?.data) {
|
if (value && employees?.data) {
|
||||||
const found = employees.data.find((emp) => emp.id === value);
|
const found = employees.data.find((emp) => emp.id === value);
|
||||||
if (found && forAll) {
|
if (found && forAll) {
|
||||||
setSearch(found.firstName + " " + found.lastName);
|
setSearch(`${found.firstName} ${found.lastName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [value, employees?.data]);
|
}, [value, employees?.data, forAll]);
|
||||||
|
|
||||||
const handleSelect = (employee) => {
|
const handleSelect = (employee) => {
|
||||||
onChange(employee.id);
|
onChange(employee.id);
|
||||||
setSearch(employee.firstName + " " + employee.lastName);
|
setSearch(`${employee.firstName} ${employee.lastName}`);
|
||||||
setShowDropdown(false);
|
setShowDropdown(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event) => {
|
||||||
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
||||||
|
setShowDropdown(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEsc = (event) => {
|
||||||
|
if (event.key === "Escape") setShowDropdown(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
|
document.addEventListener("keydown", handleEsc);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("mousedown", handleClickOutside);
|
||||||
|
document.removeEventListener("keydown", handleEsc);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="position-relative">
|
<div className="position-relative" ref={dropdownRef}>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="search"
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={`form-control form-control-sm`}
|
className="form-control form-control-sm"
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
value={search}
|
value={search}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setSearch(e.target.value);
|
setSearch(e.target.value);
|
||||||
setShowDropdown(true);
|
setShowDropdown(true);
|
||||||
onChange("");
|
onChange(""); // Clear previous value
|
||||||
}}
|
|
||||||
onFocus={() => {
|
|
||||||
if (search) setShowDropdown(true);
|
|
||||||
}}
|
}}
|
||||||
|
onFocus={() => setShowDropdown(true)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showDropdown && (employees?.data?.length > 0 || isLoading) && (
|
{showDropdown && (employees?.data?.length > 0 || isLoading) && (
|
||||||
<ul
|
<ul
|
||||||
className="list-group position-absolute bg-white w-100 shadow z-3 rounded-none px-0"
|
className="list-group position-absolute bg-white w-100 shadow z-3 rounded-1 px-0"
|
||||||
style={{ maxHeight: 200, overflowY: "auto" }}
|
style={{
|
||||||
|
maxHeight: 200,
|
||||||
|
overflowY: "auto",
|
||||||
|
zIndex: 1050, // ensure above Bootstrap elements
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<li className="list-group-item">
|
<li className="list-group-item py-1 px-2 text-muted">Searching...</li>
|
||||||
<a>Searching...</a>
|
|
||||||
</li>
|
|
||||||
) : (
|
) : (
|
||||||
employees?.data?.map((emp) => (
|
employees?.data?.map((emp) => (
|
||||||
<li
|
<li
|
||||||
key={emp.id}
|
key={emp.id}
|
||||||
className="list-group-item list-group-item-action py-1 px-1"
|
className="list-group-item list-group-item-action py-1 px-2"
|
||||||
style={{ cursor: "pointer" }}
|
style={{ cursor: "pointer" }}
|
||||||
onClick={() => handleSelect(emp)}
|
onClick={() => handleSelect(emp)}
|
||||||
>
|
>
|
||||||
<div className="d-flex align-items-center px-0">
|
<div className="d-flex align-items-center">
|
||||||
<Avatar
|
<Avatar
|
||||||
size="xs"
|
size="xs"
|
||||||
classAvatar="m-0 me-2"
|
classAvatar="m-0 me-2"
|
||||||
firstName={emp.firstName}
|
firstName={emp.firstName}
|
||||||
lastName={emp.lastName}
|
lastName={emp.lastName}
|
||||||
/>
|
/>
|
||||||
<span className="text-muted">
|
<span className="text-muted">{`${emp.firstName} ${emp.lastName}`}</span>
|
||||||
{`${emp?.firstName} ${emp?.lastName}`.trim()}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
))
|
))
|
||||||
@ -93,9 +115,11 @@ const EmployeeSearchInput = ({
|
|||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{error && <small className="danger-text">{error.message}</small>}
|
{error && <small className="text-danger">{error.message}</small>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default EmployeeSearchInput;
|
export default EmployeeSearchInput;
|
||||||
|
|||||||
@ -1,11 +1,44 @@
|
|||||||
import React from 'react'
|
import React from "react";
|
||||||
|
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||||
|
import { useEmployee } from "../../hooks/useEmployees";
|
||||||
|
import EmployeeSearchInput from "../../components/common/EmployeeSearchInput";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import Label from "../../components/common/Label";
|
||||||
|
|
||||||
const AdvancePaymentPage = () => {
|
const AdvancePaymentPage = () => {
|
||||||
return (
|
const { control, watch } = useForm({
|
||||||
<div>
|
defaultValues: {
|
||||||
|
employeeId: "",
|
||||||
</div>
|
},
|
||||||
)
|
});
|
||||||
}
|
|
||||||
|
|
||||||
export default AdvancePaymentPage
|
const selectedEmployeeId = watch("employeeId");
|
||||||
|
return (
|
||||||
|
<div className="container-fluid">
|
||||||
|
<Breadcrumb
|
||||||
|
data={[
|
||||||
|
{ label: "Home", link: "/" },
|
||||||
|
{ label: "Finance", link: "/advance-payment" },
|
||||||
|
{ label: "Advance Payment" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<div className="card px-2 py-2 page-min-h">
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12 ">
|
||||||
|
<div className="d-block w-max w-25 text-start" >
|
||||||
|
<Label>Search Employee</Label>
|
||||||
|
<EmployeeSearchInput
|
||||||
|
control={control}
|
||||||
|
name="paidById"
|
||||||
|
projectId={null}
|
||||||
|
forAll={true}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AdvancePaymentPage;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user