Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

58 lignes
1.7 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 { ClientProjectResult } from "@/app/api/clientprojects";
  8. interface Props {
  9. projects: ClientProjectResult[];
  10. }
  11. type SearchQuery = Partial<Omit<ClientProjectResult, "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: "Client Code", paramName: "clientCode", type: "text" },
  20. { label: "Client Name", paramName: "clientName", type: "text" },
  21. ],
  22. [t],
  23. );
  24. const columns = useMemo<Column<ClientProjectResult>[]>(
  25. () => [
  26. { name: "clientCode", label: t("Client Code") },
  27. { name: "clientName", label: t("Client Name") },
  28. { name: "SubsidiaryClientCode", label: t("Subsidiary Code") },
  29. { name: "SubsidiaryClientName", label: t("Subisdiary") },
  30. { name: "NoOfProjects", label: t("No. of Projects") },
  31. ],
  32. [t],
  33. );
  34. return (
  35. <>
  36. <SearchBox
  37. criteria={searchCriteria}
  38. onSearch={(query) => {
  39. console.log(query);
  40. }}
  41. />
  42. <SearchResults<ClientProjectResult>
  43. items={filteredProjects}
  44. columns={columns}
  45. />
  46. </>
  47. );
  48. };
  49. export default ProgressByClientSearch;