diff --git a/src/components/AdvancePayment/AdvancePaymentList.jsx b/src/components/AdvancePayment/AdvancePaymentList.jsx
new file mode 100644
index 00000000..358da905
--- /dev/null
+++ b/src/components/AdvancePayment/AdvancePaymentList.jsx
@@ -0,0 +1,13 @@
+import React from 'react'
+import { useEmployeesName } from '../../hooks/useEmployees'
+
+const AdvancePaymentList = ({employeeId}) => {
+
+ return (
+
+
+
+ )
+}
+
+export default AdvancePaymentList
diff --git a/src/components/common/EmployeeSearchInput.jsx b/src/components/common/EmployeeSearchInput.jsx
index 34fdecaa..c0bdbb0e 100644
--- a/src/components/common/EmployeeSearchInput.jsx
+++ b/src/components/common/EmployeeSearchInput.jsx
@@ -1,9 +1,11 @@
-import { useState, useEffect } from "react";
+import { useState, useEffect, useRef } from "react";
import { useEmployeesName } from "../../hooks/useEmployees";
import { useDebounce } from "../../utils/appUtils";
import { useController } from "react-hook-form";
import Avatar from "./Avatar";
+
+
const EmployeeSearchInput = ({
control,
name,
@@ -18,6 +20,8 @@ const EmployeeSearchInput = ({
const [search, setSearch] = useState("");
const [showDropdown, setShowDropdown] = useState(false);
+ const dropdownRef = useRef(null);
+
const debouncedSearch = useDebounce(search, 500);
const { data: employees, isLoading } = useEmployeesName(
@@ -30,62 +34,80 @@ const EmployeeSearchInput = ({
if (value && employees?.data) {
const found = employees.data.find((emp) => emp.id === value);
if (found && forAll) {
- setSearch(found.firstName + " " + found.lastName);
+ setSearch(`${found.firstName} ${found.lastName}`);
}
}
- }, [value, employees?.data]);
+ }, [value, employees?.data, forAll]);
const handleSelect = (employee) => {
onChange(employee.id);
- setSearch(employee.firstName + " " + employee.lastName);
+ setSearch(`${employee.firstName} ${employee.lastName}`);
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 (
-
+
{
setSearch(e.target.value);
setShowDropdown(true);
- onChange("");
- }}
- onFocus={() => {
- if (search) setShowDropdown(true);
+ onChange(""); // Clear previous value
}}
+ onFocus={() => setShowDropdown(true)}
/>
{showDropdown && (employees?.data?.length > 0 || isLoading) && (
{isLoading ? (
- -
- Searching...
-
+ - Searching...
) : (
employees?.data?.map((emp) => (
- handleSelect(emp)}
>
-
+
-
- {`${emp?.firstName} ${emp?.lastName}`.trim()}
-
+
{`${emp.firstName} ${emp.lastName}`}
))
@@ -93,9 +115,11 @@ const EmployeeSearchInput = ({
)}
- {error &&
{error.message}}
+ {error &&
{error.message}}
);
};
+
+
export default EmployeeSearchInput;
diff --git a/src/pages/AdvancePayment/AdvancePaymentPage.jsx b/src/pages/AdvancePayment/AdvancePaymentPage.jsx
index 7ee896b6..978f9dff 100644
--- a/src/pages/AdvancePayment/AdvancePaymentPage.jsx
+++ b/src/pages/AdvancePayment/AdvancePaymentPage.jsx
@@ -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 = () => {
- return (
-
-
-
- )
-}
+ const { control, watch } = useForm({
+ defaultValues: {
+ employeeId: "",
+ },
+ });
-export default AdvancePaymentPage
+ const selectedEmployeeId = watch("employeeId");
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default AdvancePaymentPage;