From 5c9332537c8aa638fb606149e94ae4c8f46759a8 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 15 Dec 2025 11:08:05 +0700 Subject: [PATCH] feat(FE-363): Add pagination to purchases per supplier report --- .../PurchasesPerSupplierTab.tsx | 127 +++++++++++------- src/services/api/logistic.ts | 13 +- 2 files changed, 91 insertions(+), 49 deletions(-) diff --git a/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx b/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx index 8a3879a5..6da12712 100644 --- a/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx +++ b/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx @@ -37,6 +37,10 @@ const PurchasesPerSupplierTab = () => { 'received_date' ); + // ===== PAGINATION STATE ===== + const [currentPage, setCurrentPage] = useState(1); + const [pageSize, setPageSize] = useState(10); + // ===== TABLE FILTER STATE ===== const { state: tableFilterState, updateFilter } = useTableFilter({ initial: { @@ -169,6 +173,8 @@ const PurchasesPerSupplierTab = () => { po_date: tableFilterState.po_date || undefined, start_date: tableFilterState.start_date || undefined, end_date: tableFilterState.end_date || undefined, + page: currentPage, + limit: pageSize, }; return ['logistic-purchase-report', params]; @@ -181,7 +187,9 @@ const PurchasesPerSupplierTab = () => { params.received_date, params.po_date, params.start_date, - params.end_date + params.end_date, + params.page, + params.limit ) ); @@ -191,6 +199,32 @@ const PurchasesPerSupplierTab = () => { ? (purchasePerSupplier?.data as unknown as LogisticPurchasePerSupplier[]) : []; + const meta = + isResponseSuccess(purchasePerSupplier) && 'meta' in purchasePerSupplier + ? purchasePerSupplier.meta + : undefined; + + // ===== PAGINATION HANDLERS ===== + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + + const handleRowChange = (pageSize: number) => { + setPageSize(pageSize); + }; + + const handleNextPage = () => { + if (meta && currentPage < meta.total_pages) { + setCurrentPage(currentPage + 1); + } + }; + + const handlePrevPage = () => { + if (currentPage > 1) { + setCurrentPage(currentPage - 1); + } + }; + const getTableColumns = ( totals: Totals ): ColumnDef[] => { @@ -505,55 +539,56 @@ const PurchasesPerSupplierTab = () => { const tableColumns = getTableColumns(totals); return ( - <> - - 0} - className={{ - containerClassName: 'w-full', - tableWrapperClassName: 'overflow-x-auto mt-4', - tableClassName: 'w-full table-auto text-sm', - headerRowClassName: - 'border-b border-b-gray-200 bg-gray-50', - headerColumnClassName: - 'px-4 py-3 text-xs font-semibold text-gray-700 text-left border border-gray-200', - bodyRowClassName: - 'hover:bg-gray-50 transition-colors border-b border-l border-r border-b-gray-200 border-l-gray-200 border-r-gray-200', - bodyColumnClassName: - 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', - tableFooterClassName: - 'bg-gray-100 font-semibold border border-gray-200', - footerRowClassName: 'border-t-2 border-gray-300', - footerColumnClassName: - 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', - }} - /> - {}} - onRowChange={() => {}} - onNextPage={() => {}} - onPrevPage={() => {}} - rowOptions={[10, 25, 50, 100]} - itemsPerPage={10} - /> - - + +
0} + className={{ + containerClassName: 'w-full', + tableWrapperClassName: 'overflow-x-auto mt-4', + tableClassName: 'w-full table-auto text-sm', + headerRowClassName: 'border-b border-b-gray-200 bg-gray-50', + headerColumnClassName: + 'px-4 py-3 text-xs font-semibold text-gray-700 text-left border border-gray-200', + bodyRowClassName: + 'hover:bg-gray-50 transition-colors border-b border-l border-r border-b-gray-200 border-l-gray-200 border-r-gray-200', + bodyColumnClassName: + 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', + tableFooterClassName: + 'bg-gray-100 font-semibold border border-gray-200', + footerRowClassName: 'border-t-2 border-gray-300', + footerColumnClassName: + 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', + paginationClassName: 'hidden', + }} + /> + ); }) )} + {meta && data.length > 0 && ( +
+ +
+ )} ); }; diff --git a/src/services/api/logistic.ts b/src/services/api/logistic.ts index cee1c825..611c601d 100644 --- a/src/services/api/logistic.ts +++ b/src/services/api/logistic.ts @@ -18,11 +18,13 @@ export class LogisticApiService extends BaseApiService< received_date?: string, po_date?: string, start_date?: string, - end_date?: string + end_date?: string, + page?: number, + limit?: number ): Promise | undefined> { return await this.customRequest< BaseApiResponse - >(`purchase-supplier`, { + >(`logistic-stock`, { method: 'GET', params: { area_id: area_id, @@ -32,9 +34,14 @@ export class LogisticApiService extends BaseApiService< po_date: po_date, start_date: start_date, end_date: end_date, + page: page, + limit: limit, }, }); } } -export const LogisticApi = new LogisticApiService('/reports'); +// TODO: REPLACE WITH PRODUCTION URL +export const LogisticApi = new LogisticApiService( + 'http://localhost:4010/api/report' +);