You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 line
1.5 KiB

  1. "use client";
  2. import { ProjectResult } from "@/app/api/projects";
  3. import React, { useMemo, useState } from "react";
  4. import SearchBox, { Criterion } from "../SearchBox";
  5. import { useTranslation } from "react-i18next";
  6. import SearchResults, { Column } from "../SearchResults";
  7. import { TeamProjectResult } from "@/app/api/teamprojects";
  8. interface Props {
  9. projects: TeamProjectResult[];
  10. }
  11. type SearchQuery = Partial<Omit<TeamProjectResult, "id">>;
  12. type SearchParamNames = keyof SearchQuery;
  13. const ProgressByClientSearch: React.FC<Props> = ({ projects }) => {
  14. const { t } = useTranslation("projects");
  15. // If project searching is done on the server-side, then no need for this.
  16. const [filteredProjects, setFilteredProjects] = useState(projects);
  17. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  18. () => [
  19. { label: "Team Code", paramName: "teamCode", type: "text" },
  20. { label: "Team Name", paramName: "teamName", type: "text" },
  21. ],
  22. [t],
  23. );
  24. const columns = useMemo<Column<TeamProjectResult>[]>(
  25. () => [
  26. { name: "teamCode", label: t("Team Code") },
  27. { name: "teamName", label: t("Team Name") },
  28. { name: "NoOfProjects", label: t("No. of Projects") },
  29. ],
  30. [t],
  31. );
  32. return (
  33. <>
  34. <SearchBox
  35. criteria={searchCriteria}
  36. onSearch={(query) => {
  37. console.log(query);
  38. }}
  39. />
  40. <SearchResults<TeamProjectResult>
  41. items={filteredProjects}
  42. columns={columns}
  43. />
  44. </>
  45. );
  46. };
  47. export default ProgressByClientSearch;