This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { SearchNormal } from "iconsax-react";
|
import { SearchNormal } from "iconsax-react";
|
||||||
import { FC, InputHTMLAttributes, useEffect, useState } from "react";
|
import { FC, InputHTMLAttributes, useEffect, useRef, useState } from "react";
|
||||||
import EyeIcon from "../assets/images/eye.svg";
|
import EyeIcon from "../assets/images/eye.svg";
|
||||||
import { clx } from "../helpers/utils";
|
import { clx } from "../helpers/utils";
|
||||||
import Error from "./Error";
|
import Error from "./Error";
|
||||||
@@ -30,6 +30,8 @@ const Input: FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
const [showPassword, setShowPassword] = useState<boolean>(false);
|
const [showPassword, setShowPassword] = useState<boolean>(false);
|
||||||
const [search, setSearch] = useState<string>("");
|
const [search, setSearch] = useState<string>("");
|
||||||
|
const onChangeSearchFinalRef = useRef(props.onChangeSearchFinal);
|
||||||
|
onChangeSearchFinalRef.current = props.onChangeSearchFinal;
|
||||||
|
|
||||||
const inputClass = clx(
|
const inputClass = clx(
|
||||||
"w-full h-10 text-black block px-4 text-xs rounded-xl border border-border",
|
"w-full h-10 text-black block px-4 text-xs rounded-xl border border-border",
|
||||||
@@ -68,13 +70,13 @@ const Input: FC<Props> = (props: Props) => {
|
|||||||
}, [props.value]);
|
}, [props.value]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.variant === "search" && props.onChangeSearchFinal) {
|
if (props.variant !== "search" || !onChangeSearchFinalRef.current) return;
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
props.onChangeSearchFinal?.(search);
|
const timeout = setTimeout(() => {
|
||||||
}, 1000);
|
onChangeSearchFinalRef.current?.(search);
|
||||||
return () => clearTimeout(timeout);
|
}, 1000);
|
||||||
}
|
return () => clearTimeout(timeout);
|
||||||
}, [search, props]);
|
}, [search, props.variant]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ const CustomerList: FC = () => {
|
|||||||
const getCustomers = useGetCustomers(page, limit, false, search);
|
const getCustomers = useGetCustomers(page, limit, false, search);
|
||||||
|
|
||||||
const handleSearch = (value: string) => {
|
const handleSearch = (value: string) => {
|
||||||
setPage(1);
|
if (value !== search) {
|
||||||
|
setPage(1);
|
||||||
|
}
|
||||||
setSearch(value);
|
setSearch(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user