|
|
@@ -0,0 +1,87 @@ |
|
|
|
"use client"; |
|
|
|
|
|
|
|
import { CompanyResult } from "@/app/api/companys"; |
|
|
|
import React, { useCallback, useMemo, useState } from "react"; |
|
|
|
import SearchBox, { Criterion } from "../SearchBox"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import SearchResults, { Column } from "../SearchResults"; |
|
|
|
import EditNote from "@mui/icons-material/EditNote"; |
|
|
|
import uniq from "lodash/uniq"; |
|
|
|
|
|
|
|
interface Props { |
|
|
|
companys: CompanyResult[]; |
|
|
|
} |
|
|
|
|
|
|
|
type SearchQuery = Partial<Omit<CompanyResult, "id">>; |
|
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
const CompanySearch: React.FC<Props> = ({ companys }) => { |
|
|
|
const { t } = useTranslation("companys"); |
|
|
|
|
|
|
|
const [filteredCompanys, setFilteredCompanys] = useState(companys); |
|
|
|
|
|
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
|
() => [ |
|
|
|
{ label: t("Company code"), paramName: "companyCode", type: "text" }, |
|
|
|
{ label: t("Company name"), paramName: "name", type: "text" }, |
|
|
|
{ label: t("Contact Name"), paramName: "contactName", type: "text" }, |
|
|
|
{ label: t("Contact Number"), paramName: "phone", type: "text" }, |
|
|
|
], |
|
|
|
[t, companys], |
|
|
|
); |
|
|
|
|
|
|
|
const onReset = useCallback(() => { |
|
|
|
setFilteredCompanys(companys); |
|
|
|
}, [companys]); |
|
|
|
|
|
|
|
const onProjectClick = useCallback((project: CompanyResult) => { |
|
|
|
console.log(project); |
|
|
|
}, []); |
|
|
|
|
|
|
|
const columns = useMemo<Column<CompanyResult>[]>( |
|
|
|
() => [ |
|
|
|
{ |
|
|
|
name: "id", |
|
|
|
label: t("Details"), |
|
|
|
onClick: onProjectClick, |
|
|
|
buttonIcon: <EditNote />, |
|
|
|
}, |
|
|
|
{ name: "companyCode", label: t("Company Code") }, |
|
|
|
{ name: "name", label: t("Company Name") }, |
|
|
|
{ name: "brNo", label: t("brNo") }, |
|
|
|
{ name: "contactName", label: t("Contact Name") }, |
|
|
|
{ name: "phone", label: t("Contact No.") }, |
|
|
|
{ name: "email", label: t("Contact Email") } |
|
|
|
], |
|
|
|
[t, onProjectClick], |
|
|
|
); |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<SearchBox |
|
|
|
criteria={searchCriteria} |
|
|
|
onSearch={(query) => { |
|
|
|
setFilteredCompanys( |
|
|
|
companys.filter( |
|
|
|
(p) => |
|
|
|
p.companyCode.toLowerCase().includes(query.companyCode.toLowerCase()) && |
|
|
|
p.name.toLowerCase().includes(query.name.toLowerCase()) && |
|
|
|
p.contactName.toLowerCase().includes(query.contactName.toLowerCase()) && |
|
|
|
p.phone.toLowerCase().includes(query.phone.toLowerCase()) && |
|
|
|
{/*(query.client === "All" || p.client === query.client) && |
|
|
|
(query.category === "All" || p.category === query.category) && |
|
|
|
(query.team === "All" || p.team === query.team), **/} |
|
|
|
), |
|
|
|
); |
|
|
|
}} |
|
|
|
onReset={onReset} |
|
|
|
/> |
|
|
|
<SearchResults<CompanyResult> |
|
|
|
items={filteredCompanys} |
|
|
|
columns={columns} |
|
|
|
/> |
|
|
|
</> |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
export default CompanySearch; |