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

94 行
2.4 KiB

  1. "use client";
  2. import { ClaimResult } from "@/app/api/claims";
  3. import React, { useCallback, useMemo, useState } from "react";
  4. import SearchBox, { Criterion } from "../SearchBox/index";
  5. import { useTranslation } from "react-i18next";
  6. import SearchResults, { Column } from "../SearchResults/index";
  7. import EditNote from "@mui/icons-material/EditNote";
  8. interface Props {
  9. claims: ClaimResult[];
  10. }
  11. type SearchQuery = Partial<Omit<ClaimResult, "id">>;
  12. type SearchParamNames = keyof SearchQuery;
  13. const ClaimSearch: React.FC<Props> = ({ claims }) => {
  14. const { t } = useTranslation("claims");
  15. // If claim searching is done on the server-side, then no need for this.
  16. const [filteredClaims, setFilteredClaims] = useState(claims);
  17. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  18. () => [
  19. { label: t("Creation Date"), paramName: "created", type: "dateRange" },
  20. { label: t("Related Project Name"), paramName: "name", type: "text" },
  21. {
  22. label: t("Cost (HKD)"),
  23. paramName: "cost",
  24. type: "text",
  25. },
  26. {
  27. label: t("Expense Type"),
  28. paramName: "type",
  29. type: "select",
  30. options: ["Expense", "Petty Cash"],
  31. },
  32. {
  33. label: t("Status"),
  34. paramName: "status",
  35. type: "select",
  36. options: [
  37. "Not Submitted",
  38. "Waiting for Approval",
  39. "Approved",
  40. "Rejected",
  41. ],
  42. },
  43. {
  44. label: t("Remarks"),
  45. paramName: "remarks",
  46. type: "text",
  47. },
  48. ],
  49. [t],
  50. );
  51. const onClaimClick = useCallback((claim: ClaimResult) => {
  52. console.log(claim);
  53. }, []);
  54. const columns = useMemo<Column<ClaimResult>[]>(
  55. () => [
  56. // {
  57. // name: "action",
  58. // label: t("Actions"),
  59. // onClick: onClaimClick,
  60. // buttonIcon: <EditNote />,
  61. // },
  62. { name: "created", label: t("Creation Date") },
  63. { name: "name", label: t("Related Project Name") },
  64. { name: "cost", label: t("Cost (HKD)") },
  65. { name: "type", label: t("Expense Type") },
  66. { name: "status", label: t("Status") },
  67. { name: "remarks", label: t("Remarks") },
  68. ],
  69. [t, onClaimClick],
  70. );
  71. return (
  72. <>
  73. <SearchBox
  74. criteria={searchCriteria}
  75. onSearch={(query) => {
  76. console.log(query);
  77. }}
  78. />
  79. <SearchResults<ClaimResult> items={filteredClaims} columns={columns} />
  80. </>
  81. );
  82. };
  83. export default ClaimSearch;