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

55 行
1.8 KiB

  1. "use client";
  2. import React, { useMemo } from "react";
  3. import SearchBox, { Criterion } from "../SearchBox";
  4. import { useTranslation } from "react-i18next";
  5. import { ProjectResult } from "@/app/api/projects";
  6. import { fetchMonthlyWorkHoursReport, fetchProjectCashFlowReport } from "@/app/api/reports/actions";
  7. import { downloadFile } from "@/app/utils/commonUtil";
  8. import { BASE_API_URL } from "@/config/api";
  9. import { MonthlyWorkHoursReportFilter } from "@/app/api/reports";
  10. import { records } from "@/app/api/staff/actions";
  11. import { StaffResult } from "@/app/api/staff";
  12. interface Props {
  13. staffs: StaffResult[]
  14. }
  15. type SearchQuery = Partial<Omit<MonthlyWorkHoursReportFilter, "id">>;
  16. type SearchParamNames = keyof SearchQuery;
  17. const GenerateMonthlyWorkHoursReport: React.FC<Props> = ({ staffs }) => {
  18. const { t } = useTranslation();
  19. const staffCombo = staffs.map(staff => `${staff.name} - ${staff.staffId}`)
  20. console.log(staffs)
  21. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  22. () => [
  23. { label: t("Staff"),
  24. paramName: "staff",
  25. type: "select",
  26. options: staffCombo,
  27. needAll: false},
  28. ],
  29. [t],
  30. );
  31. return (
  32. <>
  33. <SearchBox
  34. criteria={searchCriteria}
  35. onSearch={async (query: any) => {
  36. if (query.staff.length > 0 && query.staff.toLocaleLowerCase() !== "all") {
  37. const index = staffCombo.findIndex(staff => staff === query.staff)
  38. const response = await fetchMonthlyWorkHoursReport({ id: staffs[index].id, yearMonth: "2023-03" })
  39. if (response) {
  40. downloadFile(new Uint8Array(response.blobValue), response.filename!!)
  41. }
  42. }
  43. }
  44. }
  45. />
  46. </>
  47. )
  48. }
  49. export default GenerateMonthlyWorkHoursReport