Bladeren bron

update gen EX02 report

tags/Baseline_30082024_FRONTEND_UAT
cyril.tsui 1 jaar geleden
bovenliggende
commit
529c26d114
4 gewijzigde bestanden met toevoegingen van 21 en 26 verwijderingen
  1. +8
    -1
      src/app/api/reports/actions.ts
  2. +2
    -10
      src/app/utils/commonUtil.ts
  3. +7
    -5
      src/app/utils/fetchUtil.ts
  4. +4
    -10
      src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx

+ 8
- 1
src/app/api/reports/actions.ts Bestand weergeven

@@ -4,8 +4,13 @@ import { serverFetchBlob, serverFetchJson } from "@/app/utils/fetchUtil";
import { EX02ProjectCashFlowReportRequest } from ".";
import { BASE_API_URL } from "@/config/api";

export interface FileResponse {
filename: string;
blobValue: Uint8Array;
}

export const fetchEX02ProjectCashFlowReport = async (data: EX02ProjectCashFlowReportRequest) => {
const reportBlob = await serverFetchBlob(
const reportBlob = await serverFetchBlob<FileResponse>(
`${BASE_API_URL}/reports/EX02-ProjectCashFlowReport`,
{
method: "POST",
@@ -14,5 +19,7 @@ export const fetchEX02ProjectCashFlowReport = async (data: EX02ProjectCashFlowRe
},
);

console.log(reportBlob)

return reportBlob
};

+ 2
- 10
src/app/utils/commonUtil.ts Bestand weergeven

@@ -22,16 +22,8 @@ export const dateInRange = (currentDate: string, startDate: string, endDate: str
}
}

function s2ab(s: string) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}

export const downloadFile = (blob: Blob | string, type: string, filename: string) => {

const url = URL.createObjectURL(typeof blob === "string" ? new Blob([blob], { type: type }) : blob);
export const downloadFile = (blobData: Uint8Array, filename: string) => {
const url = URL.createObjectURL(new Blob([blobData]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", filename);


+ 7
- 5
src/app/utils/fetchUtil.ts Bestand weergeven

@@ -8,6 +8,7 @@ export const serverFetch: typeof fetch = async (input, init) => {
const session = await getServerSession<any, SessionWithTokens>(authOptions);
const accessToken = session?.accessToken;

console.log(accessToken)
return fetch(input, {
...init,
headers: {
@@ -56,15 +57,16 @@ export async function serverFetchWithNoContent(...args: FetchParams) {
}
}

export async function serverFetchBlob(...args: FetchParams) {
export async function serverFetchBlob<T>(...args: FetchParams) {
const response = await serverFetch(...args);

if (response.ok) {
console.log(response)
const blob = await response.blob()
const blobText = await blob.text();
const blobType = await blob.type;
return {filename: response.headers.get("filename"), blobText: blobText, blobType: blobType};
// const blob = await response.blob()
// const blobText = await blob.text();
// const blobType = await blob.type;
const blobValue = (await response.body?.getReader().read())!!.value!!
return {filename: response.headers.get("filename"), blobValue: blobValue} as T;
} else {
switch (response.status) {
case 401:


+ 4
- 10
src/components/GenerateEX02ProjectCashFlowReport/GenerateEX02ProjectCashFlowReport.tsx Bestand weergeven

@@ -7,6 +7,7 @@ import { ProjectResult } from "@/app/api/projects";
import { EX02ProjectCashFlowReportFilter } from "@/app/api/reports";
import { fetchEX02ProjectCashFlowReport } from "@/app/api/reports/actions";
import { downloadFile } from "@/app/utils/commonUtil";
import { BASE_API_URL } from "@/config/api";

interface Props {
projects: ProjectResult[];
@@ -21,7 +22,7 @@ const GenerateEX02ProjectCashFlowReport: React.FC<Props> = ({ projects }) => {

const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
() => [
{ label: t("Project"), paramName: "project", type: "select", options: projectCombo},
{ label: t("Project"), paramName: "project", type: "select", options: projectCombo },
],
[t],
);
@@ -32,17 +33,10 @@ const GenerateEX02ProjectCashFlowReport: React.FC<Props> = ({ projects }) => {
criteria={searchCriteria}
onSearch={async (query) => {
const projectIndex = projectCombo.findIndex(project => project === query.project)
const response = await fetchEX02ProjectCashFlowReport({projectId: projects[projectIndex].id})
console.log(response)
const response = await fetchEX02ProjectCashFlowReport({ projectId: projects[projectIndex].id })
if (response) {
downloadFile(response.blobText, response.blobType, response.filename!!)
downloadFile(new Uint8Array(response.blobValue), response.filename!!)
}

// const url = URL.createObjectURL(response.blob);
// const link = document.createElement("a");
// link.href = url;
// link.setAttribute("download", "abc.xlsx");
// link.click();
}}
/>
</>


Laden…
Annuleren
Opslaan