|
|
@@ -0,0 +1,53 @@ |
|
|
|
"use client"; |
|
|
|
|
|
|
|
import React, { useMemo } from "react"; |
|
|
|
import SearchBox, { Criterion } from "../SearchBox"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import { ProjectPotentialDelayReportFilter } from "@/app/api/reports"; |
|
|
|
import { fetchProjectCashFlowReport, fetchProjectPotentialDelayReport } from "@/app/api/reports/actions"; |
|
|
|
import { downloadFile } from "@/app/utils/commonUtil"; |
|
|
|
import { TeamResult } from "@/app/api/team"; |
|
|
|
import { Customer } from "@/app/api/customer"; |
|
|
|
|
|
|
|
interface Props { |
|
|
|
teams: TeamResult[]; |
|
|
|
clients: Customer[]; |
|
|
|
} |
|
|
|
|
|
|
|
type SearchQuery = Partial<Omit<ProjectPotentialDelayReportFilter, "id">>; |
|
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
const GenerateProjectPotentialDelayReport: React.FC<Props> = ({ teams, clients }) => { |
|
|
|
const { t } = useTranslation("report"); |
|
|
|
const teamCombo = teams.map(team => `${team.code} - ${team.name}`) |
|
|
|
const clientCombo = clients.map(client => `${client.code} - ${client.name}`) |
|
|
|
|
|
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
|
() => [ |
|
|
|
{ label: t("Team"), paramName: "team", type: "select", options: teamCombo }, |
|
|
|
{ label: t("Client"), paramName: "client", type: "select", options: clientCombo }, |
|
|
|
], |
|
|
|
[t], |
|
|
|
); |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<SearchBox |
|
|
|
criteria={searchCriteria} |
|
|
|
onSearch={async (query) => { |
|
|
|
|
|
|
|
const teamIndex = teamCombo.findIndex(team => team === query.team) |
|
|
|
const clientIndex = clientCombo.findIndex(client => client === query.client) |
|
|
|
|
|
|
|
const response = await fetchProjectPotentialDelayReport({ teamId: teams[teamIndex]?.id ?? "All", clientId: clients[clientIndex]?.id ?? "All" }) |
|
|
|
if (response) { |
|
|
|
downloadFile(new Uint8Array(response.blobValue), response.filename!!) |
|
|
|
} |
|
|
|
}} |
|
|
|
formType={"download"} |
|
|
|
/> |
|
|
|
</> |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
export default GenerateProjectPotentialDelayReport; |