您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

82 行
2.4 KiB

  1. "use client";
  2. import { ProjectResult } from "@/app/api/projects";
  3. import React, { useMemo, useState, useCallback } 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. import VisibilityIcon from '@mui/icons-material/Visibility';
  9. import { useRouter, useSearchParams } from "next/navigation";
  10. interface Props {
  11. projects: TeamProjectResult[];
  12. }
  13. type SearchQuery = Partial<Omit<TeamProjectResult, "id">>;
  14. type SearchParamNames = keyof SearchQuery;
  15. const ProgressByClientSearch: React.FC<Props> = ({ projects }) => {
  16. const { t } = useTranslation("projects");
  17. const router = useRouter();
  18. // If project searching is done on the server-side, then no need for this.
  19. const [filteredProjects, setFilteredProjects] = useState(projects);
  20. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  21. () => [
  22. { label: "Team Code", paramName: "teamCode", type: "text" },
  23. { label: "Team Name", paramName: "teamName", type: "text" },
  24. ],
  25. [t],
  26. );
  27. const onTaskClick = useCallback(async (teamProjectResult: TeamProjectResult) => {
  28. try {
  29. console.log(teamProjectResult)
  30. router.push(
  31. `/dashboard/ProjectStatusByTeam?teamLeadId=${teamProjectResult.teamLeadId}`
  32. );
  33. } catch (error) {
  34. console.error('Error fetching team projects:', error);
  35. }
  36. }, []);
  37. const columns = useMemo<Column<TeamProjectResult>[]>(
  38. () => [
  39. {
  40. name: "id",
  41. label: t("Details"),
  42. onClick: onTaskClick,
  43. buttonIcon: <VisibilityIcon />,
  44. },
  45. { name: "teamCode", label: t("Team Code") },
  46. { name: "teamName", label: t("Team Name") },
  47. { name: "projectNo", label: t("No. of Projects") },
  48. ],
  49. [onTaskClick, t],
  50. );
  51. return (
  52. <>
  53. <SearchBox
  54. criteria={searchCriteria}
  55. onSearch={(query) => {
  56. setFilteredProjects(
  57. projects.filter(
  58. (cp) =>
  59. cp.teamCode.toLowerCase().includes(query.teamCode.toLowerCase()) &&
  60. cp.teamName.toLowerCase().includes(query.teamName.toLowerCase())
  61. ),
  62. );
  63. }}
  64. />
  65. <SearchResults<TeamProjectResult>
  66. items={filteredProjects}
  67. columns={columns}
  68. />
  69. </>
  70. );
  71. };
  72. export default ProgressByClientSearch;