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.
 
 

49 regels
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 { EX02ProjectCashFlowReportFilter } from "@/app/api/reports";
  7. import { fetchEX02ProjectCashFlowReport } from "@/app/api/reports/actions";
  8. import { downloadFile } from "@/app/utils/commonUtil";
  9. import { BASE_API_URL } from "@/config/api";
  10. interface Props {
  11. projects: ProjectResult[];
  12. }
  13. type SearchQuery = Partial<Omit<EX02ProjectCashFlowReportFilter, "id">>;
  14. type SearchParamNames = keyof SearchQuery;
  15. const GenerateEX02ProjectCashFlowReport: React.FC<Props> = ({ projects }) => {
  16. const { t } = useTranslation();
  17. const projectCombo = projects.map(project => `${project.code} - ${project.name}`)
  18. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  19. () => [
  20. { label: t("Project"), paramName: "project", type: "select", options: projectCombo, needAll: false},
  21. ],
  22. [t],
  23. );
  24. return (
  25. <>
  26. <SearchBox
  27. criteria={searchCriteria}
  28. onSearch={async (query) => {
  29. if (query.project.length > 0 && query.project.toLocaleLowerCase() !== "all") {
  30. const projectIndex = projectCombo.findIndex(project => project === query.project)
  31. const response = await fetchEX02ProjectCashFlowReport({ projectId: projects[projectIndex].id })
  32. if (response) {
  33. downloadFile(new Uint8Array(response.blobValue), response.filename!!)
  34. }
  35. }
  36. }}
  37. />
  38. </>
  39. );
  40. };
  41. export default GenerateEX02ProjectCashFlowReport;