From e5ec0f8deb758c66ef01b3b708808471058ff2b9 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Tue, 13 Jan 2026 15:20:36 +0700 Subject: [PATCH] feat(FE): closing report overhead per kandang --- .../pages/closing/ClosingOverheadTable.tsx | 15 +++++++++++---- src/services/api/closing.ts | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/pages/closing/ClosingOverheadTable.tsx b/src/components/pages/closing/ClosingOverheadTable.tsx index 3df0844d..ed74ca66 100644 --- a/src/components/pages/closing/ClosingOverheadTable.tsx +++ b/src/components/pages/closing/ClosingOverheadTable.tsx @@ -5,21 +5,27 @@ import { cn, formatCurrency, formatDate, formatNumber } from '@/lib/helper'; import { ClosingApi } from '@/services/api/closing'; import { Overhead, OverheadTotal } from '@/types/api/closing'; import { ColumnDef } from '@tanstack/react-table'; +import { useSearchParams } from 'next/navigation'; import { useMemo } from 'react'; import useSWR from 'swr'; interface ClosingOverheadTableProps { - type?: 'detail'; projectFlockId: number; } const ClosingOverheadTable = ({ - type, projectFlockId, }: ClosingOverheadTableProps) => { + const searchParams = useSearchParams(); + const kandangId = searchParams.get('kandangId'); + const { data: overhead, isLoading: isLoadingOverhead } = useSWR( - `${ClosingApi.basePath}/${projectFlockId}/overhead`, - () => ClosingApi.getOverhead(projectFlockId), + `${ClosingApi.basePath}/${projectFlockId}${kandangId ? `/${kandangId}` : ''}/overhead`, + () => + ClosingApi.getOverhead( + projectFlockId, + kandangId ? Number(kandangId) : undefined + ), { keepPreviousData: true, } @@ -148,6 +154,7 @@ const ClosingOverheadTable = ({ 'whitespace-nowrap' ), }} + isLoading={isLoadingOverhead} renderFooter={ isResponseSuccess(overhead) ? overhead.data?.overheads.length > 0 diff --git a/src/services/api/closing.ts b/src/services/api/closing.ts index 892fc88e..ff6a0bcb 100644 --- a/src/services/api/closing.ts +++ b/src/services/api/closing.ts @@ -131,10 +131,11 @@ export class ClosingApiService extends BaseApiService { } async getOverhead( - id: number + id: number, + kandangId?: number ): Promise | undefined> { try { - const path = `${this.basePath}/${id}/overhead`; + const path = `${this.basePath}/${id}${kandangId ? `/${kandangId}` : ''}/overhead`; return await httpClient>(path, { method: 'GET', });