mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
refactor(FE): Refactor table column definitions to remove unused row
parameter
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { generateProductionResultExcel } from '../export/ProductionResultExportXLSX';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
import { Icon } from '@iconify/react';
|
||||
@@ -161,11 +162,79 @@ const ProductionResultContent = () => {
|
||||
const exportToExcelHandler = async () => {
|
||||
setIsLoadingExportingToExcel(true);
|
||||
|
||||
await ProductionResultReportApi.exportProductionResultToExcel(
|
||||
projectFlockKandangs
|
||||
);
|
||||
try {
|
||||
let projectFlockKandangsData: BaseProjectFlockKandang[] = [];
|
||||
|
||||
setIsLoadingExportingToExcel(false);
|
||||
if (selectedProjectFlockKandang) {
|
||||
const projectFlockKandangResponse =
|
||||
await ProjectFlockKandangApi.getSingle(
|
||||
selectedProjectFlockKandang?.value as number
|
||||
);
|
||||
|
||||
projectFlockKandangsData = isResponseSuccess(
|
||||
projectFlockKandangResponse
|
||||
)
|
||||
? [projectFlockKandangResponse.data]
|
||||
: [];
|
||||
} else {
|
||||
const projectFlockKandangsResponse =
|
||||
await ProjectFlockKandangApi.getAll({
|
||||
area_id: selectedArea?.value,
|
||||
project_flock_id: selectedProjectFlock?.value,
|
||||
});
|
||||
|
||||
projectFlockKandangsData = isResponseSuccess(
|
||||
projectFlockKandangsResponse
|
||||
)
|
||||
? projectFlockKandangsResponse.data
|
||||
: [];
|
||||
}
|
||||
|
||||
const productionResultData: ProductionResult[] = [];
|
||||
|
||||
for (const kandang of projectFlockKandangsData) {
|
||||
const getProductionResultPath = `${ProductionResultReportApi.basePath}/${kandang.id}?page=1&limit=100`;
|
||||
const getProductionResultRes = await httpClient<
|
||||
BaseApiResponse<ProductionResult[]>
|
||||
>(getProductionResultPath);
|
||||
|
||||
if (isResponseSuccess(getProductionResultRes)) {
|
||||
productionResultData.push(
|
||||
...(getProductionResultRes.data?.map((result) => ({
|
||||
...result,
|
||||
project_flock: {
|
||||
...result.project_flock,
|
||||
name:
|
||||
selectedProjectFlock?.label ||
|
||||
kandang.project_flock?.name ||
|
||||
`Project Flock #${kandang.project_flock_id}`,
|
||||
category: kandang.project_flock?.category || '',
|
||||
kandang: {
|
||||
...result.project_flock?.kandang,
|
||||
name:
|
||||
kandang.kandang?.name || `Kandang #${kandang.kandang_id}`,
|
||||
},
|
||||
},
|
||||
})) || [])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (productionResultData.length === 0) {
|
||||
toast.error('Tidak ada data untuk diexport.');
|
||||
setIsLoadingExportingToExcel(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await generateProductionResultExcel({
|
||||
data: productionResultData,
|
||||
period: '',
|
||||
});
|
||||
} catch {
|
||||
toast.error('Gagal melakukan export laporan hasil produksi! Coba lagi.');
|
||||
} finally {
|
||||
setIsLoadingExportingToExcel(false);
|
||||
}
|
||||
};
|
||||
|
||||
const exportToPdfHandler = async () => {
|
||||
|
||||
Reference in New Issue
Block a user