From d879acc001e69b48ca94db0b976bd7c6b823f118 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Mon, 12 Jan 2026 12:44:28 +0700 Subject: [PATCH] feat(FE): workaround general information closing kandang --- src/app/closing/detail/page.tsx | 27 +++++++++- .../pages/closing/ClosingDetail.tsx | 20 +++++++- .../ClosingGeneralInformationTable.tsx | 49 ++++++++++++++++--- .../pages/closing/ClosingKandangList.tsx | 37 ++++++++++++++ 4 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 src/components/pages/closing/ClosingKandangList.tsx diff --git a/src/app/closing/detail/page.tsx b/src/app/closing/detail/page.tsx index f3a78d9d..079cc876 100644 --- a/src/app/closing/detail/page.tsx +++ b/src/app/closing/detail/page.tsx @@ -7,18 +7,33 @@ import ClosingDetail from '@/components/pages/closing/ClosingDetail'; import { ClosingApi } from '@/services/api/closing'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; +import { FlockApi } from '@/services/api/master-data'; +import { ProjectFlockApi } from '@/services/api/production/project-flock'; +import { ProjectFlockKandangApi } from '@/services/api/production'; const ClosingDetailPage = () => { const router = useRouter(); const searchParams = useSearchParams(); const closingId = searchParams.get('closingId'); + const kandangId = searchParams.get('kandangId'); // project flock kandang ID const { data: closing, isLoading: isLoadingClosing } = useSWR( closingId, (id: number) => ClosingApi.getGeneralInfo(id) ); + // WORKAROUND - get flock data from closing ID + const { data: projectData, isLoading: isLoadingProject } = useSWR( + `flock-${closingId}`, + () => ProjectFlockApi.getSingle(Number(closingId)) + ); + // WORKAROUND - get kandang data from closing ID + const { data: kandangData, isLoading: isLoadingKandang } = useSWR( + kandangId ? `kandang-${closingId}-${kandangId}` : null, + () => ProjectFlockKandangApi.getSingle(Number(kandangId)) + ); + // const { data: salesData, isLoading: isLoadingSales } = useSWR( // closingId ? `sales-${closingId}` : null, // () => ClosingApi.getPenjualan(Number(closingId)) @@ -44,7 +59,11 @@ const ClosingDetailPage = () => { return; } - const isLoading = isLoadingClosing || isLoadingHppEkspedisi; + const isLoading = + isLoadingClosing || + isLoadingHppEkspedisi || + isLoadingProject || + isLoadingKandang; // const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi; return ( @@ -61,6 +80,12 @@ const ClosingDetailPage = () => { ? hppEkspedisiData.data : undefined } + projectData={ + isResponseSuccess(projectData) ? projectData.data : undefined + } + kandangData={ + isResponseSuccess(kandangData) ? kandangData.data : undefined + } /> )} diff --git a/src/components/pages/closing/ClosingDetail.tsx b/src/components/pages/closing/ClosingDetail.tsx index 778124be..31868830 100644 --- a/src/components/pages/closing/ClosingDetail.tsx +++ b/src/components/pages/closing/ClosingDetail.tsx @@ -19,12 +19,17 @@ import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverhea import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent'; import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable'; import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable'; +import ClosingKandangList from '@/components/pages/closing/ClosingKandangList'; +import { ProjectFlock } from '@/types/api/production/project-flock'; +import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang'; interface ClosingDetailProps { id: number; initialValue?: ClosingGeneralInformation; salesData?: BaseClosingSales; hppExpeditionData?: ClosingHppExpedition; + projectData?: ProjectFlock; + kandangData?: ProjectFlockKandang; } const ClosingDetail: React.FC = ({ @@ -32,6 +37,8 @@ const ClosingDetail: React.FC = ({ initialValue, salesData, hppExpeditionData, + projectData, + kandangData, }) => { const [activeTab, setActiveTab] = useState('sapronak'); @@ -98,7 +105,18 @@ const ClosingDetail: React.FC = ({

Detail Closing

- + + + {!kandangData && ( + + )} { + const chickinPopulation = useMemo(() => { + if (kandangData) { + return kandangData?.chickins?.reduce( + (acc, chickin) => acc + chickin.usage_qty, + 0 + ); + } + return 0; + }, [kandangData]); + return (
@@ -17,7 +34,9 @@ const ClosingGeneralInformationTable = ({ Lokasi : - {initialValue?.location_name} + + {initialValue?.location_name ?? projectData?.location?.name} + Periode @@ -27,12 +46,20 @@ const ClosingGeneralInformationTable = ({ Project Flock : - {initialValue?.project_flock?.name} + + {initialValue?.project_flock?.name ?? + projectData?.flock_name} + Populasi : - {initialValue?.population} Ekor + + {!kandangData + ? (initialValue?.population ?? 0) + : (chickinPopulation ?? 0)}{' '} + Ekor + Jenis Project @@ -40,9 +67,13 @@ const ClosingGeneralInformationTable = ({ {initialValue?.project_type} - Kandang Aktif + Kandang {!kandangData && 'Aktif'} : - {initialValue?.active_house_count} Kandang + + {!kandangData + ? `${initialValue?.active_house_count} Kandang` + : kandangData?.kandang?.name} + Status Pembayaran Penjualan @@ -69,9 +100,13 @@ const ClosingGeneralInformationTable = ({ - + - + diff --git a/src/components/pages/closing/ClosingKandangList.tsx b/src/components/pages/closing/ClosingKandangList.tsx new file mode 100644 index 00000000..dd3083a7 --- /dev/null +++ b/src/components/pages/closing/ClosingKandangList.tsx @@ -0,0 +1,37 @@ +import Button from '@/components/Button'; +import { ClosingGeneralInformation } from '@/types/api/closing'; +import { ProjectFlock } from '@/types/api/production/project-flock'; + +const ClosingKandangList = ({ + initialValue, + projectData, +}: { + initialValue?: ClosingGeneralInformation; + projectData?: ProjectFlock; +}) => { + return ( +
+
+
+
+

Kandang

+
+ {projectData?.kandangs?.map((kandang) => ( + + ))} +
+
+
+
+
+ ); +}; + +export default ClosingKandangList;
Kandang AktifKandang {!kandangData && 'Aktif'} :{initialValue?.active_house_count} Kandang + {!kandangData + ? `${initialValue?.active_house_count} Kandang` + : kandangData?.kandang?.name} +
Status Pembayaran Penjualan